Studio5000 Converting ASCII

ChaseV

Member
Join Date
Jan 2021
Location
Minnesota
Posts
25
We are pulling time through Modbus from 3 reg. the data we are getting back to the PLC is 12593 for hours, 13105 for minutes, and 8240 for seconds. Which I belevive is correct but that is in ASCII How can I get that in Decimal? Those 3 values come back as 11:31:0. I have attach what I am looking at thank you.

Time.PNG Time2.PNG Time3.PNG
 
Those 16-bit INTs are already strings.

E.g.

  • the 16-bit INT 13105 decimal
  • => is 0x3331 (hexadecimal)
  • => i.e. two bytes, 0x33 and 0x31
    • 0x33 is the ASCII code for the character '3'
    • 0x31 is the ASCII code for the character '1'
So the least you will need to do is COP those 16-bit INTs to the SINT .DATA of a string.

If you initialize a string tag, hms, with a value of "HH:MM:SS" and a length of 8 (cf. here and here), then
COP Trck1Time[0] hms.data[0] 2
COP Trck1Time[1] hms.data[3] 2
COP Trck1Time[2] hms.data[6] 2
That should

  1. copy the string "11" (Trck1Time[0] = 12593 = 0x3131), overwriting the "HH" in the first two characters of tag hms
  2. copy the string "31" (Trck1Time[1] = 13105 = 0x3331) overwriting the "MM" in the middle two characters of tag hms
  3. copy the string " 0" (Trck1time[2] = 8240 = 0x2030; 0x20 is a space) overwriting the "SS" in the last two characters of tag hms
  4. After those three steps, the value of tag hms should be "11:31: 0"
    1. The value may instead be "11:13:0 " because of byte order, but then the most you would need to do is
      1. Swap hms.DATA[0] and hms.DATA[1]
      2. Swap hms.DATA[3] and hms.DATA[4]
      3. Swap hms.DATA[6] and hms.DATA[7]
      4. Or you could use the SWPB instruction (cf. here) on the Trck1Time INTs before the COPs.
 

Similar Topics

Hey all, I'm pretty new to PLC programming and am on a team doing a PLC5 to Studio5000 conversion. After doing the built in conversion, I've...
Replies
6
Views
2,506
Dear Experts, I need to send Boolean array from PLC (1769-L19ER) to device which recieve only float data. So, How can I convert Bool array to...
Replies
4
Views
2,231
I have an array of 55 REAL values. Is there a way to multiply based on the array location ? I have 55 transfer belts that are equally spaced...
Replies
3
Views
149
Hi Hope you all are doing well. Iam working on a project with some AOI. I also hate no online edits... lol. My problem occurs when I use a UDT...
Replies
2
Views
157
I am not sure if this is possible but if there is a way, you guys would be the ones to know. I am currently working on a project where we are...
Replies
7
Views
215
Back
Top Bottom