![]() |
||
|
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. |
||
| ||
New Here? Please read this important info!!!
|
|||||||
![]() |
If you're really looking to learn about PLCs, you NEED our book... "Your Personal PLC Tutor - A Guide to Understanding PLCs" Easy to read and uses 'plain' language!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Member
|
ASCII input to PLC-5 - converting strings to numbers
this is a request posted on another forum ...
Quote:
link to original post on the other forum greetings, umesh9554, first of all, thanks for a very specific statement of your program’s requirements ... unfortunately most people don’t go to the trouble of providing a detailed example of the data format ... I do have one question though ... are your data values always “zero filled”? ... let me explain by using the first parameter as an example ... you gave this parameter as the five characters “##.##” ... based on this I would expect the value “12.34” to be transmitted as “12.34” ... that’s simple enough ... but consider the value “1.2” for the first parameter ... question: will that be transmitted as the full five characters “01.20” ... or as just three characters “1.2” ... let’s hope that it will be the former ... because if the number of characters varies, then the program I’ve written will require some SUBSTANTIAL modifications ... it CAN be done so let me know if this added functionality is required ... basically my program consists of a subroutine which uses an ABL (ASCII Test For Line) instruction to continuously monitor the PLC’s serial port for a new data string ... whenever new data is received, an ARL (ASCII Read Line) instruction gets the data and stores it in a string location ... next AEX (String Extract) instructions are used to retrieve the “whole number” and the “fractional portion” for the parameter ... at this point, the data is still in a “string” format ... if you’re not exactly sure what that means, just think of it as “text only” data ... specifically, it may “look like” a number but it has no “real” numerical value ... and so ACI (String to Integer) instructions are used to convert from the “string” type data into true numerical values ... these values are temporarily stored in integer locations ... next, a MUL (Multiply) instruction is used to convert the integer value representing the “fractional portion” of the parameter into its actual “decimal” equivalent value ... example: the integer value “34” is multiplied by “0.01” and becomes “0.34” ... writing this “decimal” value directly into a floating point location (one reserved for this specific parameter) has the effect of overwriting any existing value from the last data string ... now we use an ADD (Addition) instruction to add in the “whole number” portion of the parameter ... and the first parameter is done ... and then we move on to the next parameter following the same type of conversion methods ... you’ll notice that some of the parameters don’t even have a “fractional portion” so the conversion process is slightly easier in those cases ... once the “whole number” is converted from a string into an integer value, then only a simple MOV (Move) instruction is required to finish up by storing the number in a floating point location ... I’ve kept the layout of the program rungs extremely simple on purpose ... this will make it a lot easier for you to accommodate any future modifications to the format of your data string ... the whole conversion routine could be made more “elegant” by using a recursive loop construction and by using indirect addressing to move from one parameter to the next ... I’m just guessing but probably ten rungs or so would handle the whole operation ... BUT ... I would NOT recommend that approach ... you might save several rungs, but the complexity of the program would be increased many times over ... someday someone else will have to work with this program ... there’s no valid reason to make it any more complicated than it really needs to be ... rungs are cheap ... time is expensive ... finally, as for the cable connections that you’ll require ... a simple “null modem” cable is all that I used when I tested this out ... you’ll need a DB25 male connector for the PLC end ... and a DB9 female connector for the computer end ... if you turn the channel’s “hardware handshaking” off, then you’ll only need three wires connected ... from pin 2 on the DB25 male – wire to pin 2 on the DB9 female ... from pin 3 on the DB25 male – wire to pin 3 on the DB9 female ... from pin 7 on the DB25 male – wire to pin 5 on the DB9 female ... and incidentally, I used HyperTerminal to send the data from the PC to the PLC while testing my program’s operation ... here is a screen shot of the program's handling of some random data which fits your specified format ... [attachment] in case you haven’t thought about it yet ... you’ll have to set up your PLC’s Channel 0 for the “User Mode” to get the ASCII input to work ... so if you’re using Channel 0 as your only programming port, look out for serious complications down the road ... the best way to proceed is to use the PLC’s DH+ (Data Highway Plus) connection for programming and reserve Channel 0 for the serial communications ... continued in next post ...
__________________
|
|
|
|
|
#2 |
|
Member
|
continued from previous post ...
and here is the program FORMAT.RSP ...
[attachment] finally, for those who are interested in this topic but only have access to RSLogix500 software (but not to RSLogix5), I've included a copy of the program suitable for an SLC-5/04 processor ... you should be able to open FORMAT.RSS ... I hope that this will help ... best regards, Ron
__________________
|
|
|
|
#3 |
|
Member
|
and since it's a slow day ...
here is a quick screen shot of some of the critical rungs involved ...
__________________
|
|
|
|
#4 |
|
Member
|
and just in case your parameters are more "random" in format ...
greetings, umesh9554,
I had some extra time ... here is another version ... this one is a lot more flexible ... it takes ASCII data from the PLC's Channel 0 serial port and stores it in 14 floating point locations (F12:1 through F12:14). The data is made up of 14 individual numeric parameters separated by spaces. The program will handle parameters of various lengths. It will also handle negative values. Example input string: 123.45 -456 0.12 .12 4455 9 -.67 888 9 10.0 11.11 12.12 13 14.0 please post again if you have any questions ... or if you need a version in RSLogix500 format ... I'll post a screen shot, etc. on Monday if you need it ...
__________________
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Topics
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PC to PLC Protocol | TheRixta | LIVE PLC Questions And Answers | 13 | December 17th, 2008 12:56 PM |
| How to calibrate a load cell & how to program mitsubishi plc for analog input | M. HASSAN | LIVE PLC Questions And Answers | 7 | February 24th, 2005 10:53 AM |
| AB PLC analog input card 1771 IFE | diribarren | LIVE PLC Questions And Answers | 13 | May 9th, 2003 10:40 PM |
| Unusual PLC Input voltage | Christopher | LIVE PLC Questions And Answers | 5 | November 25th, 2002 03:57 AM |
| 1762-IF2OF2 Analog Input Problem | davidgay | LIVE PLC Questions And Answers | 21 | September 3rd, 2002 09:11 AM |