Studio 5000 stop reading string on first "$" value

Hello, I am currently setting up a barcode scanner to read different values, I get a string (02.124837$00$$)00$$). I am trying to read only up to the "$" char and remove the rest, getting only the 02.124837 string.

Thanks !
 
If you string length is greater than x, then you could use the FIND instruction to find where the $00 starts, then use the MID instruction to extract the characters you want to keep.
 
it's not the $ character, because $00 is a single character, specifically a null (ASCII code 0). If the string length (.LEN attribute's value) is beyond the first null, you can assign the offset of that first null wrt the first character to the .LEN attribute value, and the string will then have the right length.
 
It looks like there are some parentheses in there too. Setting the LEN value based on the first zero in the DATA array is easy. So is stripping out "extra" characters that are prepended to the data, but it's a bit more involved if the quantity and values of the prepended characters aren't consistent.
 
Code:
XIC control_1.EN    XIO control_1.EN   FSC 83 0 ALL 0=string.DATA[control_1.POS]

FSC 82 0 ALL "0=string.DATA[control_1.POS] OR control_1.POS=string.LEN"

MOV control_1.POS string.LEN

  • The first rung initializes the control_1 structure (clears .EN, .DN, .IN and .FD bits' values, and .POS value, to 0).
  • The second rung finds the first null in the string, or the end of the string
  • The last rung truncates the string to the characters before the null, or the original length of the string.
 
d'Oh! I forgot about the FIND instruction; nice one @GaryS,

If the FIND Result output parameter (ordinal location of first null character*) a positive value (greater than 0), then the length (.LEN) of a string up to the just before the null would be the FIND Result output parameter less 1.

If the FIND Result output parameter is 0, then the string has no null characters and the length (.LEN) need not be changed.
Code:
1) CLR Needle.DATA[0]
2) MOV 1 Needle.LEN

3) FIND Haystack Needle 1 NullOrdinal

4) GRT NullOrdinal   SUB NullOrdinal 1 Haystack.LEN
  1. Put a null as the first character of the STRING Needle
  2. Assign a 1 as the value of the length of Needle
  3. Search STRING Haystack, starting at the first character, for the first substring matching Needle i.e. for a substring of one null character,
    1. if that substring is found, then write its ordinal position (1 through Haystack.LEN) as the value of DINT NullOrdinal
    2. if that substring is not found, then write a 0 as the value of NullOrdinal
  4. If that substring was found, then set the length of STRING Haystack to one less than the ordinal location of where the substring was found.
 

Similar Topics

Hello! Is there a possiblity to bring the PLC from run to stop with software code? In a special situation my machine should go to in stop mode...
7
Replies
4,393
Views
Hello all, I have a hindsight question, as I have a working system, but thought it would be good to ask if anyone has suggestions or criticism. I...
2
Replies
123
Views
8
Replies
366
Views
Our controls group was gifted a panel with a 1769-L30ER processor. We want to use the panel / PLC as a test or play device. Trying to upload the...
7
Replies
382
Views
Hello, I have noticed that in version 35 of Studio there are times that XIC/XIO bits get stuck and will not function properly. After toggling...
14
Replies
423
Views
Top