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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this