Page 1 of 1

Compairing Numbers

Posted: Mon Jul 09, 2012 11:15 am
by jollybv
Hi there

Is there any way of comparing 2 bite variable without converting them to strings first then comparing them ?? :?:

Brian

Re: Compairing Numbers

Posted: Mon Jul 09, 2012 1:40 pm
by Enamul
Hi Brian,

What kind of comparison you are looking for? Can you tell a bit detail?

E

Re: Compairing Numbers

Posted: Mon Jul 09, 2012 1:42 pm
by JonnyW
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

Re: Compairing Numbers

Posted: Mon Jul 09, 2012 1:47 pm
by jollybv
hi

What im trying to do is (Var 1) compair (Var 2) = result_Var where Var 1 & 2 are Byte variables

Brian

Re: Compairing Numbers

Posted: Mon Jul 09, 2012 1:59 pm
by Enamul
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...

Re: Compairing Numbers

Posted: Mon Jul 09, 2012 2:04 pm
by jollybv
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

Re: Compairing Numbers

Posted: Mon Jul 09, 2012 2:59 pm
by Enamul
Hi,
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.
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?

Is that what you are looking for?

Enamul

Re: Compairing Numbers

Posted: Mon Jul 09, 2012 3:19 pm
by jollybv
Enamul wrote:Hi,
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.
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?

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

Re: Compairing Numbers

Posted: Mon Jul 09, 2012 4:04 pm
by JonnyW
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:

Code: Select all

result = (byte0 == byte1)
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:

Code: Select all

received_byte & 1 // Check for RB0

Code: Select all

received_byte & 2 // Check for RB1
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

Re: Compairing Numbers

Posted: Mon Jul 09, 2012 4:55 pm
by jollybv
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

Re: Compairing Numbers

Posted: Mon Jul 09, 2012 9:58 pm
by JonnyW
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

Re: Compairing Numbers

Posted: Tue Jul 10, 2012 10:55 am
by Enamul
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

Re: Compairing Numbers

Posted: Wed Jul 11, 2012 12:37 am
by Enamul
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