Jump to content
Sign in to follow this  
Mark Silka

Modbus word to bit array

Recommended Posts

We have a UniStream HMI which is connected to a remote Modbus Slave (Prosoft PLX31 Modbus Gateway)

I need to read the bits from particular words which hold the status of sensors mapped to the Gateway tables.

On the holding register entry page, it does not allow for just reading 1 bit of a word.

Is there a work-around or some example of plc logic that will take that register and read the bits into a bit-array?

 

Thank you,

Share this post


Link to post
Share on other sites

Hi Mark,

You can read the whole word to an integer (using R.H.R command) and then use the Ladder element NUM to Bits (You can find it under the logic menu in the toolbox).

This element will convert the integer to array of bits. (Please make sure to create the array of bits in the correct length).

 

  • Upvote 2

Share this post


Link to post
Share on other sites

I stumbled upon exactly the same problem the very first moment I begun working with MODBUS on Unistream.
I'd rather disagree with the method Ofir proposed. It is nevertheless correct way how to accomplish that, however it is redundant and unnecessarily bulky.

There are a lot of MODBUS devices that keep their status information (in form of bit fields) in their holding registers and receives commands the same way - by changing bit values of input registers. Not a single coil is even made available.

Thus it would be very conventional way to gather whatever commands are needed via separate bits of the bit array, and wtite them to MODBUS target in single register-wide operation. Exactly the same the opposite way - read holding register directly into bit array of fixed length (8;16;32) and then use the bits for whatever they are meant for.

The method Ofir proposed - doubles the amount of data storage necessary (first for storing int, then once again for storing bits), plus the unnecessary ladder elements for conversion. When doing the same thing in  C it is done the most simple and conventional way it could be done - you can reference the same chunk of memory in whatever way you may imagine - as bits, as array, as ints, words, chars...

I guess the underlying software of UniLogic/Unistream is written in C anyway, thus it could not be very hard to arrange the data within it the same way.

So, what I'm asking for is a single change within MODBUS data definition part - please remove restriction to use Bit Array (of fixed length, or even of arbitrary length with automatic padding with leading zeros) as Tag for storage of Register transmission contents.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...