SpecView: Write Line to file/printer

<< Click to Display Table of Contents >>

Navigation:  Editing a SpecView Project > Button Attributes & Strategy Controller Actions >

SpecView: Write Line to file/printer

Previous pageReturn to chapter overviewNext page

 

This is also known as 'The Line Writer'.

 

This Button/Strategy Controller Action will write a line of text allowing the writing of fixed text and SpecView variables into files.  Files can be appended to or recreated each time.

 

Click the Visual Editor button to edit the line to be printed:

 

LineWriter

 

Either specify a filename to write to in the Filename box or use a SpecView Text variable from the list of currently defined Text variables for the filename.

NOTE: The filename must not contain spaces.

To write to a filename which is specified by the date, see below.

 

On some printers it is possible to print directly to the printer by setting the filename to the name of the printer, for example, 'LPT1:', or for a network printer '\\print server\epson'  a Form Feed can be added to the end of the text using the Control Codes drop down menu, described below.

 

It is also possible to write to a COM port by setting the filename to, for example 'COM2:'.

 

Check the Append box to append to an existing file, or check the Replace box to overwrite or create a new file.

 

The Command box defines the line(s) to be written to the file. Any text can be entered together with variable names, which are added using the Choose button. These will be enclosed in a pair of percent signs, such as: %%varname%% and will be substituted at runtime. These enclosed strings are called Variable Substitutions.

 

The number of decimal places to be used for Numbers (with decimals) is specified in Preferences - Runtime under Line Writer DP. This setting will then apply to all Numbers (with decimals).

 

NOTE: The Line Writer requires that any variables you include in the %% items are on a screen (GDW) that is always open.

Otherwise the name of the variable followed by 'Val not found' will be displayed.

 

If instead of the value of a variable the file contains the error: Val not found then the problem is likely to be that the variable needs to be on an open GDW.

Certainly all SpecView Pre-defined variables or User Variables that are to by written to a file by the Line Writer need to be on an open GDW.

For instrument variables this is also important because the last known value for the variable must be available at the time the Line Writer needs to write the line.  The Line Writer cannot read the value over comms because this may take several seconds (or minutes in cases of timeouts with bad comms). By putting the value on a GDW, SpecView will usually have the value available.

 

The line written always has a <CR> and <LF> automatically added to the end, but these can also be added at any point in the line to generate multiple lines.

 

Use the Control Codes drop down menu to add typical control codes such as <HT> (Horizontal Tab) but for the more obscure codes, type the decimal code into the Special Characters box and click Add Code.  These codes may be required, for example, for printer control or for other non-SpecView software to pick up and process such as Visual Basic programs.

 

See below for a list of ASCII special characters (or search the web for 'ASCII character codes')

 

Dec Code                Dec Code

00 NUL                        16 SLE

01 SOH                        17 CS1

02 STX                        18 DC2

03 ETX                        19 DC3

04 EOT                        20 DC4

05 ENQ                        21 NAK

06 ACK                        22 SYN

07 BEL                        23 ETB

08 BS                        24 CAN

09 HT                        25 EM

10 LF                        26 SIB

11 VT                        27 ESC

12 FF                        28 FS

13 CR                        29 GS

14 SO                        30 RS

15 SI                        31 US

 

 

To specify the Decimal Places written by the Line Writer

The default setting for decimal places for values written to a file using SpecView's Line Writer is specified using Line Writer DP on Preferences - Runtime

 

To set the decimal places for specific values written to a file using SpecView's Line Writer (if the default setting above is not appropriate for a value), then use CVTSETTINGS.INI

 

To write to a filename which is specified by the date

As already stated; the filename used by the Line Writer must not contain spaces, commas or colons.

The filename would contain spaces and commas if the date format was left as: '%A, %B %d, %Y' the date would be, for example: 'Wednesday, 7 January, 2014' and the spaces and commas would cause problems.

Therefore, in order to use the date for the filename, for example:  %%SpecView.Date%%.CSV

to create, say: 14_006.CSV then the date format needs changing to: '%y_%j' from Preferences - Display.

 

To add some text as a prefix or suffix to the filename copy SpecView.Date into a Text User Variable and create another Text User Variable containing the prefix or suffix then use the Strategy Action Parameters: Math Function to add (concatenate) the Text variables together.

 

Making your own 'Log Files'

Making a form of .CSV file is easy with the Line Writer. These three separate Line Writer commands illustrate the concept - note the commas between the %% to cause commas to be output in the file.

 

Call the file, for example LOG.CSV, and append to it each time:

 +LOG.CSV Time,Zone1,Zone2

 +LOG.CSV %%SpecView.Time%%,%%Zone1.PV%%,%%Zone2.PV%%

 +LOG.CSV %%SpecView.Time%%,%%Zone1.PV%%,%%Zone2.PV%%

Provided that the last 2 lines are done independently by the Strategy Controller, the file may look like this:

 Time,Zone1,Zone2

 12:10:34,560.1,580.0

 12:11:34,560.2,579.9

 

 

The above example shows writing a CSV (Comma Separated Values) format file, just like SpecView's Log Reports.

The reason for using the Line Writer instead of Log Reports would be if a line was required to be written to the file only occasionally, for example, when a fault occurred.