iOS Question Create stream for connection made by native code

mrossen

Active Member
Licensed User
Longtime User
Hi,

Is it possible to use:

B4X:
    AStreams.InitializePrefix(Serial1.InputStream, True, Serial1.OutputStream, "AStreams")

to get the stream created with inline code.

I cannot use Serial1. because I don't have it.

I can make the SSP connection with the inline code and want to grab the stream in b4i code, then I can reuse my B4A code :)

Can this be done?

Can I make a event to see when the connection done ?


Mogens
 

mrossen

Active Member
Licensed User
Longtime User
Hi.

I can figure that out.

I atttached my demo project


Mogens
 

Attachments

  • Bluetooth_Test.zip
    5 KB · Views: 281
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Thank you for your reply,

I can see what you mean but I can not figure out how to do it.

I have made a new test project where I only connect to the bluetooth module.

The file is attached

When I get this connection can I here get the stream.

Create a method that returns NSOutputStream* and return session.outputstream. It will be converted to B4i OutputStream object which you can use with AsyncStreams (start in non-prefix mode).

This is only for the output. I also need to have a stream for the input, right?

I am realy lost so if anyone have a solution or hints anythink may be usefull

B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: Bluetooth SPP
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #PlistExtra: <key>UISupportedExternalAccessoryProtocols</key><array><string>com.RovingNetworks.btdemo</string></array>
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Dim AStreams As AsyncStreams

End Sub

Private Sub Application_Start (Nav As NavigationController)

    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    Page1.RootPanel.LoadLayout("main")
   
    Dim NativeMe As NativeObject = Me
     NativeMe.RunMethod("viewloaded:", Array (True))
   
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
   
End Sub

Private Sub Application_Background
   
End Sub

Sub ButtonScan_Click
   
    Dim NativeMe As NativeObject = Me
    NativeMe.RunMethod("doScan:", Array (True))
End Sub

Sub ButtonConnect_Click
   
End Sub

#If ObjC

EAAccessoryManager *mgr;
EASession *session;

#import <ExternalAccessory/ExternalAccessory.h>

- (void)viewloaded: (bool) on{

    mgr = [EAAccessoryManager sharedAccessoryManager];
   
}

- (void)doScan: (bool) on{

    NSLog(@"Starting Scan");
     
    NSOutputStream *os = session.outputStream;
   
    if ([mgr.connectedAccessories count])
    {
        if (os.hasSpaceAvailable)
        {

            UIAlertView *alert = [[UIAlertView alloc]
                                  initWithTitle: @"Warning !!!"
                                  message: @"Device are already connected"
                                  delegate: nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil]; [alert show];

            [alert show];
                    }
        else
        {

        /*[self connectBT];*/


        }
    }
    else
    {
        [mgr showBluetoothAccessoryPickerWithNameFilter:nil completion:^(NSError *error){ NSLog(@"%@", [error localizedDescription]);}];
    }

}


#End If

Mogens
 

Attachments

  • bluetooth_spp.zip
    2.9 KB · Views: 317
Upvote 0
Top