QSI Corporation

Manufacturer of Mobile Data and Operator Interface Terminals

Skip to content

Modbus 32 bit integers

Questions regaring the Qlarity language and Qlarity Foundry software.

Please read the Qlarity FAQ before posting to this forum.

Moderators: Jeremy, QSI Software Support

Modbus 32 bit integers

Postby jentem on Thu Jan 21, 2010 11:17 am

Quick question about the use of reading a 32 bit integer from a modbus slave, it seems to show the wrong value. Almost like the value is being rounded off on the low byte.
jentem
 
Posts: 9
Joined: Thu Jan 21, 2010 11:04 am

Re: Modbus 32 bit integers

Postby Ron L. on Thu Jan 21, 2010 11:29 am

I'm going to assume your using an MBRegister object or similar to read the value. Here are some properties you can check or try changing.
1. On the MBRegister object verify the vartype is set to mb_int32.
2. You may want to try changing the register property in case your address if off by 1.
You'll also want to look at some properties on the ModbusComm object.
3. Make sure your wordsize is set to mb_16bit. It is very rare for the wordsize to be different that 16-bit.
4. Try toggling the swapword property to see if it makes any difference.
User avatar
Ron L.
 
Posts: 352
Joined: Thu Mar 02, 2006 2:12 pm
Location: Salt Lake City, Utah

Re: Modbus 32 bit integers

Postby jentem on Thu Jan 21, 2010 11:39 am

ok, so to confirm, the ModbusComm object is set to 16bit, the VirtualRegister is set for 32 bit int. In my modbus simulator i have register 1 set for as 0xDEAD and register 2 is 0xBEEF, when i read the registers individually as 16 bit and print them to a label in hex format they read normally, but when i read as a 32bit i get BEEFDE80 and using swapword i get DEADBF00.
jentem
 
Posts: 9
Joined: Thu Jan 21, 2010 11:04 am

Re: Modbus 32 bit integers

Postby Ron L. on Thu Jan 21, 2010 11:50 am

Are you using the signed or unsigned 16 bit? The conversion problem could be that your expecting the 32bit to convert as an un-signed 32bit would. To get the exact hex your looking for from a 32-bit signed, you may need to use GetBytes to convert the 32bit integer to 4 bytes, then use FromBytes function to convert the 4 bytes to two unsigned ints (unibytes in Qlarity). Then convert the two unibytes to hex using the function _FormatAsHex.
User avatar
Ron L.
 
Posts: 352
Joined: Thu Mar 02, 2006 2:12 pm
Location: Salt Lake City, Utah

Re: Modbus 32 bit integers

Postby Jeremy on Thu Jan 21, 2010 11:55 am

If you can simplify this to a workspace with a single register object that queries those two consecutive registers, it might be helpful if you can post a screen shot of your Simulation View Communication Window (Be sure to turn on Hexidecimal display first).
User avatar
Jeremy
QSI Support
QSI Support
 
Posts: 679
Joined: Wed Mar 08, 2006 12:25 pm
Location: Salt Lake City, Utah

Re: Modbus 32 bit integers

Postby jentem on Thu Jan 21, 2010 1:23 pm

Ok here is a screen shot.
ModbusComm is set for 16bit registers, swapword is false
Virtual Registers are set accordingly as Int16's and a Int32.
Valuechanged code in each Virtual Register is "Label1.value = _FormatAsHex(value,8,true)"
Attachments
Qlarity_Error1.gif
Qlarity_Error1.gif (20.68 KiB) Viewed 235 times
jentem
 
Posts: 9
Joined: Thu Jan 21, 2010 11:04 am

Re: Modbus 32 bit integers

Postby jentem on Thu Jan 21, 2010 1:32 pm

Sorry about that here is the proper picture.
Attachments
Qlarity_Error2.gif
Qlarity_Error2.gif (95.28 KiB) Viewed 238 times
jentem
 
Posts: 9
Joined: Thu Jan 21, 2010 11:04 am

Re: Modbus 32 bit integers

Postby Ron L. on Thu Jan 21, 2010 3:09 pm

I don't see any problems with the data going back and forth. It's as I would expect. I'm probably going to need to look at your workspace to help.
User avatar
Ron L.
 
Posts: 352
Joined: Thu Mar 02, 2006 2:12 pm
Location: Salt Lake City, Utah

Re: Modbus 32 bit integers

Postby jentem on Thu Jan 21, 2010 3:18 pm

Yes the data looks fine but what is being displayed on the label is not.
Attachments
integererror.qly
(6.83 KiB) Downloaded 5 times
jentem
 
Posts: 9
Joined: Thu Jan 21, 2010 11:04 am

Re: Modbus 32 bit integers

Postby Ron L. on Thu Jan 21, 2010 3:49 pm

I've reproduced the problem. To fix, change this code:

Code: Select all
Data_32_400001.value = _FormatAsHex(value,8,true)


to

Code: Select all
Data_32_400001.value = _FormatAsHex(intvalue,8,true)


You were losing precision when casting from a float32 which is what the property value is. To avoid this, use the intvalue property instead.
User avatar
Ron L.
 
Posts: 352
Joined: Thu Mar 02, 2006 2:12 pm
Location: Salt Lake City, Utah

Re: Modbus 32 bit integers

Postby jentem on Thu Jan 21, 2010 4:04 pm

Ah i see, Thank you guys for the excellent support on this.
jentem
 
Posts: 9
Joined: Thu Jan 21, 2010 11:04 am


Return to Qlarity Software Support

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron