I have A CSV string I need to seperate

JeremyAdair87

Member
Join Date
Jun 2014
Location
By International Airports
Posts
64
I have a long string in one tag Weld,data,Setting1,Setting2,Setting3,Setting4,Accept/reject

I can't use concatenate and length due to some of the data having varying lengths depending on the decimal place of the weld.

I need to take the one long tag and separate it into multiple individual tags based on the comma

ex Weld,data,setting1 where first comma is in a weld tag second is in a data tag and 3rd is in a setting1 tag.

Any guidance?

Control logix/ Logix 5000
 
Not sure exactly what you're after... If it's something in Excel or to program and copy the contents from one tag into other tags.

I found this example for string manipulation:

http://www.feng.pucrs.br/professore...-en-p_Logix5000_Controllers_ASCII_Strings.pdf

If you use the find to look for the comma, you can then keep track of where the commas are and then calculate the offsets to input in the MID function.
This should be easy in ST, but a real pain in Ladder...
 
no,no,

I have a tag inside my plc that is already CSV. I used a gateway to get a serial string into a plc tag.

I need to parse it in logic before I send it off to SQl with transaction manager.

There is no excel involved. I literally have a tag that has multiple data sets crammed together with commas that I need to separate.

I think I can use the 'Find' with a comma and then use 'concat' I was just curious if anyone had 2cents on the matter.

I plan on doing it in ladder and structured text is a redheaded stepchild but may be easier.... you know... that kind of thing.
 
Not sure exactly what you're after... If it's something in Excel or to program and copy the contents from one tag into other tags.

I found this example for string manipulation:

http://www.feng.pucrs.br/professore...-en-p_Logix5000_Controllers_ASCII_Strings.pdf

If you use the find to look for the comma, you can then keep track of where the commas are and then calculate the offsets to input in the MID function.
This should be easy in ST, but a real pain in Ladder...

I think this is essentially what I was thinking of, although I only know the Siemens instruction names.

First you search for the first comma. Then you split the string into two chunks: left of the comma for the first value, right of the comma for the rest of it. Then repeat until no more commas are found.

It's easier if you at least know how many parameters to expect, and only the num of chars is different. If the number of parameters/number of commas is also a variable, then things get a little trickier.
 
FIND will get you the location of the commas (you're "finding" a string that will be just a comma) and then you can use the MID instruction to extract the appropriate number of characters.

This isn't trivial; I just spent a few minutes on it and got halfway, and I like to think of myself as a pretty good programmer.

One hint to get you started: the "position" of a "Found" string starts at 1, not zero. If you get a zero as the result of a FIND instruction, it means there was no comma found between your start position and the end of the string. This will be the case for the last comma you search for.
 
I'm still not great on RS Logix, but if you run find sequentially you should be able to "mid" the strings out. Something like:

Find first comma
"mid" string between 0 and comma location.
Find comma starting from first comma location +1
"mid" the string between previous comma location +1 and new comma location.
Repeat.
 
Around my shop I'm infamous for promoting brute force logic because of ease of troubleshooting.

For a string like this (spaces for clarity only)

12 , 34.56 , 789.10 , 11.12 , 13.14 , 1516 , 17

FIND the "," string starting at 1. Result = 3, Length = (3-1) = 2
FIND the "," string starting at 4. Result = 9, Length = (9-4) = 5
FIND the "," string starting at 10. Result = 16, Length = (16-10) = 6
FIND the "," string starting at 17. Result = 22, Length = (22-17) = 5
FIND the "," string starting at 23. Result = 28, Length = (28-23) = 5
FIND the "," string starting at 29. Result = 33, Length = (33-29) = 4
FIND the "," string starting at 34. Result = 0. Length = (Total String Length -Previous Result = 35 - 33) = 2

After each FIND, you can increment the Index for your result array by one. Be sure to condition any rung that uses an indirect address so you cannot execute the rung if the index value is out of range.

After each FIND, you'll use a MID to extract the appropriate number of characters and put them into a Result_Strings[x] array, then you'll go through that array with STOD or STOR to convert Strings to DINT or REAL results.
 
no,no,

I have a tag inside my plc that is already CSV. I used a gateway to get a serial string into a plc tag.

I need to parse it in logic before I send it off to SQl with transaction manager.

There is no excel involved. I literally have a tag that has multiple data sets crammed together with commas that I need to separate.

I think I can use the 'Find' with a comma and then use 'concat' I was just curious if anyone had 2cents on the matter.

I plan on doing it in ladder and structured text is a redheaded stepchild but may be easier.... you know... that kind of thing.

I would use sql to take care of it.

https://docs.microsoft.com/en-us/sql/t-sql/functions/string-split-transact-sql
 
I have been slowly converting some of my string functions from VB to Structured text. This is perhaps the only reason to use structured text IMO.

Lots of Basic examples for parsing strings on the interweb.
 
if you want to separate the string using ladder logic use the ASCII search function
search for the comma and then remove the value between the commas
other wise separate the string in VB or Excel and write it to multiple tags
 

Similar Topics

I have a device that reports back multiple data points in a string seperated by commas. Is there an easy way to extract each data point to a tag...
Replies
2
Views
2,330
Good morning, I have a Emerson/GE PLC with Cimplicity SCADA. I need to export data of a specific point/object to a CSV file and load the CSV file...
Replies
7
Views
280
I am trying to import addresses and symbols from a PanelBuilder32 application into the RSLogix 5 Address/Symbol database - however each time I...
Replies
5
Views
533
Hello guys, Im using a siemens with WINCC in a computer and need to import to tag´s data fom a specific row in a SCV file, i have a working...
Replies
15
Views
1,682
Hi. About 18 months ago a did a CODESYS project using the CSV Utils from the IIoT libraries. I am trying to reuse what I did and it does not...
Replies
1
Views
382
Back
Top Bottom