Sign in to follow this  
Followers 0
pszczepan

Smart solution for converting ASCII to HEX and comparing

4 posts in this topic

Hi guys First thing I made. When I trigger INput in my PLC the scale current value is transmitted to PLC and the string is converted to HEX. I made a value from them and code automaticly makes down threshold and upper threshold. f.e. value from scale is 162 f.e down threshold will be 156 f.e upper threshold will be 168 It works - maybe it is not very smart, but I make it just once and the effective is enough. Now I have to receive values from the scale - they are as showed below Every short time I need to convert received ASCII string to HEX - makes value from it and compare with thresholds. If the value is between threshold the PLC Output is going ON. I have some idea how to make it, but maybe you guys could recommend any smart and fast solution. Thanks for any clue Pawe? Edited by pszczepan

Share this post


Link to post
Share on other sites
First question - Is the scale transmitted packet always same length. IE will twenty one {21} weight units and thirty one {31} weight units have the one {1} or ascii 31 in the same register?

Share this post


Link to post
Share on other sites
I guess the {20} (spaces) are used to pad the reply to the same length. I don't know the scale type, but I used a MettlerToledo scale recently, and this was the case. Can we use the HEX instruction (ASCII to hex conversion) - here's an example of it. Thinking more, does this work....? Take the raw byte character, AND with 2#11001111 and you're left with the decimal. Then (100*FirstNumber)+(10*SecondNumber)+(1*ThirdNumber) is the whole value? Footnote - Maths in the CPM2 is my worst nightmare. Edited by ParaffinPower

Share this post


Link to post
Share on other sites
Finally I decided to use MOVD Simply I used 8 times MOVD instruction with uniqe DI parameter and in one cycle I got my scale value in BCD without using instruction HEX f.e. I received 16 bytes from scale and they are starting from DM10 dm10 is #2020 when I use MOVD I have first two digits of my scale value in DM20 - they are 00 After 8 MOVD I have value from the scale. It really works and it's fast Thanks for help

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0