iOS Question iExternalAccessory ReadData

mrossen

Active Member
Licensed User
Longtime User
Hi,

You can send data in text and hex format, but only recieve in hex format.

Is it possible to recieve in text format?

Thanks
Mogens
 

mrossen

Active Member
Licensed User
Longtime User
Hi Alberto,

Thanks for your answer.

I have tried this

B4X:
Dim d() As String
       
    d = Array As String(BytesReceived)
   
    Log(d.Length)

But i seems to get the same result as I read the BytesReceived string

How do I get the byte into the array right?

Mogens
 
Upvote 0

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hi Alberto,

Thanks for your answer.

I have tried this

B4X:
Dim d() As String
      
    d = Array As String(BytesReceived)
  
    Log(d.Length)

But i seems to get the same result as I read the BytesReceived string

How do I get the byte into the array right?

Mogens
Hi Mogens, Im in the street right now, but when I arrive in office I send to you a project I do
 
Upvote 0

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hello again Mogens, look this example:

B4X:
Sub objEA_ReadData(BytesReceived() As Byte)

     SU_Log("[objEA_ReadData]:Size => " & BytesReceived.Length)    
     Dim bc As ByteConverter

     Dim strDataHex As String = bc.HexFromBytes(BytesReceived)
    SU_Log("[objEA_ReadData]:Hex:" & strDataHex)    

     Dim strBytesDec As String 
     Dim strBytesAsc As String 
     For a = 0 To BytesReceived.Length-1
        strBytesAsc = strBytesAsc & Chr(BytesReceived(a)) & ","
        strBytesDec = strBytesDec & BytesReceived(a) & ","
     Next
    SU_Log("[objEA_ReadData]:BytesDec:" & strBytesDec)    
    SU_Log("[objEA_ReadData]:BytesAsc:" & strBytesAsc)    
     
 
End Sub
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hello Alberto,

Thanks for the reply, but I still not get it to Work,

A screendumb with you code snip, with the error

Udklip.JPG


Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi Alberto

This is a sample on what I recieve as string

[stream]:NSStreamEventHasBytesAvailable
-[B4iExternalAccessory _readData]
[_readData]:Bytes:1
[objEA_onStream]:NSStreamEventHasBytesAvailable
[objEA_ReadData]:<6f6c>
[stream]:NSStreamEventHasBytesAvailable
-[B4iExternalAccessory _readData]
[_readData]:Bytes:3
[objEA_onStream]:NSStreamEventHasBytesAvailable
[objEA_ReadData]:<6f6c7070 70>

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi Alberto,

That is correct.

But is there a way to get the data as array.

Now I have make the recieved into pairs and then convert to ascii.

But there another problem with that. In the string there i a space I have to deal with.

[objEA_ReadData]:<6f6c7070 70>

Any idea where that come from?

Mogens
 
Upvote 0

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
is curious because I send like I got, a array of bytes, look the readdata inside:

B4X:
   B4IArray* arr = [B4IArraynew];
   arr.bytesData = _readData;
   [B4IObjectWrapperraiseEventFromDifferentThread:self :@"_readdata:" :@[arr]];

I test with some devices and I get an array.

Wich device you testing?


I thought about creating a property for you to get the contents of readdata, but it would be the same, ie a B4iArray
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi Alberto,

I am testing with a RN-42 bluetooth module connected to a Cruise Control for a car we produce.

I have made the same app for android and it is working without problems.

In android I recieve characters like "olppp" and then convert from asciii to dec, and then I have my values.

When I use "Sub objEA_ReadData(BytesReceived() As Byte)" I can debug BytesReceived, but it looks like a string contains the hex values, not an array.

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi Alberto

How are you making this video. I will make one for you to see my content of the array

Mogens
 
Upvote 0

mrossen

Active Member
Licensed User
Longtime User
Hi Alberto,

I made screendumps from B4i

As you can see there is no differnce between byte and string

1. The way I think a array will be present

array.jpg


2. BytesReceived() As Byte

byte.jpg


3. BytesReceived() As String

string.jpg


Mogens
 
Upvote 0

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Mogens, I little gift for you:

you have now 2 more events readData2 and readData3

B4X:
Sub objEA_ReadData3(DecReceived() As String)
   
    Dim strDec As String
    For a = 0 To DecReceived.Length-1
       strDec = DecReceived(a)
        LogColor("strDec=" & strDec,Colors.Blue)
    Next

End Sub

Sub objEA_ReadData2(HexReceived() As String)
   
    Dim strHex As String
    For a = 0 To HexReceived.Length-1
        strHex = HexReceived(a)
        LogColor("strHex=" & strHex,Colors.Blue)
     Next
     
End Sub


Get the new version v1.0.3 in my Store

http://worknhouse.com/store/product...ble-and-customize-way-to-connect-mfi-devices/
 
Upvote 0
Top