Studio 5000 Creating a Lookup Table
I am receiving an integer via modbus from a motor protection relay that can be one of ~250 values telling me why the motor shutdown. I need to write to a string based on the value of the integer. For instance, a 0 input would mean no shutdowns active, a 1 would mean Forced Setpoints dump, a 2 would mean Speed Switch Trip etc. I could write logic (see link) to Copy the value from an array of strings into a tag, but that would mean 250 rungs of code, and I need to do this for five motors, so that would be a lot of time. Is there a better way to do this?
Edit: I used one bpeck451's solution and it worked great. I updated the Imgur pics to show the ladder logic in case anyone is interested. Thank you to everyone who responded. Please note: I did have to do a MOV block from my modbus register to a controller tag that didn't have brackets in order for it to work correctly.
Posted Feb 3, 2020, 1:43 PM UTC · edited
Make an array of strings with all those strings in it and just reference the individual elements. Use the Modbus value you use for the array element. As long as the states all map the same it should make your rung count really low.
AB does the this for description and error lists with PlantPAX.
Depending on the platform, you may want to apply a bounds check before indexing the array.
If you take that modbus value you were talking about and put it in a variable you should be able to use COLT_Array[Modbus_Val]. As long as Modbus_Val is of the right data type it will work.
Like the u/con247 said do some bounds checking. You WILL crash a compactlogix if you mess that up. I'm not sure about a controllogix since I haven't actually crashed one of those for this reason. But it's a better safe than sorry kind of thing.
Yeah, it will also cause a major controller fault on a ControlLogix. Definitely add in bounds (starting with a SIZE is usually helpful!)
I did this and it worked great. I updated the Imgur pics to show the ladder logic in case anyone is interested. Thank you to everyone who responded.
Sounds good, I will give that a try. Thanks!
Move/Copy COLT_Array[NameOfTag] into AlarmStringDescription
There should be instructions in the help of how to do indirect addressing. There may not be this exact example, but enough to understand how it works.