Modbus, read in registers as unsigned integers

tactical

Member
Join Date
Nov 2012
Location
NE
Posts
41
Hello,

I'm using the MSG command with RSLogix 500. The values are being read in as signed integers. Is there a way I can read them in as an unsigned integer? Do I have to convert them?
 
SLC-500 integers are always Signed Integers; there is no unsigned datatype.

Are the values intended to be unsigned integers with values greater than +32767 ?
 
SLC-500 integers are always Signed Integers; there is no unsigned datatype.

Are the values intended to be unsigned integers with values greater than +32767 ?

Yes, the values are unsigned integers per the manual. Is it possible to convert them to unsigned?
 
That's the problem: there is no unsigned integer format in the SLC-500 controllers.

The MicroLogix 1100/1200/1400/1500 have a Long Integer format, which would display a 16-bit unsigned integer correctly.

Otherwise your principal option is to convert the value to Floating Point, with some possible loss of precision (though with a 16-bit value, not much).

You'll have to do a little bitwise manipulation to do this: use a Masked Move to remove the sign bit, then add +32768.0 to the resulting value if the sign bit (the highest bit, /15) is true.
 
That's the problem: there is no unsigned integer format in the SLC-500 controllers.

The MicroLogix 1100/1200/1400/1500 have a Long Integer format, which would display a 16-bit unsigned integer correctly.

Otherwise your principal option is to convert the value to Floating Point, with some possible loss of precision (though with a 16-bit value, not much).

You'll have to do a little bitwise manipulation to do this: use a Masked Move to remove the sign bit, then add +32768.0 to the resulting value if the sign bit (the highest bit, /15) is true.

Not sure if that would work? It's a 16 bit integer so the value that corresponds with -1 should be 65535. Doing what you stated would give you 32768. Instead would you do the following?

- IF the value is greater than or equal to 0, then do nothing and use that value. Else, add 65536.

- So if the value is -1, you'll add 65536, which gives you 65535
 
Here's an example:

Source Decimal Value: 54321
Source Binary Value: 2#1101010000110001

"Strip" the highest bit out using a Masked Move with all but the highest bit set, and the result is 2#0101010000110001

The decimal result is 21553. Add +32768, and you get 54321.
 
Here's an example:

Source Decimal Value: 54321
Source Binary Value: 2#1101010000110001

"Strip" the highest bit out using a Masked Move with all but the highest bit set, and the result is 2#0101010000110001

The decimal result is 21553. Add +32768, and you get 54321.

awww a see what you're doing now. I'll have to give that a try when I am back in the office tomorrow.
 
Okay, I tried the masked move but couldn't get it to work out. I believe it's because the value I have is in a data file of type N. Do I have to convert it to a binary file before the masked move? See picture below for the rung.

2my99xw.png
 
That ought to work.

Basic troubleshooting: are you sure that rung is being scanned, and nothing else is writing zeroes to B3:3 ?
 
The "mask and add" method I suggested is just because I prefer to make it really explicit what I'm doing when I manipulate data.

"If VALUE < 0 Then Add VALUE + 65536" is functionally the same thing and will give the same result.
 
Just wanted to say thanks to Ken for posting a solution. I was trying to pull a unsigned register from a modbus device using a micrologix 1400. unfortunately the modbus message doesnt support writing the unsigned registers directly to a long datatype so I was able to workaround these shortcomings using his posts.
 

Similar Topics

hi there! i am trying to read modbus registers in M340 PLC from a Turck BL20 Gateway. I have done this with a Emerson Gateway and everything...
Replies
1
Views
1,950
Dear Experts, Can you help me, I am using compactlogix cpu with ILX34-MBS485 card as Rs485 master in serial modbus network to make communication...
Replies
5
Views
2,830
Hi! Can anyone help me with ModBus TCP Read Multiple Registers(Function Code 03)? I have a Master Request: 00 00 00 00 00 06 01 03 64 06 00 07...
Replies
2
Views
3,933
Hi all, I am writing a program where the user will input a bunch of individual registers they want to read. I am going to sort these registers...
Replies
2
Views
13,717
When using the ECOM100 as a Modbus TCP Client (Master), how to do Function Code 04 (FC04) - Read Input Registers
Replies
1
Views
3,636
Back
Top Bottom