ASCII Code in a Siemens program.

kea

Member
Join Date
Feb 2006
Location
Rangiora
Posts
15
HI,
We have a S7300, CPU-314 and an OP270 6" controlling a machine and have a recipe in place in the OP program whereby the part processing parameters are manually inputted and stored for each part that a customer has. There are 6 different parameters that are in the recipe, 2 are REAL values and the other 4 are INT ( the recipe also gives a name for each part). The values are stored in a data block in the PLC.
What one of our customers wants to do is instead of manually inputting the process parameters into the recipe, they want to transfer the information for a particular part from their office over a RS232C connection in ASCII code.
I was looking at using a CP340 module for doing this, but am wondering what is the easiest way to convert the ASCII code back into our recipe values.
Any ideas would be much appreciated. Thanks.
 
I don't think there's any easy way to do this, or at least I never found one. I get a telegram every 30 secs with date and time and the current temperature and required temperature of five sets of magnetic coils in ASCII format (in my case via FTP over Ethernet using a CP343-1IT, but the transport medium is irrelevant).

I just take the data Byte by Byte and convert it using brute force in a very spaghetti like piece of code! That way you can get the data into the format you require (still as an ASCII STRING, for example, Siemens use a non-standard format for REALs) and you can then use the IEC functions out of the Standard Library to convert each sub-STRING to REAL or INT as required.

I do this holding all the data in one DB and it works fine. In this application, very heavily commented spaghetti code makes it a lot easier for somebody else to follow what you're up to - IMHO not the appropriate place for loops and indirect addressing, although it might look prettier!
 
I know this doesn't answer you question, but here's some food for thought.

Are the recipe values in a database like MSSQL or Access?

Do you have an ethernet connection between the PC where the recipes are stored and the PLC?

If the answer to both of the above is yes, I would look at going that route instead of passing ACII code over RS-232.

As an alternative, I have passed recipe parameters to a PLC by going through the HMI. In this case, the HMI node was connected the the plant server via ethernet. The PLC was connected to the HMI via a proprietary PLC network. I read the values into Wonderware from the server database, displayed them for the operator to verify, and then had a button on the screen to load them into the PLC.

It's not as clean as going directly to the PLC, but it works very well. It also gives opportunity for a second pair of eyes to verify the data beofore it gets loaded.
 
The CP340 would work fine. I use them all the time when ethernet is not available or practical.

But, if there is some process in the office that is sending the data, why don't they do the conversion for you automatically? I would assume there is some kind of software needed to prepare the message, and it would be really easy to do the conversion at a high level.

If that is simply not possible, then you can do the conversion in the PLC. The integers are a piece of cake: Convert from ASCII to BCD to INT, and you're done. But the real numbers will be a pain. You will have to rip through each character, decode it, and stitch it back together again. If I remember right, there is a Siemens function in their library that will do it, or you can write your own.
 
the real numbers will be a pain. You will have to rip through each character, decode it, and stitch it back together again. If I remember right, there is a Siemens function in their library that will do it, or you can write your own.




If you can remember where that function is , I'd be glad to know it - I couldn't find anything. Having said that, it's pretty easy by brute force. If Kea's still having problems I can post my code next week.
 
Thanks for all the feed back.
I have got on to the customer to see if the conversion can be done at the send stage, and should hear back today. We are tied into RS232 as there is no other comms availiable.
It looks as though the tricky bit is going to be the REAL conversion, I will have a look for the block in the siemens library, and try writing some code to do this if I can't find it.
If I get stuck I would appreciate having a look at the code that RMA has.
 
What format will the real numbers be in ? If you are in control of the conversion process you could get them sent as two integers (if this is enough precision), one for manitissa and one for exponent and then use the ascii to int conversion and then construct the floating point number.
Alternatively you could just send the ascii value of the double word that represents the floating point number. You may as well get as much done at the PC as possible. (Many hands make light work)
 
Roy, take a look at FC39 in the IEC library. Here's a description:

The function FC39 converts a string to a variable in REAL data type format. The string must have the following format:

±v.nnnnnnnE±xx ± Signv 1 digit before the decimal pointn 7 digits after the decimal pointx 2 exponential digits

There just isn't a clean way of doing this conversion, although if you were guaranteed that the numbers were going to be in a limited range, then maybe the algorithm could be simplified. But ultimately this should be done on the top end.
 
Question

und one. I get a telegram every 30 secs with date and time and the current temperature and required temperature of five sets of magnetic coils in ASCII format (in my case via FTP over Ethernet

I just take the data Byte by Byte and convert it using brute force in a very spaghetti like piece of code! That way you can get the data into the format you require (still as an ASCII STRING, for example, Siemens use a non-standard format for REALs) and you can then use the IEC functions out of the Standard Library to convert each sub-STRING to REAL or INT as required.

I do this holding all the data in one DB and it works fine. In this application, very heavily commented spaghetti code makes it a lot easier for somebody else to follow what you're up to - IMHO not the appropriate place for loops and indirect addressing, although it might look prettier![/QUOTE]
 
Please send me an expample of a system which is worked with plc of siemens s-7 with their programming and software knowledge also.
 
Sample ASCII to String code?

RMA said:
If you can remember where that function is , I'd be glad to know it - I couldn't find anything. Having said that, it's pretty easy by brute force. If Kea's still having problems I can post my code next week.
RMA - would you mind posting some of your sample conversion code where you change the ASCII to string byte for byte?

There's also a Code Download page at Mr PLC if they don't allow it on this forum. See http://forums.mrplc.com/index.php?act=Downloads
 
Sorry, wasn't able to get online over the weekend, so this is a bit delayed. Here's the source code of the FC I'm using to extract my data from a file I receive from the customer over Ethernet via FTP transfer.

I've added a short description at the start including the exact format of the data I receive from the customer PC.

Hope it helps, if there's anything you don't understand post again. As I said, it's not very elegant, but it works and I think it's fairly understandable!
 
Last edited:

Similar Topics

Hi All, I have application to read data from barcode scanner to S7 PLC through SI ASCII Card (RS232C). I have tried using the standard FB's to...
Replies
4
Views
2,592
Hi to everybody. I need to read the first 12 characters of the message that a barcode reader sends to the ascii card (1734-rs232 ascii) and I...
Replies
8
Views
725
Hi Guys, i am reposting this beacuse I'm still having issues with the "READ" ARL or ARD instructions. I have a pdf of a program that I found on...
Replies
4
Views
1,966
Hello, I am working with a micrologix 1100 allen bradley plc and I need to send and receive ascii code to a sensor device. The syntax for the...
Replies
3
Views
2,302
hi, i try to capture barcode data using UDT with SINT ascii array. i have all the data i need but it in array format, how can i convert to 1...
Replies
5
Views
3,055
Back
Top Bottom