Lookout

cancel
Showing results for 
Search instead for 
Did you mean: 

using ModbusSlave and for bitwise operation

I ran into a problem using a ModbusSlave to read a signed Integer for bitmasking.
I connected the Tag value into D40001 and read the bits from ModbusSlave1.H40002.fx (for bits 0-15) and ModbusSlave1.H40001.fx (for bits 16-31).
When the the MSB (Bit 15) was on, the number returned was a negative value, and the ModbusSlave showed no bits as set.
 
 
I alos found this to be a problem using mod( int(WORD) , 2) --> to get Bit 0
                                                       mod( int(WORD/2) , 2) --> to get Bit 1...
 
as this will return an error if WORD is negative.
 
I saw a suggestion to check for the sign bit by: if ((WORD <0), TRUE, FALSE).
How does this work if the sign bit is the only bit on (WORD = -0)?
 
 
The solution we did was to create a new Tag in the PLC as a DINT (double INT-32 bit) and add a rung to move the INT(16 bit) into this new Tag.
However I did find that this will be a problem if the MSB (bit 31) is used in the DINT.
 
The getbit function worked but I was looking for a solution other than using this as I am often working from existing PLC's and don't always have access to the PLC program to make a change like this.
 
 
0 Kudos
Message 1 of 4
(3,569 Views)
Hello DSwift,
 
Have you tried using the "S" registers for signed values? 
 
It will be helpful if you can post the LKS file for your Modbus Slave and Master.  Better yet, a simpler bare-bones file that's showing what you're trying to accomplish would be nice. 
 
Thanks,
 
-Khalid
Message 2 of 4
(3,563 Views)

Hello Khalid,

The application is pretty simple.

I am reading a tag from a AB Controllogix PLC.

Lookout is seeing it as a 16 bit signed Integer.

The tag has each bit assigned to a Photoeye or e-stop and I want to monitor each bit to see of it is true.

It can be simulated using a Pot and ModbusSlave.

I tried the "S" regsitered but did not see a value in the ModbusSlave1.H40002.fx.

Should I use another connection?

Dswift

0 Kudos
Message 3 of 4
(3,556 Views)

Hello Dswift,

It seems to work for me (with one small bug):  I used the S40001 in the ModbusSlave and wrote -3 to it.  When displayed on the panel, S40001 gives me a 65533 (which is technically correct because that's what really gets stored in the register 40001); but Lookout should interpret this as a signed number and display a -3 (this is the small bug). 

Nevertheless, when I pull the individual bits off of this using the H40001.f1 thru' H40001.f16, I do get the right bits, i.e., 1111111111111101.  Which again can represent either 65533 or -3 (two's complement of +3 using 16 bits), depending on how we interpret it. 

So, I am wondering what issue you are experiencing.  Perhaps the LSB and MSB are switched in the AB tag?  In which case you would interpret the bits in reverse order. 

I hope I haven't misunderstood your question. 

-Khalid

0 Kudos
Message 4 of 4
(3,551 Views)