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
Use of ReceiveRS232String in main loop
Moderator: Benj
- 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
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
}
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
}
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Use of ReceiveRS232String in main loop
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.
Ondra.
-
- 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
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.
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
- 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
Hi Ondra,
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/
A string variable can contain a whole sentance including spaces and other ASCII / Extended ASCII characters.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?
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/
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel