Using 'MID' Instruction With Custom String Type

tbreww96

Member
Join Date
Aug 2018
Location
Ohio
Posts
6
So, I am a beginner-slightly intermediate level programmer, and I am looking for a way to access specific data, and pull it out of a larger string. Not hard right, just use the MID command to pull it out!

Wellll, the string that I am attempting to pull data out of is a custom string data type, with a possible length of up to 4096.

The MID command will not work with any string larger than 82 characters. :angr:
I have to find a way to pull this data out; whether it be by splitting the custom data type up into regular 82-character strings, or using an instruction that will work with strings larger than 82 characters. Help! & thanks in advance!
 
To start, three questions:

  1. What PLC part number?
  2. What PLC Firmware version?
  3. What programming software version?
The more exact your answers, the more exact our answers can be.


Also, what do you mean by a "custom string data type"? Are you using an array of characters instead of a string?
 
To start, three questions:

  1. What PLC part number?
  2. What PLC Firmware version?
  3. What programming software version?
The more exact your answers, the more exact our answers can be.


Also, what do you mean by a "custom string data type"? Are you using an array of characters instead of a string?
@mk42

1) PLC is AB 1769-L36ERMS. I am using this PLC for bench testing.
The application PLC will be a 1769-L30ER

2) Vs 30.012

3) RSLogix 5000 Vs 30.00.00

Technically in this version of Logix, all strings are an array of characters or SINT's (in the ASCII style) with the length in an attribute called 'LEN' of DINT type. The only difference is, in a regular string, there can only be 82 characters, and the array of SINT's is always a SINT[82].

In this string type, the array is a SINT[4096].

I've attached an image that maybe helps show this:
Capture.png
 
That's one heck of a string! So, in practice, is there any real chance that the content of the string will really be that long? If not, perhaps you can look at its LEN value and if that is less than or equal to 82, copy the customer STRING to your own internal STRING with an SINT[82] size and work with that.

Just a thought
 
That's one heck of a string! So, in practice, is there any real chance that the content of the string will really be that long? If not, perhaps you can look at its LEN value and if that is less than or equal to 82, copy the customer STRING to your own internal STRING with an SINT[82] size and work with that.

Just a thought
I did think about that. Unfortunately, the strings I am dealing with are consistently 300-500 characters.
 
You could roll your own fairly easily.

COP INPUT.DATA[START_INDEX] OUTPUT.DATA[0] NUMBER_OF_CHARS
MOV NUMBER_OF_CHARS OUTPUT.LEN

I would have to read the MID instruction's manual to find out what you want to do when you mess up the array index. Eg.
if start_index >= input.len
if start_index >= LEN(input.data)
 
You could roll your own fairly easily.

COP INPUT.DATA[START_INDEX] OUTPUT.DATA[0] NUMBER_OF_CHARS
MOV NUMBER_OF_CHARS OUTPUT.LEN

I would have to read the MID instruction's manual to find out what you want to do when you mess up the array index. Eg.
if start_index >= input.len
if start_index >= LEN(input.data)
I thought the same! I tried it, and it still seems to be unhappy! I'm stumped!
Capture1.png
 
The MID command will not work with any string larger than 82 characters.

In Logix Rev 18, at least, the MID instruction is not limited to the default 80-character string type. So long as your string can fit into a user-defined string type of the desired length, MID will work over the whole length. I just tested with a 200-character string, finding a 3-character substring at position 151 to 153.

Also, I created a 4096-character string to make sure that was not a limit.
 
In Logix Rev 18, at least, the MID instruction is not limited to the default 80-character string type. So long as your string can fit into a user-defined string type of the desired length, MID will work over the whole length. I just tested with a 200-character string, finding a 3-character substring at position 151 to 153.

Also, I created a 4096-character string to make sure that was not a limit.
That's extremely interesting. I will keep trying; maybe there is something else going on here.
 
@mk42

1) PLC is AB 1769-L36ERMS. I am using this PLC for bench testing.
The application PLC will be a 1769-L30ER

2) Vs 30.012

3) RSLogix 5000 Vs 30.00.00

Technically in this version of Logix, all strings are an array of characters or SINT's (in the ASCII style) with the length in an attribute called 'LEN' of DINT type. The only difference is, in a regular string, there can only be 82 characters, and the array of SINT's is always a SINT[82].

In this string type, the array is a SINT[4096].

I've attached an image that maybe helps show this:
Capture.png

Thanks for circling back with those answers! The logix experts are already on the case, so I'm going to let them do their thing.

That said, your response is way more detailed than most new posters on this forum, so props to you, best of luck, and welcome aboard!
 

Similar Topics

Hi We have a PC application that uses Pyramid driver to connect to Controllogix PLC using EthernetIP. It uses Class 1 communication for the...
Replies
2
Views
5,938
Hi, I'm trying to use the IO Device Library (Product Versions) which is configured to work with the 1756-EN4TR & 1756-EN2TR but my system uses...
Replies
0
Views
43
Hello, As part of our project, we are using an M241 controller. This controller interfaces with an industrial computer and a router via a switch...
Replies
2
Views
78
I'm trying to write a data in Arduino using MODWR function block .I used the code I got from online for both PLC and Arduino. I made the wiring...
Replies
4
Views
87
Hey all, i have a panelview screen (image attached), with 4 items on it. Program 1, Program 2, ...3, ...4. The PLC i am using is a compactlogix...
Replies
5
Views
158
Back
Top Bottom