B4i Library iExternalAccessory - A flexible and customize way to connect MFi devices

iEATop.png

This library was built for create apps using devices with iAP protocol and MFi.

Installation instructions:

- Copy the *.a and *.h files into the folder "Libs" in your MAC or in your MAC HOSTED by AnywhereSoftware, normally in "B4i-MacServer\Libs" folder

-Copy the iExternalAccesory.xml to your custom libraries folder in B4i
- Select in your REFERENCED LIBRARIES

RefiEA.jpg

Version history:
V1.0.0 (First public release):
- Initial version

iExternalAccessory
Author:
Alberto Iglesias ([email protected])
Version: 1
  • iExternalAccessory
    Events:
    • _ReadData (BytesReceived As String)
    • _onClose
    • _onConnected (Accessory As String)
    • _onDisconnected (Accessory As String)
    • _onOpen
    • _onStream (Event As String)
    • onInitialized (EventName As String)
    Methods:
    • EACloseSession
    • EAGetAccessories As NSString*
    • EAOpenSession:: (name As NSString*, protocol As NSString*) As Boolean
      Scan External Accessories
      -(void)EAScan;
    • EASendHex: (hextosend As NSString*) As Boolean
    • EASendText: (texttosend As NSString*) As Boolean
    • Initialize:: (bi As B4I*, EventName As NSString*)
      Initializes the object.
    • LicenseShow
      Show License
    • isConnected As Boolean
    Properties:
    • Author As NSString* [read only]
      Author of this Library
    • DebugMode As BOOL
      Enable/Disable Debug mode from Library
    • ErrorCode As Int [read only]
      Last Error Code
    • ErrorDescription As NSString* [read only]
      Last Error Description
    • LicenseEmail As NSString*
      License Email
    • LicenseKey As NSString*
      License Key
    • Version As NSString* [read only]
      Library Version

B4iEAShot2.jpg



* This version is fully functional, the only one difference is when send message, sometimes can be show a donation message.
Please consider a simple €10 donation and I send to you the Library without "Donationware" message alert.

Get the lastest version in http://vnsoft.es/store/

You can get your license key in our library store:

 

Attachments

  • EASample.zip
    3.2 KB · Views: 37
Last edited:

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
as I can see in the library, the buffer is controlled by device, is not from the library, so you can use the method cleardata to clear after you receive:

you see the variable: hasBytesAvailable ?? this is part of control from device

B4X:
while ([[session inputStream] hasBytesAvailable])
    {
        NSInteger bytesRead = [[session inputStream] read:buf maxLength:EAD_INPUT_BUFFER_SIZE];
        if (_readData == nil) {
            _readData = [[NSMutableData alloc] init];
        }
        [_readData appendBytes:(void *)buf length:bytesRead];
        //NSLog(@"read %d bytes from input stream", bytesRead);
        if(_DebugMode) NSLog(@"[_readData]:Bytes:%ld",(long)bytesRead);

    }
 

Turbo3

Active Member
Licensed User
Longtime User
That works. I did not see the "cleardata" method listed at the top where you listed the methods so did not know about it.

Is there some reason you defined BytesReceived as a string when it is really an array of bytes? Even your example prints a pointer when it logs "BytesReceived". It is not a string.

_ReadData (BytesReceived As String)
 

Turbo3

Active Member
Licensed User
Longtime User
Its not a matter of conversion. The type is wrong. I fixed it by changing:

ReadData (BytesReceived As String)

to

ReadData (BytesReceived() As Bytes)
 

Turbo3

Active Member
Licensed User
Longtime User
I see a potential problem with the app asynchronously calling "cleardata".

What if more data comes in between the time ReadData is called and "cleardata" is executed. It seems data would be lost.

Cleardata needs to clear only the data returned to the app when ReadData is called. Any data received after Readdata is called needs to be accumulated in a different buffer. So you need a ping-pong set of buffers so nothing gets lost.

I can place the OBDLink MX+ into a mode where it will continuously send data. This means ReadData is going to be called over and over again without the app every sending another command. There is not going to be a safe time for my app to call cleardata without the risk of clearing data the app has not received yet.

Please look at setting up a pair of buffers, that way the cleardata will not be necessary and no data will be lost.
 

Turbo3

Active Member
Licensed User
Longtime User
I am trying to see if I can automatically connect to the device as the list accessory does not work if there is no connection with the device.

Can a function be added to list the Paired Bluetooth devices?

Can a function be added to connect to a Paired device?
 
Top