S7 PLC trying to format date time to ASCII

mspath

Member
Join Date
Mar 2004
Posts
7
Hello:
I have an Siemens S7 PLC appliaction and a module CP340 for seial communication with Hyperterminal.
I've got to format a ASCII string that looks like:
< 03-11-2004 12:33:07 123.45 0.78 >
I've started just by putting a CHAR in a data block and that transmitts fine.
How do I build the above string with real data?
Thanks
 
Hello, mspath;

Siemens support entry #6175489 shows you the principle of converting a Date_and_Time value to ASCII string. Basically you need to take iindividual bytes of the DT variable, change them to CHAR values, and concatenate the string.There is a STL example listed.
Look the entry up on Siemens support webpage.
Hope this helps,
Daniel Chartier
 
I can tell you this: There is no canned function that will make this easy. I always end up writing my own functions.

Just to get you started, I can give you a few hints. I haven’t looked at the example Daniel showed, but I imagine I would do it in a similar way. I’ve found it is useful to use a pointer and index through the data and create the string byte by byte. For instance, let’s say you want to print “TEST 12345”, and the data that you are sending in located in DB200, starting at DBB0. And, let’s assume that the string always starts with “TEST “, followed by a number up to five digits (which is represented in MD50). Here is some code that should work. Just create a DB200 and define an array of 100 characters, and put this code in OB1. Then, force MD50 with any number between 0 and 99999, and you will see that the text will change from “TEST 0” to “TEST 99999”.

Once you understand how this works, you’ll see how you can create any string using dynamic numbers (such as your time stamp). By the away, don’t bother thinking in terms of “strings” in the S7 side for this application. Think in terms of characters instead (the difference will be evident when you start programming this stuff). Also, even though I am not using the Date and Time specifically, this method works with any dynamic data, no matter where it comes from. If you do a search of the recent threads, you will see some other questions regarding the Siemens Date Time format.


//**************************
//Convert the DINT to BCD and
//transfer it to MD100
//**************************
L MD 50
DTB
T MD 100

//**************************
//Open DB200 and initialize
// area pointer 1
//**************************
OPN DB 200
L 0
LAR1

//**************************
//Load "TEST " as static data to the
//first five bytes of DB200.
//**************************
L 'TEST'
T DBD [AR1,P#0.0]
L ' '
T DBB [AR1,P#4.0]
+AR1 P#5.0

//**************************
//Clear the bytes that represent the DINT
//by transferring spaces.
//**************************
L ' '
T DBD [AR1,P#0.0]
L ' '
T DBB [AR1,P#4.0]

//**************************
//Check to see how many digits are
//in the DINT
//**************************
L MD 50
L L#9999
>D
JC m001
L MD 50
L L#999
>D
JC m002
L MD 50
L L#99
>D
JC m003
L MD 50
L L#9
>D
JC m004
JU m005

//**************************
//Take the DINT in BCD form, and isolate the
//first digit by shifting it left 12 bits,
//and then move it to the right 28 bits.
//Add 48 to each digit to convert it to
//ASCII. Repeat this for each digit.
//**************************
m001: L MD 100
SLD 12
SRD 28
+ 48
T DBB [AR1,P#0.0]
+AR1 P#1.0

m002: L MD 100
SLD 16
SRD 28
+ 48
T DBB [AR1,P#0.0]
+AR1 P#1.0

m003: L MD 100
SLD 20
SRD 28
+ 48
T DBB [AR1,P#0.0]
+AR1 P#1.0

m004: L MD 100
SLD 24
SRD 28
+ 48
T DBB [AR1,P#0.0]
+AR1 P#1.0

m005: L MD 100
SLD 28
SRD 28
+ 48
T DBB [AR1,P#0.0]
+AR1 P#1.0
 

Similar Topics

I just bought a new compact logix 5069-L306ER i am trying to set up the IP address thats working fine but for some dang reason i can not disable...
Replies
7
Views
2,038
Hello, this is a brand new task for me. I recently bought a particulate sensor and it communicates with UART protocol or I2C protocol. It came...
Replies
12
Views
2,811
We received a cell that has a MELSEC Mitsubishi FX 2N-80MR PLC installed. We need to access the PLC program for troubleshooting and additional...
Replies
4
Views
1,971
Need You help... Trying to setup an communication between two PLC's [1756 L61 & 1756 L72 ] thru ethernet EN2T. first i added the EN2T module in...
Replies
6
Views
1,928
Trying to upload the PLC program from SLC 5/04 Using RS232 DB9 cable... already tried with Allen Bradley USB 1747-CP3 1756-CP3 cable... still...
Replies
9
Views
2,279
Back
Top Bottom