Data to string

garlantm

Member
Join Date
Aug 2016
Location
Michigan
Posts
28
Hello, I am just wondering if you have any ideas to help me with this. I am currently working on a barcode scanner reading via serial.

This is Logix Designer 30.11

I need to search the sint and start after the first R and then end with the little r. The sample serial that I sent was 123456 which can be seen below. Basically I want to copy only 123456 and put it onto my hmi. but they will not always be 6 characters so I do not know how to copy variable sizes and not have the "r" show up with a bunch of zero's behind it.

Thank you,

serial slave.JPG
 
The ASCII Instruction Find will do that. In your example the Find Instruction would report "R" in position 4. That would be first SINT of you number. Since the Data starts at 0 then we find "R" in .data[3] or the 4th position. So your first number is in .data[4] The "r" is in the 11th position. So 11-1 =10 and 10 - 4 = 6 that's the size of your number. You will have to subtract 1 from "r" position to get last number position. Again, because the .data[0]
 
Last edited:
Here is the Logic: You don't need to subtract for the second position. The STOD only changes the digits. If you need your number to be a string then add the DTOS to this Rung to change it back.

Capture.jpg
 
Here is the Logic: You don't need to subtract for the second position. The STOD only changes the digits. If you need your number to be a string then add the DTOS to this Rung to change it back.

Can FIND use a variable/Tag for the start position, or must it be a constant? If it doesn't have to be a constant, it would probably be good to have the start position of the "r" search be the position of the "R". That way it doesn't fail if the string has an "r" before the "R" for some reason.
 
Yes it can. It can be a SINT, INT or DINT. I was going by the OP saying his data followed the "R" and ended at "r"
 
Hello,

Thank you for the response but I have a question. What if the bar code were to have a lowercase r in it then wouldn't it end? Also something I just now realized while playing with it is that ci.data[2] is actually the length of the response including both R and r. So what I need to do is take the data and put it in a string skipping the first and last letter. This would be a little easier right?
 
The 'lowercase r' you are referring to is actually a carriage return. Note the $. This means that this is a special control character. Some, like the $00 just show the value of the control character. Others, like this $r attempts to show the function.
 
I think I am getting closer but have run into a different problem.

first is if I copy this into a DINT all I can get is 4 characters back which wont work for a barcode scanner. Second is it is copying it backwards. Any ideas on these two problems?

hello_part3.JPG serial_hello.JPG hello_part2.JPG
 
I think I am getting closer but have run into a different problem.

first is if I copy this into a DINT all I can get is 4 characters back which wont work for a barcode scanner. Second is it is copying it backwards. Any ideas on these two problems?

Try doing a CPS instead of a COP; serial comms are pretty 'slow' especially when running on Logix Rev30.
 
The MID Instruction will allow you to pull data from the string. Just tell it where to start and how many characters. In the example I started at .DATA[1] for a length of 2. If you only use .DATA[2] your max length is 9. This is assuming that your serial number will always start at .DATA[4]. or the 5th position.

Capture.jpg
 
Last edited:

Similar Topics

Hi, I'm new with ST and especially data structures and I am trying to create a data structure to store the following shapes and properties...
Replies
0
Views
592
I am needing to transfer some prod_cons tags where the data type is a string[10]. Can you move a String data type? Thanks in advance RM
Replies
18
Views
3,492
Hey folks! I've gotten an idea in my head and I'm wondering if anyone can help - and my title is terrible because I'm not good at articulating...
Replies
2
Views
1,031
Hi all, I have a customer that is asking for a recipe of 200 recipes to be sorted. I'm trying to do this by way of a bubble sort. Basically my...
Replies
18
Views
3,464
I have a customer that sent me the email below, I have been trying to find an answers in the manuals but cant find much to help He is using a...
Replies
3
Views
4,392
Back
Top Bottom