Jump to content

Recommended Posts

Posted
Hello Guys, I'm frustrated, I cannot work with these two functions :s I have some ascii string on HMI saved in the D95-d96 register but by some reason I cannot convert it to uint. I Think i'm using these functions correctly. Can somebody help me?

Posted (edited)
That HEX number designator doesn't seem to work the way it is described. Note --- If you have any imbedded null bytes (#00) that terminates the string and will cause the functions not to work. Try this: Edited by Mendon Systems
Posted
Hello Mendon, As you can see I think all the data coming from HMI is correct. But still nothing at the hex function, is it because that end (#00) character on the end of D96?? How can I do this? Can I shift 8 bits to the right, but in that way the #00 will be in the beginning instead of being in the end.
Posted
I am quite sure that the null in the low byte of D96 is causing your problem. If the HMI is going to store the data that way you may have to use several rungs and read each character individually.
Posted (edited)
There probably is. Will the data always be 3 digits long?? It gets a LOT more complex if it is a variable length string. IF it is always 3 digits then this should work. edit: I did a bit more tweaking. If you change the first digit designator to #11 you can get rid of the NASL instruction. String-Hex.pdf Edited by Mendon Systems
Posted (edited)
I guess there is no easy method to accomplish this. I agree with Mendon Systems that the NULL character is an issue. Where is your data stored in the NS5? I have an example of converting it from a String Display & Input object and of variable length. In this case I was able to select an option to convert 'blanks' to ASCII Spaces. Not sure if this will solve your issue but you may find some useful techniques. ASCII_to_BCD.cxp Edited by IO_Rack
Posted
This one will work with NULL characters. I'm not a big fan of ST language but it works. There is an issue where the 4 character (2 Word) address runs into the upper byte of the 3rd Word. I don't know why. For instance, if you populate D805 (upper byte), then the result in D901 will be affected.
Posted (edited)
There is also concat in st for joining strings i dont know if it suits your application: HMI_STRING_WITH_NO _GAPS:=CONCAT(HMI_STRING_A,HMI_STRING_B,HMI_STRING_C,HMI_STRING_D); OUTPUT_STRING:=STRING_TO_INT(HMI_STRING_WITH_NO _GAPS_NUMBER), or this for filling in the gaps : INSERSION POINT:= FIND(HMI_STRING_WITH_WITH_GAPS,00); HMI_STRING_WITH_NO _GAPS:= REPLACE(HMI_STRING_WITH_WITH_GAPS,NULL_CHAR,2,INSERSION POINT) Edited by professor_jonny
Posted
Hello Guys, Thanks for all the replies. In the end I used the ST string_to_uint function, it is simple enough and it does the job. I just created some internals variables linked with the double words were the strings were being saved.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...