Need a simple serial terminal

Does anyone have a simple serial terminal project they can share? I need to verify a serial stream on a COM port. My own attempts are not working out.

Is there not one in the example projects that come with xojo?

Not really. The samples just show how to check the status lines, not how to read characters from a serial stream.

I’ve actually made some progress and can see characters now, but the characters start out correct and then become scrambled after the first 50 or 60. The characters are correct if I look at them with Cool Term.

Sounds like your handshaking is getting out of synch…

There is no handshaking, just a stream of data at 9600 baud. Even when I put a half second delay between each set of 15 bytes, CoolTerm displays all 15 characters just fine, and Xojo displays only the first 3 or 4 sets correctly. Then it displays zeros and 0Eh characters. Here’s a sample. Even if I FLUSH the serial channel, the bad characters persist until I quit and relaunch the app. With every fresh start the first 3 or 4 lines are correct, and it breaks again. The transmitter is a hardware device that outputs “abcdefghijklmno” over and over.

61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
0D 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E
6F 0D 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D
6E 6F 0D 61 62 63 64 65 66 67 68 69 6A 6B 6C
6D 6E E0 00 E0 00 00 E0 E0 00 E0 00 00 E0 E0
E0 00 E0 00 00 E0 E0 00 E0 00 E0 E0 E0 00 E0
E0 00 E0 E0 E0 E0 E0 E0 E0 00 E0 E0 E0 E0 E0
E0 00 E0 E0 E0 E0 E0 E0 E0 00 E0 00 E0 00 00
E0 E0 00 E0 00 00 E0 E0 E0 00 E0 00 00 E0 E0

Try using Serial.Xon = True

You may want to wait the DataAvailable event to read.

How are you reading the data?

I’m reading the data by way of the DataAvailable event.

I have switched data sources from a fast binary stream in one device to a slow ASCII stream from another device. Xojo reads the slow ASCII data correctly. It just garbles the fast binary stream.

Do you use ReadAll? What processing, if any, are you doing in DataAvailable?

Does it help to put a thread on the window and in its Run event poll the serial port?

while true
   theSerialPort.Poll
   me.sleep(1)
wend

[quote=93957:@Bryan Mumford]I’m reading the data by way of the DataAvailable event.

I have switched data sources from a fast binary stream in one device to a slow ASCII stream from another device. Xojo reads the slow ASCII data correctly. It just garbles the fast binary stream.[/quote]

What about Xon = True ? It should allow flow control.

Maybe check DSR before reading ?

The sample program below is an extract from a small terminal program we developed to communicate with some embedded devices. Maybe it helps point you on the right direction.

https://dl.dropboxusercontent.com/u/42062295/RealSoftware/forum%20serial%20monitor.rbp

[quote=93982:@Michel Bujardet]What about Xon = True ? It should allow flow control.

Maybe check DSR before reading ?[/quote]

Our sending device does not use flow control.

[quote=93963:@Tim Hare]Do you use ReadAll? What processing, if any, are you doing in DataAvailable?

Does it help to put a thread on the window and in its Run event poll the serial port?

while true theSerialPort.Poll me.sleep(1) wend [/quote]

This is all I’m doing in DataAvailable. It updates every 15 characters and scrolls them, but it does not keep up with the data rate, and BytesAvailable continues to grow at a rapid pace.

if TestSerial.BytesAvailable > 50 then
zz =TestSerial.Read(15,encodings.MacRoman)
zz = EncodeHex(zz,True)
TextField1.Text = TextField1.Text + chr(13) + zz
end

This is going to slow down over time, which could account for part of what you’re seeing. Try using TextField1.Append chr(13)+zz instead.

My recommendation, though, would be to not leave anything in the serial buffer. Get it all out with readall, append it to an internal buffer and be done. Spend as little time as possible in DataAvailable. Use a timer to process the buffer and stuff it into your textfield.

Then what about hardware signals ? This is part of the most basic RS-232 standard.

[quote=94003:@Tim Hare]This is going to slow down over time, which could account for part of what you’re seeing. Try using TextField1.Append chr(13)+zz instead.

My recommendation, though, would be to not leave anything in the serial buffer. Get it all out with readall, append it to an internal buffer and be done. Spend as little time as possible in DataAvailable. Use a timer to process the buffer and stuff it into your textfield.[/quote]

Good idea! As a test, I just ReadAll and displayed it over and over, building nothing longer. It behaves the same way. The first string has the real data, the second string and from then on contains the same 00 E0 data.

Can it be that Xojo is unable to keep up with a fast data feed? I would think that the buffer would allow this.

We don’t want to handshake. In fact, the data streams over a Bluetooth link. I’m getting it from a Virtual COM port. It’s output through a serial port of a PIC chip, relayed by a Bluetooth module, and collected by the Bluetooth interface in a Mac.

[quote=94009:@Bryan Mumford]
Can it be that Xojo is unable to keep up with a fast data feed? I would think that the buffer would allow this.[/quote]

The example I provided was used with a continuous stream @ 115k baud. You are at 9600. Trust me, that is not fast at all.

Whatever your desire to use handshake, serial communication requires it because it is intrinsically asynchronous. Whether it is obtained by software or hardware, Cool Term is using either handshake method and that is the reason why it displays the data reliably and your program not.

The only alternative would be to slow down data fetching enough to prevent synchronisation loss…

I have never seen a serial device that did not include/require/use some type of handshaking such as xON/xOFF…
Which is why that was the first thing I mentioned on this thread