The behaviour of the following code puzzles me.
When Buffer(0) contains hex FF the first test fails, but the else clause logs -1 received.
The buffer is an array of bytes, so I would have thought 0xFF and -1 would be treated equivalently.
The work around is to test if Buffer(0) = -1, of course. If I do this the textwriter appears to write 195 to the (Bluetooth) serial port, rather than 254. Even if I write Chr(254) to the textwriter, I receive 195 at the other side.
A second question, if I may: what's a more straightforward way of sending a byte to the serial port? Using a textwriter seems illogical if I'm thinking hex bytes.
Thanks, Martin
B4X:
Sub AStream_NewData (Buffer() As Byte)
'Cirel sends 0xff handhsake before sending file
'We need to respond with 0xfe to acknowledge
If Buffer(0) = 0xFF Then
Log("FF received")
Dim tw As TextWriter
tw.Initialize(serial1.OutputStream)
tw.Write(Chr(0xFE))
tw.Flush 'to get the FE transmitted
Else
Log(Buffer(0) & "received")
End If
End Sub
When Buffer(0) contains hex FF the first test fails, but the else clause logs -1 received.
The buffer is an array of bytes, so I would have thought 0xFF and -1 would be treated equivalently.
The work around is to test if Buffer(0) = -1, of course. If I do this the textwriter appears to write 195 to the (Bluetooth) serial port, rather than 254. Even if I write Chr(254) to the textwriter, I receive 195 at the other side.
A second question, if I may: what's a more straightforward way of sending a byte to the serial port? Using a textwriter seems illogical if I'm thinking hex bytes.
Thanks, Martin
Last edited: