Need a simple serial terminal

  1. 6 years ago

    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.

  2. Russ L

    30 May 2014 Pre-Release Testers, Xojo Pro

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

  3. 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.

  4. Dave S

    30 May 2014 San Diego, California USA

    Sounds like your handshaking is getting out of synch....

  5. 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<CR>" 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

  6. Michel B

    31 May 2014 Pre-Release Testers, Xojo Pro

    Try using Serial.Xon = True

    You may want to wait the DataAvailable event to read.

  7. Tim H

    31 May 2014 Pre-Release Testers Portland, OR USA

    How are you reading the data?

  8. 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.

  9. Tim H

    31 May 2014 Pre-Release Testers Portland, OR USA

    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
  10. Michel B

    31 May 2014 Pre-Release Testers, Xojo Pro

    @Bryan M 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.

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

    Maybe check DSR before reading ?

  11. 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

  12. @Michel B What about Xon = True ? It should allow flow control.

    Maybe check DSR before reading ?

    Our sending device does not use flow control.

  13. @Tim H 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

    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

  14. Tim H

    31 May 2014 Pre-Release Testers Portland, OR USA

    @Bryan M TextField1.Text = TextField1.Text + chr(13) + zz

    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.

  15. Michel B

    31 May 2014 Pre-Release Testers, Xojo Pro

    @Bryan M Our sending device does not use flow control.

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

  16. @Tim H 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.

    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.

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

    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.

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

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

  19. Michel B

    31 May 2014 Pre-Release Testers, Xojo Pro

    @Bryan M 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.

    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...

  20. Dave S

    31 May 2014 San Diego, California USA

    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

  21. Newer ›

or Sign Up to reply!