03-26-2025 12:49 PM
Hello all, apologies if this isn't the best board for this, I couldn't decide between posting on LabView, Digital IO, Modbus, DQMH, etc.
My question really will boil down to "am I missing an obvious way of doing this that's less of a pain in the butt than what I'm planning?" I don't have any reference for how this is typically done, but surely you folks with more experience in industrial automation will know how to do this.
Background
I'm writing an application that will control a number of valves and other hardware components, each one through a number of digital I/O outputs. To create the outputs, I'm using a Phoenix Contact bus coupler with "smart elements", which is communicating with the LabView program via Modbus/TCP. The software I'm writing is using DQMH, and I have a cloned module for each hardware unit. Ideally, I'd like these modules to write directly to the modbus instance instead of sending a command somewhere else in the software.
My problem
On this bus coupler, I have a 16 pin digital output element. In a perfect world, each pin would have its own address and I could talk to each pin individually. But I have to write a 16 bit value to a single register in order to flip a pin's output. So if I want to exclusively turn on pin 5, I have to write 0000100000000000 (ignoring 0 addressing, enddianness, etc. Just for the sake of example). This obviously turns off all pins except for pin 5. If we imagine there are 4 pins per hardware unit that I'm controlling, and the current state looks like this: 0000 1000 1101 1000, I might want to change the second one from 1000 to 0100. The way I could do this, is by creating a bitmask: 0000111100000000, reading the current state, and doing something like writing the register with 0000 0100 0000 0000 OR (!bitmask AND current). This feels like a horrible way to go about this though, and I think it breaks encapsulation, because it requires the state of all of my hardware to be reading and potentially modifying the state of other hardware.
My other thought of how I could do this is to have a separate DO expansion for each unit of hardware. So if I had 4 units I'm controlling, I'd have 4 DO modules, and I'd just ignore the 12 wasted DO pins per module. That's less cost effective, but seems easier to debug if something goes wrong and doesn't have the complexity problem.