Question

I am working with the Scribbler 2 robot and the Fluke 2 board, and communicating with the Fluke through Myro in Java. The Fluke board is a Bluetooth communication bridge between the Scribbler and the desktop client written in Java. It communicates through an RS232 serial port to the Scribbler.

This may be a dumb question and the above system is complicated, so bear with me if I don't explain this well.

The background of my question: Java uses signed bytes. The Fluke is (I think) written in C so that uses unsigned bytes. The firmware on the Scribbler is written in Spin which also uses unsigned bytes. Some of the command bytecodes for the Scribbler firmware use values that are greater than 127 so when they get sent from my Java client they are sent as negative numbers. The robot is not responding to these > 127 commands and I am trying to understand why.

The gist of my question: If I send 162 from Java it displays as -94 (seeing this in my console with 'print'). Will the Spin firmware see this as 162 because a byte is a byte, or will it see it as something else?

I know the Spin code is doing some bit shifting for params to movement commands which can be greater than 255 but it is not doing it for the specific command.

pub Move | x_coord, y_coord
'        0    1     2      3      4      5 
'Format 162 type hXByte lXByte hYByte lYByte
'  type    := indata[1]
  x_coord := (indata[2]<<8 | indata[3])
  y_coord := (indata[4]<<8 | indata[5])
Was it helpful?

Solution

Byte is 8 bits, and nothing more. It is not signed or unsigned by itself. It is arithmetic operations who make difference - simply because there are different arithmetic operations. So Java has only signed integer operations, while C has both. While a byte is sent via RS232, it does not have any operations. So don't worry, your bytes would not be spoiled by Java.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top