I’m doing a Project for a pecan farm here in New Mexico that wants to capture the weight of the bags of pecans as they are processed and save that data to an excel file.
I’m using a Rice Lake 920i HMI scale indicator with a WLAN card and I’m sending the data to the network each time the user presses the “print” button on the indicator. My goal is to transfer this data to Excel, such that each time the user hits “print” a new row is appended to an existing excel file that contains the data.
Currently, when the user presses “print,” the following data shows up in the Advanced Serial Data Logger main window:
Largest Pecan Farm 1 HMI 1, La Scala, NM 88111 Date/Time: 01.24.14:08:14.51 Superbag ID: 12312 Gross Weight: 2103lbs Variety: Wichita Grade: No. 1 Farm: Murano
I would like this data to appear in Excel as follows:
DATE BAG ID WEIGHT VARIETY GRADE FARM 01/24/14 12312 2103 Wichita No. 1 Murano
01/24/14 12313 1994 Wichita No. 1 Murano
01/24/14 12314 2068 Wichita No. 1 Murano
It is assumed that:
You've configured communication parameters (baud rate, number of data bits, flow control etc) in the data logger and can receive any data without communication errors.
The image above shows that the data flow is very simple, but we should extract data variables from a report with multiple rows.
It is clear from the data example above, that the data block starts with "Date/Time:" and ends with "Farm: " with some letters.
We are now ready for configuring of the modules. First, select the "ASCII data query and parser" plug-in (fig.1, pos.1) from a drop-down list. Then, enable a parsing option for data received (fig.1, pos.2) and select the necessary data export plug-ins. The DDE server (fig.2) will help us to check that the data packet is parsed and exported. The "Excel Export Pro" plug-in will write data directly to XLS file without Microsoft Excel installed.
Fig.1.Data parser plug-in.
Fig.2.Data export plug-ins.
Now, please, open the ASCII parser and query configuration window by clicking the "Setup" button near a drop-down box (fig.1, pos.1). The dialog window below will appear on the desktop (fig.3).
Fig.3.The parser configuration window.
The configuration process should be very simple if you have examined your data flow in the data logger window (fig.3). You should type in the same as in the data logger window in fields 1 and 2. Field #1 marks the beginning of the data block and the field #2 marks the end. In this example, our data block contains both markers. Therefore, all fields are not empty. The values to be typed in here are as underlined in red in fig.3 above. Because the end marked is not constant then we'll use a regular expression as a the end marker. The expression "\bFarm: [A-Za-z0-9]+[\x0D\x0A]+" means any string that begins with the "Farm" word and following by any characters from the specified range. The "RE" checkbox near the expression field specifies that this expression is the regular expression (not plain text).
Because the report in this example is rather short, then we should set the "Timeout" value (fig.3 pos.#3) to a corresponding value to prevent losing of a data. The option at pos.4 allows you to use the start marker in the parsing process.
The next tab is a very important part of the parser configuration. The data parser uses this information for data extraction from the data block. In the example, the data block contains 6 data items (look at the data example above) namely: DATE, BAGID, WEIGHT, VARIETY and so on, that should be separated out to different variables. Later, these variables will be used in the data export and will be placed in different columns of our Excel file. The file with all variables you can download here (right-click -› Save As...) and load it on the "Data parsing" page (fig.4 pos.#8).
Fig.4. Parser items.
Any new items may be added by clicking the "Add item" button (fig.4, pos.7). Before adding an item the program will ask you about an item description. You can type any characters here, which will help you to remember a variable's content. For this example all 6 variables with their corresponding descriptions have been added.
Each parser item has a number of properties:
All other items have identical parameters, except a data type and a regular expression.
|DATE||Date\/Time: ([\d\.\:]+)||sequence of any combination of digits, dots and colons|
|BAGID||Superbag ID: (\d+)||any digits|
|VARIETY||Variety: ([^\x0D\x0A]+)||any characters before a line ending characters (\x0D and \x0A mean ASCII codes for CR and LF)|
|WEIGHT||Weight: ([\d\.]+)||any digits (the units will not be included)|
|GRADE||Grade: ([^\x0D\x0A]+)||any characters before a line ending characters|
|FARM||Farm: ([^\x0D\x0A]+)||any characters before a line ending characters|
In the next tab, you can specify basic format options as per (fig.5). In this example one variable has the "datetime" data type. Therefore the first option (fig. 5, pos. #1) allows you to convert the date string to a field with the "datetime" data type. We specified MM"."DD"."YY":"HH":"NN"."SS here, according to the data example above. For a detailed description of formatting characters, please, see the help file.
Fig.5. Date/time foramt.
Therefore the second option (fig. 5, pos. #2) allows you to trim unnecessary spaces from left and right from "string" values.
Click the "OK" button and close the parser configuration window. Then click the "OK" button in the options window.
Now that our parser is ready it is time for testing it. Connect your device and power it on if necessary. Check to see if you are able to receive a data block from the specified port. If the parser had been correctly set up, then you should see all parser items names and their values (fig.6) in the DDE server window below.
Fig.6. Testing parser. DDE server window.
All parser variables are now ready for export to an Excel spreadsheet. You can read about it in the second part.