Log in

View Full Version : RoboRio and Serial Data


stu54
07-05-2015, 14:28
I have been trying to hook up a MaxSonar range finder to my RoboRio using the ASCII output of the MaxSonar rather than the analog output. I tried both the RS-232 port (using a TTL-to-RS-232 converter) and the MXP port. My programming language is Java for the WPIlib but that should not matter.

It seems like the syntax of the MaxSonar somehow violates the VISA format
that the RoboRIO expects so I get Java crashes when I try to read the serial
port. I don't know anything about the VISA format - I was just trying to read
the simple ASCII string from the MaxSonar. I know if I just use a loopback
to test my code I can read and write the serial ports but that's probably
because everything is using the VISA format deeper in the libraries.

Does anyone have experience with general ASCII devices on the RoboRIO
or would I have to use a device that put out the VISA format (which I
could only do if I passed the data from the MaxSonar though an Arduino
to re-format it for VISA, and that's a lot more trouble than just using the
analog input).

Thanks for any help.

virtuald
08-05-2015, 00:41
I have been trying to hook up a MaxSonar range finder to my RoboRio using the ASCII output of the MaxSonar rather than the analog output. I tried both the RS-232 port (using a TTL-to-RS-232 converter) and the MXP port. My programming language is Java for the WPIlib but that should not matter.

It seems like the syntax of the MaxSonar somehow violates the VISA format
that the RoboRIO expects so I get Java crashes when I try to read the serial
port. I don't know anything about the VISA format - I was just trying to read
the simple ASCII string from the MaxSonar. I know if I just use a loopback
to test my code I can read and write the serial ports but that's probably
because everything is using the VISA format deeper in the libraries.

Does anyone have experience with general ASCII devices on the RoboRIO
or would I have to use a device that put out the VISA format (which I
could only do if I passed the data from the MaxSonar though an Arduino
to re-format it for VISA, and that's a lot more trouble than just using the
analog input).

Thanks for any help.

I find it hard to believe that there would be a VISA-specific format required.

I've not used the serial functionality on the RoboRIO, but typically with serial devices you need to make sure that the baud rate matches (eg, you need to set the port speed to what the device is using) or you'll get unpredictable results similar to what you describe. Typical serial devices tend to be 9600 or 115200 baud, refer to your data sheet to see what your device uses.

GeeTwo
08-05-2015, 15:43
It's possible that java somehow thinks that it's getting Unicode instead of ascii, and mangling the strings on the way in. You may want to try getting the raw bytes in a buffer to see if you can use it instead.

stu54
13-05-2015, 11:55
I found that when I did a try/catch on my code and did the single byte unbuffered reads I was getting framing errors (even though everything is set to 9600 N 8 1) and
when I got some reads to work it did not look like the ASCII format as
documented for the MaxSonar. Maybe it is a unicode thing or maybe
the RoboRIO serial reader is not set up for asynchronous reading like would be needed
for the MaxSonar. Guess I will just have to go with analog.

Bonzabonz
15-05-2015, 15:11
It's possible that java somehow thinks that it's getting Unicode instead of ascii, and mangling the strings on the way in. You may want to try getting the raw bytes in a buffer to see if you can use it instead.

I second this, in my experience, if you read the raw and do your own encoding things seem to work better. If you can post your code, we could probably take a look and see if anything obvious stands out.