Traffic / TrafficReader

Block Name: TrafficReader

Code File Location: VisualSim/actor/lib/io/Traffic_Reader

Block Overview

Description

This block reads a file or URL, one line at a time, and outputs each line as a data structure. The file or URL name is specified in the file Parameter. When the last line of the file is read and produced on the output port, this block produces true on the endOfFile port. If the Repeat parameter is selected the sequence is repeated. This block requires a trigger to read the next line. The 6 Header fields will be added to the fields from the file.

Format

This block accepts a file name as a parameter. There are a number of file path options available for this block.  To see the list, view the section on File Paths in the Reference Guide document here. The file name is a concatenation of any number of individual strings and parameters, separated by "+".  To view the file path in a demo model, click here.

The first row should contain the column names which will become the field names of the data structure. There must be one name for each column and no spaces in the name are allowed.

The second row must contain the type in each column. The following types are accepted: array, boolean, bin, double, hex, integer, long, octal, and string.

There can be as many lines in the file as required. Each column must contain the set type for each column and must contain a value in each column. The columns can be separated either by tabs or commas.

HEX, OCTAL and BINARY will be converted to integer. Hex value can start with '0x' or just contain the HEX value; OCTAL value can start with '0' or just contain the OCTAL value.

For string entries, the Traffic_Reader will add "" around the entry, even if it not included in the text file.

Listen to Block

Listen to Block will list the line number to correspond with the list row number. This can be used to determine which row has a bad setup. It is a good practise to see if the file can be opened correctly using Excel or other spreadsheet editing tools before using the Traffic Reader block.

Refer TrafficReader Demo Model.



Connection

The input port of the Traffic_Reader can be connected to a Single Event or Traffic Generator. Lines are read from the input file when we get a trigger on the input port. So if we want to read the lines continuously, then we need to loop back the output to the input.

The output port of the TrafficReader can be connected to an ExpressionList, Script, Mapper, Node, TextDisplay, DeviceInterface, Hardware Devices etc. We make use of ExpressionList and Script blocks to make an update to the data structure that comes out of the traffic.This can be field update (specify the destination, memory access command, data size etc) or to add additional fields (Task Name, Time Stamps etc).

ParameterExplanation
fileOrURL
View the above section on formats.
The filename can be a parameter to name the output files differently for each simulation run during batch mode operation.
Repeat_File
When this is selected, the file is repeated until the simulation is completed.

PortExplanationType
inputAn input port that triggers the next line in the traffic file to be output
Any type
outputAn output port that sends out the data structure corresponding to the line in the file.
Data Structure
endOfFileAn output port that produces false until the end of file is reached, at which point it produces true. Boolean