File Parsing example - SuperTrend

Hi All,

One of my coworkers had a SuperTrend file he wanted to re-arrange for better importing into Excel.

The original data looked something like this: (one line per pen in the Supertrend)

1 23/01/2012 13:53:39.783 1.000000
2 23/01/2012 13:53:39.783 2.000000
3 23/01/2012 13:53:39.783 3.000000
4 23/01/2012 13:53:39.783 4.000000
5 23/01/2012 13:53:39.783 5.000000
6 23/01/2012 13:53:39.783 6.000000
7 23/01/2012 13:53:39.783 7.000000
1 23/01/2012 13:53:49.783 1.100000
2 23/01/2012 13:53:49.783 2.200000
3 23/01/2012 13:53:49.783 3.300000
4 23/01/2012 13:53:49.783 4.400000
5 23/01/2012 13:53:49.783 5.500000
6 23/01/2012 13:53:49.783 6.600000
7 23/01/2012 13:53:49.783 7.700000

And he wanted each line to be one point in time w/the pens as columns like this:


I wrote the attached strategy (which I ran on his file on this PC using PAC Sim) – no actual controllers were harmed or used.

I thought this might be a helpful example, especially if you also want to convert a SuperTrend file, but perhaps if you’re interested in doing some other kind of file conversion or string parsing.

-OptoMary (5.66 KB)

Thanks for sharing your work.

It will help me soon.

Hi All,

Here’s another option to consider. The best tool to view your SuperTrend data could very well be the program that created it (PAC Display Runtime). Perhaps you have some data you’d like to look at elsewhere/later, maybe on your laptop on an airplane as you create your slick presentation to the boss using screen shots…

Did you know: to look at a SuperTrend file, you don’t need a strategy or controller? All you need is:[INDENT]a) the original PAC Display project that created the SuperTrend file and
b) PAC Display configurator + runtime
Try these easy steps:[INDENT]1) Copy the SuperTrend from the original PAC Display project into a new one, by selecting the SuperTrend grid, doing a right-click copy then File > New. [Leave the “Control Engines” list empty.] Right-click paste it into the new project – you just need the one window.

  1. [optional] To keep it simple, configure the Trend to: “historical” by double-clicking on the Trend and clicking the ‘Historical’ radio button (top left).

  2. [Note: you have no strategy or controller involved or configured here in your new PAC Display project, just one window w/one historical Supertrend]
    Click: File > Save Project and Load Runtime.

Runtime starts, close empty event log. Click on the little file icon (bottom right of your SuperTrend), browse to that file you want to see, typically named: RD*.T00. File loads so you can see your data.

Ta da! Super-Trendy. :slight_smile:


with softPAC, any idea where the files are read from and written to? i wrote to the file ‘OutputFile.txt’ and closed the com handle to locate it via a search. i thought the path would be relevant to the softPAC.exe file directory, but no luck, then i tried %system%/system32/optocom no luck… searched my local drives (theres a few…) and no luck… started on network drives but no luck either… no errors were encountered when writing the file. any suggestions??

sorry found it. it appears that the old version of pacsim was targeted as the service to run and i think it was messing with a few things. removed the old service (sc delete SoftPAC) and then ran the softPAC monitor and reinstalled the services and BAM! there it was in the SoftPAC directory (just as i suspected…). mystery solved!! WhooHoo!

Oh, and thanks for this very handy piece of code. love it.


This is very close to what I’m looking for, just wondering would it be possible to modify the code so that it would go
IF variable nSerial = 1 it will put it all in one line starting with nSerial and
if nSerial = 2 it will start a new line and put all data in that line for serial 2, each serial number will have it’s own line starting with the serial number.

or it could also work just put the serial number at the start of Data, and once a new serial number is enter it will start a new batch of data. something like that, cause I’m writing a software that will read the text file and create a graph. but I need to have the serial number parse into the txt file.


Just to clarify, you’re talking about parsing a supertrend file, still? Is this serial number you mention a piece of data that’s also logged in that same file, as one of the “pens”?

yes I’m still talking about supertrent, the serial number of the part that’s being process is stored in a Variable “nSerial” the txt would look like this

Serial # 000000

Serial # 22222

like that I can separate it by serial number in my software and also search by serial number.
I just want to parse the variable each time a new part is finish in front of the data.
hope it makes cense

In that case, it sounds like you’d need to add that serial number as one of the pens. Otherwise, I’m not sure how you’d be able to correlate which sets of data go to which serial numbers. Know what I mean?

Ok, if that is possible to add the serial number as one of the pen than that would work, I just use a barcode scanner to scan the work order and it save’s the barcode (serial #) in a variable so you say I can add that as 1 of the pen?
if that works then I will be set.

You cant trend (or super trend) strings.
So, if your barcode is all numbers, then your set, just trend that (and perhaps hide it, since it will be ‘jumping’ all over the place).
Note, you might have to convert string to float in your strategy if the barcode comes in as a string.

If you have alpha’s in your barcode, then it gets a little trickier…
Is there a unique part of the code that is just numeric? If so, you could do a get substring and then convert that to a float then trend that number…

If not, we might have to brain storm up a way to convert each barcode to a unique number…

I guess I was assuming for this part of an earlier post that the serial number was already in the form of an integer:

IF variable nSerial = 1 it will put it all in one line starting with nSerial and
if nSerial = 2

If that nSerial value is going to a pen, then it would be fairly straightforward to modify the above example strategy to move that pen number to the first column (instead of the date/timestamp I had there). Or leave the sample strategy as-is and just sort in the spreadsheet by the column number.

yes it is just a numeric serial number I think 7 to 9 digit serial number, I just want to use the serial number to link the super trend to that part number, I have a start button when ever the operator loads a new part he/she will hit the start button and the windows will popup to enter/scan the serial number, and it will be stored in a variable (nSerial) once that part is done takes about 10min to unload and a new part is loaded and same process is performed again.

so all I need is to have that serial number appear each time it’s scanned so I can use it as the unique ID.

I got it all working I wrote a little program that can read the csv file and convert it to chart, now I just need to know how can I convert a string to a float? my bar codes are all numbers but I store them in a string now I just like to convert them back to a float to save me from changing other things in the program


Check out the commands in the “String” category. There’s one called “[B]Convert String to Float[/B]” (or [B]StringToFloat[/B] in OptoScript) that I’m betting is all you need!

thanks I will try that, I knew it would be something simple.

ok it works good converting to a float or int32, but now I’m limited to the length of the float or int32, sometimes the barcode from the work order is 15 digits long and float does not read it out like that, what I’m wondering is there a way that can remove the first few digits from the string like in visual basic I can do it like this,( “TextBox3.Text = TextBox3.Text.Remove(0, 3) //this will remove the first 3 characters” ) if I can just keep the last 7 digits that all I need.


There’s a “Trim String” command that sounds like what you seek. That’s new-ish command–is the firmware on your PAC relatively new? (You’ll get an error when you try to download the strategy if it’s not new enough…)

The SNAP-PAC-R1 we have is about 2 years old since purchase, do I need to upgrade the firmware first or that one compatible,
I did try the trim command but my experience with it was that it trim it from the back I need the front 00026 trim each barcode has those number in front and those I like to trim. I will play with it again.
I tried to use Int64 which can hold all the digits that I need only problem is it does not appear in the supertrend pen.

Ah! I see. That trim command is for white space, you’ll probably want the “Get Substring” command instead.

FYI, Once you convert your string to a numeric value, those leading zeros won’t matter, but I’m not sure why you had trouble with an Int64 in your supertrend?

In any case, you’ll want to choose the best type for the value you’re using. How big do/could those numbers get? Will you ever have a fractional piece or are they always whole numbers?

these are always whole numbers, a barcode number looks like this 0260178360 but sometimes they will scan 2 work order at once if it’s a small part they can process 2 parts at once, so the number would double, what I thought if I can get rid of the 0260 it would shorten it by 4 digits would give little more flexibility.
as far as Int64, if you think that it should work with supertrend I will try it again,
what my supertrend currently has is 2 int32 pen and when I ad the int64 it shows that the pen is there, but it does not draw a line, and no numbers appear on the comma delimited file. but the int32 work just fine. and if I add a float it will work too, just int64 seems like has a mind of it’s own. int64 would be ideal cause it can handle most bits.

thanks for your help.