mmervenne Posted January 12, 2006 Report Posted January 12, 2006 Hello all, I am pulling in a position measurement serially. I would like to know how i can convert this ASCII String to a number to use for comparisons, etc. Any help is greatly appreciated. Quote
panic mode Posted January 12, 2006 Report Posted January 12, 2006 you have to be more specific... what plc and what number formats (in and out)? for example, plc is FX2N, input is something like "123.45" and output should be integer 12345 or maybe float 123.45 Quote
mmervenne Posted January 12, 2006 Author Report Posted January 12, 2006 The PLC is a FX2N, the input is "21.23" and the output format is float. For example 21.23. Thanks for the reply. Quote
panic mode Posted January 12, 2006 Report Posted January 12, 2006 take a look at hex instruction Quote
Paulio Posted May 17, 2006 Report Posted May 17, 2006 I am trying to do a similar thing in a Q00J. Is this possible? HEX is not supported on this. Quote
panic mode Posted May 17, 2006 Report Posted May 17, 2006 According to SH(NA)080039, section 7, Q plcs (except basic models) come with HEX, HEXP instructions as well. If you have to use such CPU you can make your own function to do this. Quote
FNMdeJong Posted May 18, 2006 Report Posted May 18, 2006 Try to use the instruction EVAL -> conversion from string to real (floating point). This function can be used on the basic models of the system Q CPU. Take a look at the programming manual for a detailed explanaition. Be aware to check the serial number on the PLC CPU (first 5 digits must be 04122 or later. Quote
waynes Posted May 19, 2006 Report Posted May 19, 2006 mmervenne, To convert the ASCII to numbers directly, you can simply subtract H30 from the D register values. If you receive the data in 16-bit form, you will need to split the word into the two bytes, then subtract the constant (H30). Then proceed by multiplying the split bytes with their base values. Receiving "123.45" Translated as H31 H32 H33 H2E H34 H35 (These values are typically stored in D registers when you received the data (D0 D1 D2 D3 D4 D5 for 8 bit comms; D0 D1 D2 for 16 bit comms). for 8 bit If you Sub D0 H30 D100 - (Do this to the rest) D100 will contain the value '1'. Result will be D0= '1', D1= '2' D2= '3', D3='-1', D4= '4', D5= '5'. Now, you can simplify it for yourself. I would try and not transmit the "." via the comms. Just receive "12345"- only if you know that the value will always contain two decimal places. Multiply D0 with K10000; D1 * K1000; D2 * K100; D4 * K10; D5 * K1. Add all these new values together and you will have the value recreated in the PLC. This might be the long way round, but it works.... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.