Datatype Implicit conversion

I have inherited a large project with a lot of errors on many windows. One of my larger issues is Ignition will not coerce an AB 16 bit integer into an Ignition Integer or Short.

A template with a custom property was used to bring in an Int tag and pick out the bits with getBit(). The template appears to be functioning but every time the window loads I get an error popup anyways.

Using toInt() when linking my tag to the instance of the template in the window avoids the error but I would rather not have to apply this to every template in the project.

Is there a datatype that is compatible with an Int2? I am assuming the 2 represents it’s a 2 byte int? Shouldn’t that be a Short?

Is there a way to embed toInt() within the custom property definition in the template?

An Int2 would be a 2-byte / 16-bit integer. What error message are you getting?

Let's say your template property is tag. Would using this expression binding where you use the value inside your template accomplish what you need?


The error is:

“ClassCastException: Cannot coerce value ‘java.lang.Object@3a70ead1’ into type: class java.lang.Short”

I get this error when I supply an Int2 to the property configured as a Short.

Using toInt() inside the template does not work as I have already gotten the error on my input to the template.

I’ve been playing around with it and it looks like I can pass my Int2 to a string in the template without getting an error. Strange that I can coerce an integer to a string then back into an integer but can’t coerce an integer into an integer…

That does seem strange. How does the Int2 get into Ignition? As a tag or some other way? If as a tag, what Data Type do you have set on the tag?

You may be on to something there. Everything is coming in as a tag. The ones I am having issues with are a mix of Bytes (Int1), Shorts (Int2), and Integers (Int4).

The Bytes were being cast into Shorts, the Shorts into Integers and the Integers into Doubles. I changed everything to String earlier to make the errors go away. I will have to do some testing when I get a chance, although I would have expected this to be an easy implicit type conversion.

I did notice earlier that there is no option to create a Byte custom property. Short appears to be the smallest. Possibly why the previous guys bumped everything up. Anyone know why we’re not allowed to use a Byte?

My pure guess on this is that they were running into a sign bit issue for something that should be treated as unsigned.

For completeness, which AB PLC and driver are you using?

Yes, upcasting is needed when reading an unsigned value into a signed value (to make room in a signed tag to hold the maximum possible value of the unsigned tag).

As for binding, it only cares about the tag Data Type set in Ignition (not what it is in the PLC). So if the PLC Int2 is brought into Ignition as an Integer, you’ll need an Integer type custom property to bind it to.

The PLC is a ControlLogix 5584E. The driver is “Allen-Bradley Logix Driver”. Not sure where to find more info on the driver. As far as I can tell all the integers I’m dealing with are signed.

To make matters even more confusing, I’ve reset all some of the templates custom properties from Strings back to Integers now and the errors do not return. I’ve tried setting the property to Short, Integer, and Double then pointing to various sized Integers without any re-occurrence of the errors.

In other cases, where I have not touched the templates. I am still getting errors. Below are some screenshots of the errors I’m getting and how the template and tags are configured. The templates that I switched to String then back to Integer now have no issue with reading a Byte as an Integer…