Serial Communication

I am trying to use an 8-bit communication with the serial port, using all 8 bits; The piece of code I am using to do this test is:

setup: Serial.begin(9600);

loop: if (Serial.available()>0) { Serial.print(,HEX); }

When I send any byte from 0x00 to 0x7f, I get the correct echo, but when I send any byte from 0x80 to 0xff, I receive back the string 0x3f ("?")

Any suggestion?

sounds like the sign bit is getting in the way. What are you using to send the hex value?

I am using Visual Basic .net

arduino_port.BaudRate = 9600 arduino_port.StopBits = IO.Ports.StopBits.One arduino_port.Parity = IO.Ports.Parity.None arduino_port.DataBits = 8 arduino_port.Open()


OK I’ve been doing a bit of digging around in the VB documentation and it appears there are several SerialPort.Write methods.

The form you are using seems to be expecting a string to send. Therefore it isn’t going to accept any character code higher than 127.

The form you need is the one that will send BYTES of data. The only form that I can find that will accept bytes, takes three arguments. The first is an array of bytes, next is an offset and finally, how many bytes to send.

That worked, thank you for the information. To solve this, add the following before opening the port:

arduino_port.Encoding = System.Text.Encoding.GetEncoding(1252)

Thank you for the feedback and the solution.

cartsan: arduino_port.Encoding = System.Text.Encoding.GetEncoding(1252)

Don't you just love VB. What the hell has character encoding got to do with BYTES of data? Yet, I'm sure that someone at Microsoft thought it was a good idea at the time. :)