Help - Search - Members - Calendar
Full Version: How change strings on ASCII to integer positive or negative?
Forums.MrPLC.com > PLCs and Supporting Devices > Allen Bradley
crsgab
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 thumbsupsmileyanim.gif

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
Smoke
Do you mean something like this?

[attachmentid=3287]
crsgab
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ˇˇˇ
TWControls
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?

geniusintraining
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) thumbsupsmileyanim.gif
Ken Roach
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.


geniusintraining
QUOTE(crsgab @ Oct 10 2006, 03:28 PM) [snapback]41499[/snapback]
Hi:

...with a micrologix 1200 ...



QUOTE(Ken Roach @ Oct 10 2006, 08:42 PM) [snapback]41518[/snapback]
The SLC-500 doesn't have a String-to-Real (floating-point) instruction, so he must be using the string-to-Integer then dividing....


So would that be the same with the micro?
Ken Roach
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.
Smoke
I came up with this.

[attachmentid=3298]
[attachmentid=3299]

Ken Roach
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.
crsgab
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

geniusintraining
QUOTE(crsgab @ Oct 11 2006, 06:55 PM) [snapback]41579[/snapback]
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 ...


clapping.gif very nice....can you tell me part numbers? I would like to try the same
crsgab
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 dancered.gif

Regards
geniusintraining
Thank you very much... notworthy.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.