I've had a bit of trouble trying to receive (unsigned) bytes since using the 32.02 OS.
Previously I've done this which is a bit of a hack but this works on 28.02.
Function ReveiveByte() As Long
Dim reveivedByte As Long
If SerialInChk(TCP_Socket) > 0
SerialInBlock(TCP_Socket,reveivedByte,1)
RXval = reveivedByte >> 24
If (RXval < 0)
RXval = 127 + (129 + RXval) ' "undo" two's compliment
EndIf
Return RXval
Else
Return 256
EndIf
EndFunction
I had to do this as there is no 'byte' data type available for variables. The byte gets received as a long and then appropriately bit shifted, then I have to undo two's compliment to get the correct value.
Since the new OS this doesn't work. The way longs are stored seems to have changed. I can't even seem to work out a way to bitshift my long to get a byte out of it, there seems almost no logic to it. I can confim with the terminal serial sniffer that the bytes are being received correctly. Strings won't work as it's binary data and are null terminated.
The reason I need a sudo byte data type is to calculate an 8-bit CRC which is used by a sensor. Is there a better way to do this? I really just want to be able to receive a serial byte and put it into a long. (Not worried at all about the overhead to this.)
Really wanting to switchover to the new OS for other reasons...
Any solution for this?
Change what you have:
RXval = reveivedByte >> 24
If (RXval < 0)
RXval = 127 + (129 + RXval) ' "undo" two's compliment
EndIf
To the following:
RXval = reveivedByte >> 24
If (RXval AND &H80)
RXval = 256 - RXval ' "undo" two's compliment
EndIf