Sign in to follow this  
Followers 0
crsgab

How change strings on ASCII to integer positive or negative?

14 posts in this topic

Hi: This is the first time I write on this forum , always that I have a doubt about something I enter this forum and reading the topics I have found the correct answer In this moment I'm developing a project , we want to connect a go-no go measure system with a micrologix 1200 in order to control the highness of motor shaft and with a limit instruction accept or reject a part. In fact I have connected the measure system and is sending measurements to PLC on ASCII code but the problem is that sends measures from -0.0010 to +0.0010 it doesn't send integer part just floating and also they are sent as strings, I have no problem using the extract string instruction and after convert that measures on floating numbers , my problem is how can I manipulate the minus (-) or plus (+) signals that sends the measure system as strings so PLC knows when measure is positive or negative? If you can suggest something would be fantastic. Thank you Best regards

Share this post


Link to post
Share on other sites
Do you mean something like this?

Share this post


Link to post
Share on other sites
Hi: I mean , if there is a way for PLC to interpret the (-) minus or (+) plus signal when they are received as a string , as I can got positive or negative string measurements for example: If I got a string on ST9 file like -0.0015 how can I convert or how PLC can interpret is a negative measure? thanks¡¡¡

Share this post


Link to post
Share on other sites
Use Smokes STOR and then look for the result to be GEQ than 0 for positive or LES for negative. This would make 0 a positive number. Sub question - Is 0 positive or negative assuming neither is not an answer?

Share this post


Link to post
Share on other sites
crsgab, I also do a lot of measurements, but I use the go/no-go from the controller to my PLC as a digital input, I have just found it more reliable that way, are you using a linear probe that is a ASCII input or does it go to a measuring device? then out from the controller to your plc? The majority of my controlers are Mitutoyo's (they are great)

Share this post


Link to post
Share on other sites
The SLC-500 doesn't have a String-to-Real (floating-point) instruction, so he must be using the string-to-Integer then dividing. I think the most straightforward thing is to check the first Data byte of the String for the ASCII minus sign symbol, then multiply the value by -1. Ascii minus sign = 2D hex = 45 decimal. You'll have to use a MVM masked move to get just the first character of the ST9:0.Data[0] word, then compare that value to 2d00 hex = 11520 decimal to check for a minus sign.

Share this post


Link to post
Share on other sites
Thanks for pointing that out, GiT. I must have mentally substituted SLC for MicroLogix when looking at the ControlLogix tag data type example. The MicroLogix 1100, 1200, and 1500 have some special functions (like the high-speed counters) that are different from the SLC-5/03,4,5, but the ASCII instruction set of the SLC and MicroLogix are the same. All the "extract a number from a string" instructions search the string for the first numeric character, so they'll ignore + or - signs (as far as I've seen). Since the + or - will be the first character in any case, I think that checking for its ASCII code is the simplest approach. Edited by Ken Roach

Share this post


Link to post
Share on other sites
I came up with this.

Share this post


Link to post
Share on other sites
What I'd add to the first section there is a masked move (MVM) of the first Data word of the string. In many cases (and perhaps all of the cases noted by the original poster) the first two characters will be "-0", but if the first digit isn't a zero, the EQU statement will be incorrect. I'd do a MVM of ST9:0.Data[0] with a mask of FF00 (hex) into a holding register like N7:0, then compare it to 2d00 (hex) = 11520 (decimal) to check for a minus sign. 2d (hex) = 45 (decimal) = minus sign (ASCII). In ControlLogix this is a little simpler because there is a string-to-Real instruction, but I still get requests to round or truncate the number of decimal places. Floating point isn't magic, just math.

Share this post


Link to post
Share on other sites
I have done it as Ken said and is working amazingly :D Thanks a lot ¡¡ I'm using a Mahr Federal go/no go it has one interfase that sends ASCII code on a DB9 conector, so the measure I get from meter is the same I get on PLC , we use it on this way because was cheaper than a Mitutoyo controller. The only detail is to make an special conector to adapt from micrologix din conector to db9 male measurement system :D Best regards

Share this post


Link to post
Share on other sites
Hi: These are number parts that we are using from Mahr Federal: Description Part Number REMOTE INDICATING UNIT, MAXUM3 2033011 WITH DATA OUTPUT -6PIN CABLE, SERIAL DATA, MAXUMIII 2239036 6-PIN TO PC 9-PIN. DIGITAL TRANSDUCER, "PENCIL" 2033099 3/8 OD X 4.0" +-.04" TRAVEL In fact you can select a different digital transducer to fit your process Regards

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