HOW TO SEND '0' IN A STRING VIA RS232

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
A_Smith
Posts: 7
Joined: Tue Oct 26, 2010 4:59 pm

HOW TO SEND '0' IN A STRING VIA RS232

Post by A_Smith »

Hi

Hopefully someone can help me.

I am sending a string of data via RS232 from a master pic to a slave. Unfortunately I cannot send the number 0. For example, if I define the string data in a calculation function as;

STRING[0]=5
STRING[1]=150
STRING[2]=0
STRING[3]=10
STRING[4]=75

Then send via RS232; Only STRING[0] and STRING[1] are sent. This is backed up by the simulation which highlights this. A '0' terminates the string.

Unfortunately for me, there are multiple variables in my program which could have a 0 like time for instance . I thought about trying an if function like;

if
Variable 2 = 0
then
String[2] = 255

but this would take too many functions as there are lots of variables and I actually need the number 255.

Hopefully this all makes sense.

Any help would be greatly appreciated.

Cheers

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times

Re: HOW TO SEND '0' IN A STRING VIA RS232

Post by Spanish_dude »

Use an array of bytes instead of a string.
Use the "sendbyte" macro into a loop and that's pretty much it.

Hope this helps.

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: HOW TO SEND '0' IN A STRING VIA RS232

Post by Benj »

Hello,

You have two options.

1) you could transfer the values as ascii eg 0 would become '0' and 255 would be '2', '5' and '5'. To do this you would need a routine to parse the string and convert to ascii characters. The downside to this is that you will need to repeat the process in reverse at the other end of the RS232.

2) Otherwise you can change the properties for the RS232 component so that the return type is an int and this way you will be able to send and receive the value 255. As for sending 0 in a string, spanish_dude is correct, you can simply read the length of the string and then use a loop to run through the bytes in the string sending them one at a time through the RS232.

Post Reply