Use of ReceiveRS232String in main loop

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Use of ReceiveRS232String in main loop

Post by Ondra »

Good day all.
Up until this point, I am comfortable using ReceiveRS232Char and a decision icon to check if var < 255 before beginning to process any further.
My question is, what does the ReceiveRS232String macro return when it is called in a loop and there is no data available? Also if I wanted to use a decision
Icon after the ReceiveRS232String macro, to check if any data is in the macro before processing further, how could I should I accomplish this?
Thanks in advance.

Ondra

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Use of ReceiveRS232String in main loop

Post by Benj »

Hi Ondra,

The receive string function works like this.

It will try to receive the number of bytes specified in the parameter.

If a timeout occurrs then it will save the timeout information into the string. Most strings will be sent out as one piece of information so you should not really get a timeout half way through a string.

If a timeout happens before any valid data is received then you will get a string with index 0 = 255.

In a decision you can use string[0] =255 to test if the byte is 255.

If a timeout were to happen half way through a string then you could detect this by finding the length of the string and then creating a loop to check through each byte to ensure it is not 255.

length = StrLen(String)
idx = 0
while (idx < length)
{
if (string[idx] = 255)
yes: timeout occurred
no: byte ok

idx = idx + 1
}

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Use of ReceiveRS232String in main loop

Post by Ondra »

Thanks Benj this looks good.

Ondra

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Use of ReceiveRS232String in main loop

Post by Ondra »

OK Benj, just to round out my thinking on this. Is a string each word in a sentence or would it be the entire sentence or phrase?

Ondra.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Use of ReceiveRS232String in main loop

Post by medelec35 »

Hiya Ondra,
I'm not quiet sure if this i what you are after:
http://www.matrixmultimedia.com/mmforum ... =29&t=7877

I have created a flowchart that can match strings with stored strings.
Although, the strings are stored as ASCII numbers.
Its the only way I could think of to compare strings of more than one char.
I'm sure there could be a way to compare using just strings, It's something I can look into.
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Use of ReceiveRS232String in main loop

Post by Benj »

Hi Ondra,
OK Benj, just to round out my thinking on this. Is a string each word in a sentence or would it be the entire sentence or phrase?
A string variable can contain a whole sentance including spaces and other ASCII / Extended ASCII characters.

EG
string = "the cat in the hat!"

Generally a byte equalling 0 or null will terminate the string variable but Flowcode will handle this functionality automatically if there is room in the string left for adding the termination.

Please note that 0 or null is not the same as an ASCII letter 0 which is actually 48 in decimal.

EG
string[19] = 0

is not the same as

string[19] = '0'

http://www.asciitable.com/

Post Reply