Serial port data and Excel. Real time charting
I want to connect an RS-2322 port to MS Excel. The port will provide a stream of ASCII numeric characters to Excel. I want Excel to automatically receive and graph the ASCII data, sort of like an oscilloscope. I can control the format of the incoming ASCII data.
Fig.1. Serial port data and Excel. Data captured
- Advanced Serial Data Logger (ASDL) Professional or a trial version;
- ASCII data parser and query plug-in for the data logger;
- DDE server plug-in for Advanced Serial
Data Logger (optional);
- Direct Excel Connection plug-in for the data logger software.
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.
You can work in Microsoft Excel, specifically create charts in an Excel file.
The image above shows that the data flow is very simple, but we should extract data variables from a report with multiple rows. At the same time the figure doesn't contain non-printable characters and doesn't show ending characters of a data packet. We need to recognize ending characters of an each data record. Please, enable display output for non-printable characters with a character code below than 0x20h. You need to create a port configuration. Please, click the "Plus" button in the main window if you didn't make it before and set the following options.
Fig.2. Serial port data and Excel. Serial data view setup
Then click the "OK" button and try to receive the data from a port. You should receive the data like on the figure below.
Fig.3. Serial port data and Excel. Data received.
This is the other view of the data received. Notice that all non-printable characters were replaced with their code i.e. #0D. It is clear from the data screen above, that the data block (within the green rectangle) starts with TLFLOW and ends with three pairs of CR+LF characters (#0D#0A#0D#0A#0D#0A) (underlined by red).
We are now ready for configuring of the modules. First, select the "ASCII data query and parser" plug-in (fig.4a, pos.1) from a drop-down list. Then, enable a parsing option for data received (fig.4a, pos.2) and select the necessary data export plug-ins. The DDE server (fig.4b, pos.3) will help us to check that the data packet is parsed and exported. The "Direct Excel Connection" plug-in
will write data directly to a Microsoft Excel spreadsheet.
Fig.4a. Serial port data and Excel. Data parser plug-in.
Fig.4b. Serial port data and Excel. 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.4a, pos.1). The dialog window below will appear on the desktop (fig.5).
Fig.5. Serial port data and Excel. 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 report in this example is very long, then we should increase the "Timeout" value (fig.5 pos.#3) 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 28 data items (see fig.1) namely: DDATE, DTIME, TLFLOW, TLVOLM and so on, which 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 and load it on the "Data parsing" page (fig.6 pos.#8).
Fig.6. Serial port data and Excel. Parser items.
Any new items may be added by clicking the "Add item" button (fig.6, 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 28 variables with their corresponding descriptions have been added.
Each parser item has a number of properties:
- Item name - this name will be bound to a column in the data export plug-in. It is a limited text description and cannot contain spaces and a few other characters;
- Parser's type - is a method, which the program will use for data extraction. Our parser has a few methods from simple to most powerful. In this example, where data items are placed in a variable place, we should use the most powerful method - regular expression. This method allows you to extract a data from any position of the report by mask. This mask can be widely transformed and adapted to characters in the report;
- Data type - is the data type of the characters extracted. For example, you can specify FLOAT, DATE, TIME or STRING data types. The data will be converted to the conversion type later, in the data export module. The data type here is being used for formatting of the value, which will be specified on the "Data formats" tab later. In the example, we'll use the FLOAT data type for all number, the DATE type for date and the TIME type for time values;
- Default value - the value specified here is to be used when data cannot be extracted from a data block. In this example, some numbers may not exist in the reports, therefore we should define a default value for all variables;
- Regular expression - in this example we need numbers or strings, which follow by dot or the ":" character in several places of the report. For example, a regular expression will as following: TLVOLM: ([\-\d\.]+). Here, the expression in parenthesis is our number, which we should extract to a variable. Please, search in Google for a detailed description of regular expressions;
- Entrance position - all our values are present in the report once only, therefore an entrance position for each variable is 1.
All other items have identical parameters, except a data type and a regular expression.
In the next tab, you can specify basic format options as per (fig.7). In this example two variables have "date" and "time" data types. Therefore the first option allows you to convert the date string to a field with the "date" data type. We specified MM"."DD"."YY and HH"."NN"."SS here, according to the specification above. For a detailed description of formatting characters, please, see the help file. The second option allows you to convert the time string to a field with the "time" data type.
Fig.7. Serial port data and Excel. Format of items.
Other options are unnecessary in our case, because all our items do not have the "datetime" or "string" data type.
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.8) in the DDE server window below.
Fig.8. Serial port data and Excel. DDE server window.
All parser variables are now ready for export to an Excel spreadsheet. You can read about it in the second part.
To export data to the necessary format, please, click on the corresponding link below:
- Parsing data from barcode scanner and writing to a log file with a date/time stamp (data at fixed positions, no data packet signatures);
- Processing data from barcode scanner (data at fixed positions, data packets with the end signature);
- Parsing data with help of regular expressions (complex data format, regular expressions, data filter);
- Receiving and parsing data from aircraft engine monitor (usage example, custom data parser);
- Processing data from the lab equipment (simple data format, regular expressions);
- Receiving and parsing data from Garmin Geko301 GPS receiver (simple data format, data at fixed positions, data packets with both signatures);
- Parsing data from the filling machine (simple data format, delimited data, data packets with the end signature, data filter);
- Parsing and processing data from PBX (simple data format, data at fixed positions, data packets with the end signature, data filter);
- Logging and parsing data from an intellectual pressure measuring device (sending requests to the device, simple data format, data at fixed positions, data packets with the end signature, data filter);
- Serial data acquisition in the Checkweigher Management Information System (complex data format, regular expressions, filtering data);
- Serial port data aggregation. Combine a data of two different com-ports (simple data format, data at fixed positions, data packets with the end signature, data filter);
- Weight data logger. Parsing weight data from scales (simple data format, data at fixed positions, data packets with the end signature, data filter).
- Send data to a port from a file (data requests, send data by a schedule).