I’m having difficulties with Text Encoding regarding serial port communications with Linux. I have the port set to 9600 Baud, Even Parity, 7 Bits, 1 Stop. I can’t seem to get the correct encoding. I’ve tried Nil, Windows ANSI and ASCII. All produce null characters for CR. Any advice will be greatly appreciated. It is interesting to note the windows compiled application with the same code does not have this issue regardless of the encoding.
For proper traffic you need 8 bits, not seven.
Instead of reading as a string, perhaps read as data.
Thus, do not specify any encoding.
dim data as string
data = mySerialPort.readAll()
for counter as integer = 1 to lenB(data)
if ascB(midB(data, counter, 1) = 13 then msgbox “CR found”
I have not had to use a serial port with seven bits of data. All have been 8. So this may not solve the issue.
I don’t think it should be a problem using 7 data bits. ASCII only uses 7. My guess is that Xojo is automatically converting line endings. If the input stream contains Windows line endings, CR+LF, then it may be stripping the CR to leave just the LF which is the correct line ending for Linux. If the input stream contains just CR’s they may be converted to LF or just deleted.
I’ve been using Xojo to talk to serial devices for many years - and have found that if you don’t get the parameters exactly right in your serial setup, you’ll get garbage. What device are you connecting to? What are it’s port settings? I’m talking ALL the settings: baud, bits, parity, CTS, DTR, XON, etc etc.
Thanks everyone for your inputs on the subject. Oddly, it was an odd issue with the virtualization of the Linux operating system that caused the anomaly.