Compairing Numbers
Moderator: Benj
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Compairing Numbers
Hi there
Is there any way of comparing 2 bite variable without converting them to strings first then comparing them ??
Brian
Is there any way of comparing 2 bite variable without converting them to strings first then comparing them ??
Brian
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Compairing Numbers
Hi Brian,
What kind of comparison you are looking for? Can you tell a bit detail?
E
What kind of comparison you are looking for? Can you tell a bit detail?
E
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Compairing Numbers
Hi. To test whether the byte values are equal you can add the code 'variable1 == variable2' into a decision or calculation icon. Other operators are != for not-equal, and <, >, <= >=.
You should not need to convert to strings to do anything other than display the numbers.
Jonny
You should not need to convert to strings to do anything other than display the numbers.
Jonny
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: Compairing Numbers
hi
What im trying to do is (Var 1) compair (Var 2) = result_Var where Var 1 & 2 are Byte variables
Brian
What im trying to do is (Var 1) compair (Var 2) = result_Var where Var 1 & 2 are Byte variables
Brian
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Compairing Numbers
Hi,
Compare$(string1, string2, compare_type)
Compares the two strings, parameters 1 and 2, and returns a BYTE value corresponding to the following results:
0 = strings are identical
1 = string1>string2
255 = string2>string1
You can generate this kind of function using the attached FC...
Compare$(string1, string2, compare_type)
Compares the two strings, parameters 1 and 2, and returns a BYTE value corresponding to the following results:
0 = strings are identical
1 = string1>string2
255 = string2>string1
You can generate this kind of function using the attached FC...
- Attachments
-
- compare.fcf
- (14.5 KiB) Downloaded 374 times
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: Compairing Numbers
I am really stuck what I have is a master panel a number of slave boards all with 10 outputs they all daisy-chained together on the RS232 port on each board I have a dip switch to set up the board address
eg:
RB0 = 1
RB1 = 2
RB3 = 4
RB4 = 8
RB5 = 16
so if switch (1 is on board is selected with outputs 1 to 10) is to be used switch ( 1 + 2 is on board selected as 3 and outputs 21 to 30) are used
I send a string from the main board 0011 which the first 3 bits 001 is the address of the first output of board now what must happen when i get to n 011, 012, 013, 014 .... 020 it must know that it is on board 2 (RB1 on) which is outputs 11 to 20.
Can anyone help as this is driving me crazy
eg:
RB0 = 1
RB1 = 2
RB3 = 4
RB4 = 8
RB5 = 16
so if switch (1 is on board is selected with outputs 1 to 10) is to be used switch ( 1 + 2 is on board selected as 3 and outputs 21 to 30) are used
I send a string from the main board 0011 which the first 3 bits 001 is the address of the first output of board now what must happen when i get to n 011, 012, 013, 014 .... 020 it must know that it is on board 2 (RB1 on) which is outputs 11 to 20.
Can anyone help as this is driving me crazy
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Compairing Numbers
Hi,
Is that what you are looking for?
Enamul
So, you want to compare 011 or 012 etc. out of 0011/0012 in the slave boards to confirm this request for output 11/12 in board 2?I send a string from the main board 0011 which the first 3 bits 001 is the address of the first output of board now what must happen when i get to n 011, 012, 013, 014 .... 020 it must know that it is on board 2 (RB1 on) which is outputs 11 to 20.
Is that what you are looking for?
Enamul
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: Compairing Numbers
Enamul wrote:Hi,So, you want to compare 011 or 012 etc. out of 0011 in the slave boards to confirm this request for output 11/12 in board 2?I send a string from the main board 0011 which the first 3 bits 001 is the address of the first output of board now what must happen when i get to n 011, 012, 013, 014 .... 020 it must know that it is on board 2 (RB1 on) which is outputs 11 to 20.
Is that what you are looking for?
Enamul
No what I'm trying to do is set the boards address up with a dip switch on RB port then when i send the data it must know what board to go to eg: switch 1 on, on one of the slave board in board is set to output from 1 to 10 and if switch 4 is on on another slave board 1t must output 31 to 40. All the slave boards have 10 relay output on them so if i have 5 boards connected it will have 50 outputs 1 to 50
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Compairing Numbers
Hello. Sometimes it helps to simplify the problem - your program sounds like it has a lot going on which is incidental to the problem you are having.
Are you receiving your input data as a byte or as a string? If possible, avoid string processing as it takes needless processing and memory.
To compare 2 byte values and store the result, create a calculation icon and write in it:
Here 'result' will be 1 if byte0 and byte1 are equal, 0 if they are not. Use the simulation mode to confirm your results.
You also seem to be mixing bit-masks with numbers. 012, for example, is not a valid binary number. My advice is ignore strings for this entirely - send a single byte representing up to 8 boards.
Then you can test for a particular board. Add in a series of decision icons:
And so on.
Down the 'yes' branch put your code to send data to that board.
I would test this without the hardship of HW first by fixing the value of received_byte and seeing if the behaviour is what you expect in simulation.
I hope this is of use,
Jonny
Are you receiving your input data as a byte or as a string? If possible, avoid string processing as it takes needless processing and memory.
To compare 2 byte values and store the result, create a calculation icon and write in it:
Code: Select all
result = (byte0 == byte1)
You also seem to be mixing bit-masks with numbers. 012, for example, is not a valid binary number. My advice is ignore strings for this entirely - send a single byte representing up to 8 boards.
Then you can test for a particular board. Add in a series of decision icons:
Code: Select all
received_byte & 1 // Check for RB0
Code: Select all
received_byte & 2 // Check for RB1
Down the 'yes' branch put your code to send data to that board.
I would test this without the hardship of HW first by fixing the value of received_byte and seeing if the behaviour is what you expect in simulation.
I hope this is of use,
Jonny
- jollybv
- Flowcode v5 User
- Posts: 374
- Joined: Thu Feb 12, 2009 5:20 am
- Location: Cape Town
- Has thanked: 81 times
- Been thanked: 25 times
- Contact:
Re: Compairing Numbers
Hi Jonny
Thanks for the reply I am sending the data as a string as I do not know how to send it as a byte over the RS232 port could you please explain
Brian
Thanks for the reply I am sending the data as a string as I do not know how to send it as a byte over the RS232 port could you please explain
Brian
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Compairing Numbers
Hi. All a string is is an array of bytes, so you are really already sending a byte over RS232. There are RS232 calls in Flowcode SendRS232Char and ReceiveRS232Char which send a byte - a char and a byte are the same thing.
All you are doing by converting a byte to a binary text string is creating the need to send 8 bytes instead of 1. Once you are sending a single byte try hard-coding the values you are receiving and test these in simulation to make sure your code works before putting it on HW.
Good luck with your program.
Jonny
All you are doing by converting a byte to a binary text string is creating the need to send 8 bytes instead of 1. Once you are sending a single byte try hard-coding the values you are receiving and test these in simulation to make sure your code works before putting it on HW.
Good luck with your program.
Jonny
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Compairing Numbers
Hi Brian,
You can use Vnet to simulate master-slave RS232 communication using FC..Here goes the link for that...
http://www.matrixmultimedia.com/mmforum ... =26&t=6649
Ben has describe there excellent how to simulate..Vnet
You can use Vnet to simulate master-slave RS232 communication using FC..Here goes the link for that...
http://www.matrixmultimedia.com/mmforum ... =26&t=6649
Ben has describe there excellent how to simulate..Vnet
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Compairing Numbers
HI Brian,
I have tried to make two FC for you. One for master which just send 0011 as string repetitively. Other one is slave_1 which will receive that and take out "011" from the string and convert the string to number,. i.e. 011 in number..
Hope this will help
Enamul
I have tried to make two FC for you. One for master which just send 0011 as string repetitively. Other one is slave_1 which will receive that and take out "011" from the string and convert the string to number,. i.e. 011 in number..
Hope this will help
Enamul
- Attachments
-
- slave_1.fcf
- (12.48 KiB) Downloaded 281 times
-
- Master.fcf
- (7 KiB) Downloaded 286 times