How to handle ASCII string with delimiters

Sphinxj

Member
Join Date
Jan 2014
Location
Washington, MO
Posts
24
New here, but have been using the site for a while. I tried searching the site here for the answer I need, but was not able to find it. So here goes.

I am reading in a Dot Peen 2D matrix code via a Cognext 8500 Dataman scanner that lists the part number and the orientation of the code relative to the scanner. I am most interested in the orientation code. Let's assume I am already reading in the code to the PLC. So I have an ASCII string dumping into a register that is not edited yet.

Some background on the orientation code (OC hence forth). The range of the OC is 0-360. The output data will not always be three digits (i.e. 000-360). There may be one digit or up to three digits.

I spoke with Cognex and there is no way to program the scanner to show three digits all the time and suggested I use a delimiter to break up the code and only extract what is between the delimiters. I have been struggling to find a way to pull data from delimited text.

So that is my question, how can I pull this orientation code that is sent via RS-232 to my plc (RSLogix 500) correctly every time?

Thanks in advance for all or any help provided. 🍻
 
Can you post what a typical string would be. Note the position of the information you want and any variability (like length as you mentioned)?
 
The code that I will be seeing is this for now - DOC258214XXA00587190 177

I have the Data Matrix formatting to be - <Full string><SP><Code Orientation>

The problem that I foresee is the last three, in this case 177, may not always be three digits. So if I look for the last three digits, I anticipate to see garbage after the real numbers. Thanks for the quick reply.
 
You will use ASC to search for the space. Use AEX to extract the final character(s) beginning at the point found by the ASC command into a new string. The AEX command will only get the characters belonging to this particular string, not possible characters left by earlier reads. Then use ACI on this extracted string to convert what remains to an Integer.
 
Last edited:
I will try that out in the morning. Thanks a bunch for the help.

Do you think I will see any issue with the garbage at the end of the extracted data? I am assuming I will extract 3 places at all times for the orientation.
 
Do you think I will see any issue with the garbage at the end of the extracted data?
That "garbage" at the end is probably the two end-of-line characters that designate the end of the line of ASCII characters. The AEX NEEDS to see those characters to know where is the END of the current line.

If your string was always the same length, the AEX Index and Number would take care of getting the right characters. But for variable lengths such as your situation, you have to set "Number" equal to the maximum possible number of characters to be extracted. Then if Number > Actual String Length, AEX will return all characters UP TO the end-of-line characters. The end-of-line characters can be 1 or 2 control characters (sometimes selectable in your sending device), usually CR or LF or both.
 
Last edited:
So after fighting with this scanner this morning, I am finally reading in my dot peen code and can see all the data I want to see.

The next issue I am having is the ASC command can't find the comma I am inserting between the full string and orientation.

I also added a period to the end of the orientation. I plan to find the comma, then find the period, then take the difference between the two and set my index of an AEX to where the comma is and take all the digits that add up to the difference of the comma and period... if that makes any sense.

I am looking at the datatables, and I see the scan data, but noting changes when searching for the comma or period.

The ASC is searching a string file (ST75) and then dumping the integer into a integer file (N63).

What do you think I am doing wrong here? This is driving me bonkers.
 
start the search at the end, and shift back unbtil you find the space character, then you just take this number out and convert it.
 
Well here is what I ended up doing for now. I think the first part of my code will be constant. If I end up having another part with a different length of code, I will ID it and have the system choose a different length to start at.

ASCIIstringtointeger.jpg


Here is what I had when I was trying to find the code within the string when it had a comma at the start and a period at the end. Hopefully someone can benefit from my work...

ASCIIstringtointegerwithcommasandperiods.jpg
 

Similar Topics

I am working on a project using AB PLCs and PanelView HMIs. There is a desire to allow control loop setpoints to be provided through the HMI or...
Replies
11
Views
3,684
I've used Banner for RTD's, thermocouples and 4-20's but not for discretes. I called the factory to find out whether either PNP or NPN wiring...
Replies
1
Views
1,471
The hole size to mount a through door handle is 65mm to 70mm. I can not find a punch that will work in Stainless Steel. What are you using to...
Replies
1
Views
1,134
Hi; We have below mentioned softwares for PLCs, PVs drives etc. I want to ask what is the best practice to handle these softwares, should we...
Replies
9
Views
2,969
If you get a cold call to come out and work on a system with ControlLogix and PanelView HMI, how can you determine which major firmware revisions...
Replies
15
Views
3,819
Back
Top Bottom