Good Morning All,
Noticed something weird today when creating a new UDT with a parameter type of floating point. I am working with Siemens PLC and I want to provide the location of a particular bit. My OPC path is set and I want the parameter to pass 107.6 for example. So the Item Path would resolve to ns=1;s=[C48]IX107.6 which works if I enter that directly.
Problem is, when I enter 107.6 as the parameter, it actually resolves to ns=1;s=[C48]IX107.5999984741211 which of course will not work.
I tried changing the type to string too just to see and it still behaves the same.
Am I missing something here?
Ok it was me being dumb. I completely forgot you can add formatting to the item path {param | ###.00}.
Sorry!
You really should be using a string for this though.
3 Likes
Hey thanks for replying - what's the reasoning for going string. I'm not opposed I'd jut like to understand. Thanks!
The OPC path is a string, so adding a float in the middle will always require doing formatting. If using a string, it will take the literal parameter and concatenate it with the rest of the path without any additional formatting needed.
Thanks Michael - I did try changing to a string but it behaved the same. Even tried deleting the parameter and re-adding it as a string but it still acted like it was a float.
It shouldn't act like that as far as I know. My initial gut would say that it still has it stored as a float. I would think deleting it and re-adding it would fix it, but have you tried adding a parameter with a different name and setting it as a string from the start to see if it makes a difference?
Was just trying that lol - yes that does make a difference. Making it a string from the start works. Thanks for sticking with me!
You may have possibly been able to switch to a string and put a non-numeric character in the parameter temporarily to force a switch, but glad it's all working.