Reading string from RS232

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

kassa
Posts: 3
Joined: Thu Mar 12, 2015 4:12 pm
Has thanked: 1 time
Been thanked: 1 time
Contact:

Reading string from RS232

Postby kassa » Fri Mar 13, 2015 4:23 am

I have spent hours trying to solve an issue that is probably very simple. I looked all over this forum and cannot find anyone experiencing the same issue I'm having.
1. I have a very simple setup to test RS232 read. I send 8 bytes to the serial port and find only the first two bytes are read and stored in the string variable. The remaining 6 bytes are all zero. I'm I missing something?

2. I found on this forum that UART RXINT1 interrupt cannot be simulated in Flowcode 6 as of yet. Please correct me if I'm wrong.

Thank you in advance for the help!
Attachments
rs232_test.fcfx
rs232 read
(5.34 KiB) Downloaded 62 times

User avatar
LeighM
Matrix Staff
Posts: 1911
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 460 times
Been thanked: 646 times
Contact:

Re: Reading string from RS232

Postby LeighM » Fri Mar 13, 2015 3:07 pm

You could try increasing the timeout value for the ReceiveString, that will allow more time between characters. Although if you are typing characters by hand on a keyboard it is likely the macro will still timeout between characters. This will only work for automated streams. For slow input, you could use ReceiveChar instead and save the received characters into the buffer yourself. The ReceiveChar macro will return 255 if nothing was received, so you could loop waiting for non-255 results.

Another issue with your test program is that you have a 5 second delay in the loop, this is best removed as this will dominate the loop time and cause you to miss input. As you point out the interrupt is not simulated.
These users thanked the author LeighM for the post:
kassa (Fri Mar 13, 2015 4:33 pm)
Rating: 5.26%
 

kassa
Posts: 3
Joined: Thu Mar 12, 2015 4:12 pm
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Reading string from RS232

Postby kassa » Fri Mar 13, 2015 4:32 pm

LeighM, thank you for the response. I have removed the 5 second delay and increased the timeout and got the same result. However, I found a post (http://www.matrixtsl.com/mmforums/viewtopic.php?f=54&t=15231&p=62253&hilit=rs232+string#p62250)on these forums that may solve my problem. My 3rd byte is 0x00. The string variable interprets the 0x00 as end of string instead of continuing to read the remaining bytes. It looks like I need to use ReveiveChar instead of ReceiveString and load into and array variable in a loop.

I will give that a shot and see.

thanks again.

kassa
Posts: 3
Joined: Thu Mar 12, 2015 4:12 pm
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Reading string from RS232

Postby kassa » Fri Mar 13, 2015 6:33 pm

Solved! Received data always starts with one and I expect 8 bytes of data. So the following code now works!

Thanks again.
Attachments
rs232_test.fcfx
(6.56 KiB) Downloaded 147 times
These users thanked the author kassa for the post:
LeighM (Mon Mar 16, 2015 9:47 am)
Rating: 5.26%