Page 1 of 1
A difficult binary operation for me:(
Posted: Tue Oct 23, 2012 6:28 am
by memethemyn
Hi..
In a project I use 9 of Emotron VFX drives. But in modbus the emotron uses its own procedure like EInt.
That I want to read input registers I must take an 16 bit data and the value I need the first 11 bit and then convert it to decimal again..
For example I take a data as 61563
it is 111100
0001111011
the blue bits its my real value.. when I convert the blue bits to decimal I took 123 the value what I want..
How can I do this
Help please..
Re: A difficult binary operation for me:(
Posted: Tue Oct 23, 2012 8:36 am
by Patrick Hall
I may be mistaken, but I think what you want is something like this..
- ModbusTag_BitMapped.png (10.94 KiB) Viewed 7679 times
If your Emotron drive were actually using Modbus Register 40000 for your 61563 value, then by mapping a tag to 40000.0-10 (default controller register size is INT16 but you can change it to UINT16 if you prefer un-signed behavior). The result is that the Value of Tag1 is driven by just the 11 bits specified by the ".0-10" portion. If you were to write a value from the HMI back to this tag (assuming read/write) then the value written would be masked by the bits specified as well.
Re: A difficult binary operation for me:(
Posted: Tue Oct 23, 2012 9:14 am
by memethemyn
A question again:(
I tried to solve the problem as you described but I want a little cheat..
I planned to masking the bits and I wrote a sample code as you see below:
Code: Select all
int deger1;
int deger2;
int deger3;
deger1 = (Globals.Tags.deger1.Value);
deger2 = (Globals.Tags.deger2.Value);
deger3 = deger1°er2;
but these codes didnt give me a result.
Where is the wrong
Re: A difficult binary operation for me:(
Posted: Tue Oct 23, 2012 9:36 am
by mark.monroe
Maybe this
post will help.
If you are using & both numbers will have to have a 1 in them for it to stay a one.
1111 1000 & 0011 1111 = 0011 1000
Are you sure your mask is correct? You may want to use uints so that you do not have to deal with the sign bit.