File Parsing example - SuperTrend

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.

thanks.

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.

I thought I had everything figure out, until I started running the program, I find out that my top row is always modified, somehow it puts the newest line on top, and then all the time and date are in order but the last data received is put in the first row

example
05/20/2014,13:37:27.060,201.539001,204.490540,178373.000000,
05/20/2014,08:12:46.615,151.837128,143.727982,111111.000000,
05/20/2014,08:12:47.617,151.837128,144.026474,111111.000000,
05/20/2014,08:12:48.638,151.837128,144.026474,111111.000000,
05/20/2014,08:12:49.638,152.135620,144.474228,111111.000000,
05/20/2014,08:12:50.639,152.135620,144.499100,111111.000000,
05/20/2014,08:12:51.654,152.309753,144.499100,111111.000000,

for my software to work it should look like this and the top row should always stay

Date,Time,Temp East,Temp West,Work Order
05/20/2014,08:12:46.615,151.837128,143.727982,111111.000000,
05/20/2014,08:12:47.617,151.837128,144.026474,111111.000000,
05/20/2014,08:12:48.638,151.837128,144.026474,111111.000000,
05/20/2014,08:12:49.638,152.135620,144.474228,111111.000000,
05/20/2014,08:12:50.639,152.135620,144.499100,111111.000000,
05/20/2014,08:12:51.654,152.309753,144.499100,111111.000000,
05/20/2014,13:37:27.060,201.539001,204.490540,178373.000000,

is there anyway to change it that the top row will never be modified? or that my top row data will always be rewritten to this [B]Date,Time,Temp East,Temp West,Work Order[/B] cause I use the keywords on top to Filter the data.

thanks.

that file parsing is working now as I needed, and in my PAC SIM it works good, buy when I load it to the controller it can’t open the connection, I believe it’s code -417 that it gives, I have my files on C:\Oven_Data\STRENT.T0004 and output sLog.csv I don’t see and error on the output but the input, I’m wondering is it related to the 8 - 3 file length cause it’s extension is longer then 3 characters. if I is than how can I make Supertrend to save the file to File.T01,
any help would be appreciated.
Time to stop working for this week.

have a good long weekend.

The controller, unlike PAC Sim, is not aware of your C: drive… It can not navigate across your network, make a connection to your PC where the trend file is, and navigate your directory structure to the file.
This is one of the really powerful features of both PAC Sim and SoftPAC, the fact that its running on the PC means it can access the local file system.
Changing the file name wont make the file accessible to the controller. Its the location, not the name that is the problem.
You could try and set up some sort of batch job that FTP’s the file from the PC to the controller, then change the code on the controller to access the file on its local file space, but I suspect that running SoftPAC would be a better solution.

Ok I had not heard of SoftPAC before. thats a sign I’m new at this, the [B]SNAP PAC R1[/B] controller that I build 2 to 3 years ago works good, but the company wants the data logging now, if I can use SoftPAC with my current controller so I can just change over without changing hardware, I will ask for the money and purchase it.
can you tell me if I buy a license, is it only for 1 controller or can I use it on more than 1 controller? currently we have 2 Opto22 controllers running and looking to build some more in the near future.

do I still need PAC Control basic or pro running if I have SnapPAC?

thanks.

I have come in right at the end here, so sorry if I dont get your setup straight up…

SoftPAC lets you run 64 charts on a PC. A pac R1/2 can run 16 charts, an S1/2 can run 32 charts.
The main difference is of course is that your PC does not have any IO, and must be running all the time to ensure your strategy keeps running…

That said, your SoftPAC strategy can have the IO on the rack that your R1 is running, just configure the points and IP address.
In other words, your R1 can keep doing what its doing and the SoftPAC strategy can just take over your PAC Sim strategy.
The main difference between PAC Sim and SoftPAC is that the sim will only run for 12 hours and then stop, where as SoftPAC will run as long as your PC is up. (There are a couple other things, but that’s the big one).

So, do you need to run the logging all the time? Or can you run it as you need it?
If it its only needed now and then, just call up PAC Sim when you need it and do like you have. (For example, start it at the start of each day and it will run for your usual 8-9 hour day and then some?).
If it needs to be parsing the file all the time, then SoftPAC might be the go.

The license is for one instance of SoftPAC, but if you need more, ring presales or your local Opto guy and they can help you out.

Ok that helps thanks for the explanation.

I will try to schedule the SIM to start up for the 3 hours at night when the shop is down see how it works. but I can see that in the future we will be needing SoftPAC if those bigger projects come that have been talk about.

thanks for your help this will help me to finish the project.

OK, I’m must be missing something. I’m using SoftPac, but getting the -417 error when trying to write to anything other than the “root” of my file system. For example:

sOutputFileName = "h:/RD140702.T0003.csv";
sOutputCommHandleValue = "file:w," + sOutputFileName;

Doesn’t work. However, if I leave out the h:/, it does work, but puts the file here:
C:\Windows\SysWOW64

This is a Windows 7 Pro machine. Am I just messing up the syntax somehow?

Do you know the name of your networked drive, with some slashes in the other direction? You’ll want to use that.

For example, around here we found:

Network Drives use the “/” character, like this example:
file:w,//000Eng/Temp/_TestFile_01.txt

Drives that are local to the Windows computer use the “” character, like these examples:
Hard Drives local to my computer:
file:w,C:\Temp_TestFile_01.txt
file:w,F:\Temp_TestFile_01.txt

USB Flash Drive local to my computer:
file:w,G:\Temp_TestFile_01.txt

Here’s how you might be able to find that name using Explorer:


I hope that helps!
-Mary

Thanks! Using your example, specifying a local drive path is working. However, the network drive location is still not recognized even with the syntax suggested. It isn’t a show stopper, just a speed bump.

One more question on this thread… has anybody tried writing a converter that will read the binary format of SuperTrend logs, so that they don’t need to be converted to text first through PAC Display?

It looks like the format is like this:

0x55 {8 bit pen number} {64 bit windows filetime timestamp} {32 bit IEEE 754}

Not sure if the first byte changes, all the ones I looked at started with 0x55.

C# console program to convert Supertrend to CSV.

Usage:
ConvertSuperTrendToCSV.exe < RD160328.T0002 > new.csv

ConvertSuperTrendToCSV.zip (2.29 KB)

using System;
using System.IO;

namespace ConvertSuperTrendToCSV
{
    class Program
    {
        static void Main(string[] args)
        {
            using (Stream stdin = Console.OpenStandardInput())
            {
                int Pen;
                DateTime TimeStamp;
                Single Value;

                Console.WriteLine("Pen,TimeStamp,Value");

                byte[] buffer = new byte[16];
                int bytes;
                while ((bytes = stdin.Read(buffer, 0, buffer.Length)) > 0)
                {
                    Pen = buffer[1];
                    TimeStamp = DateTime.FromFileTimeUtc(BitConverter.ToInt64(buffer, 2));
                    Value = BitConverter.ToSingle(buffer, 10);
                    Console.WriteLine("{0},{1},{2}", Pen, TimeStamp, Value);
                }
            }
        }
    }
}

Reviving an old thread…this is exactly the function I was looking for! Having some issues though: when I hit “Debug” to download the strategy, I get the error “controller out of memory” as per screenshot. Any ideas what could be wrong? Your help is greatly appreciated! (I’m new to PAC).

Running the latest versions of both: PAC Sim R9.5d and PAC Control Basic R9.6d

Error msg

PAC Sim configuration is kept at its automatically populated settings (Standard, 127.0.0.1)