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

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

Use of ReceiveRS232String in main loop

Postby Ondra » Mon Dec 20, 2010 12:04 pm

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: 14363
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4444 times
Been thanked: 4144 times
Contact:

Re: Use of ReceiveRS232String in main loop

Postby Benj » Mon Dec 20, 2010 1:17 pm

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

Postby Ondra » Mon Dec 20, 2010 1:24 pm

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

Postby Ondra » Mon Dec 20, 2010 1:38 pm

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.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8440
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2412 times
Been thanked: 3450 times
Contact:

Re: Use of ReceiveRS232String in main loop

Postby medelec35 » Mon Dec 20, 2010 5:34 pm

Hiya Ondra,
I'm not quiet sure if this i what you are after:
viewtopic.php?f=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

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

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

Re: Use of ReceiveRS232String in main loop

Postby Benj » Tue Dec 21, 2010 3:23 pm

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/