Codesys Boolean Variables and Scratchpad

I have a bunch of boolean variables in a Codesys program that I now need to send out via MQTT Sparkplug. I am looking at writing them to the scratchpad but there is no option to store boolean variables. Will I need to change them to integer values before passing them into scratchpad?

Also is there a way to write all of these values in one block write to the scratchpad or do I need to write out the function to write the value for each tag?

Thanks

The values pushed to scratchpad will be integers, so a 0 and 1 for your use case. You can find info on the MMP functions on our developer site. You would want to use the MmpClientWriteUDINT function. So you would likely have to create an instance for each signal.

To save time, you could always use Ignition Edge onboard with MQTT Transmission to simplify this task.

Thanks,

@greichert: is there some reason MmpClientWriteBlock wouldn’t work for writing a group of values to the scratchpad in one pass?

Also, is there wisdom in considering ModbusTCP for writing values to the scratchpad instead of the MmpClient function blocks? Using ModbusTCP with a rising trigger for the write often feels simpler for me because it feels like outsourcing the nuts and bolts of the communication to the backend. In that case, move the boolean variables to the registers and then set the write bit to true to write in batch. If the function blocks are much more efficient, then obviously there’s value in that approach, but I don’t know that.

Edit: none of that is to gloss over that building a Symbol Configuration and letting Ignition handle the MQTT transmission would get my vote if Ignition is available.

The MMPClientWriteBlock is used for writing a block of string data to a MMP address. There is a tutorial here on using it.

You could use Modbus TCP as well. As for efficiency. I am not sure either. There probably is a point where it would be faster given a large enough number of data points to move.

You could do it with a for loop and a single write function and iterate through the addresses, if speed isn’t super critical, but you want a more condensed code.

Edit: All of this is to say, there are numerous ways this can be accomplished within codesys and outside.

Edit 2: I was mistaken, the block write will pack as much data in as you can use, and write over multiple mmp addresses. so you could pack all your boolean data into larger datatypes and write them as 32 ints to scratchpad. This may save time.

1 Like