Problem:
Enabling a cobol program to recognize a printer plugged into a usb port
Resolution:
The way to print via a USB-port and not the 'normal' LPT1/2 etc is to use the printer_redirection run-time tuneable.
This redirects output on a file defined as ASSIGN TO PRINTER to whatever your default printer is. So, if that is connected via USB it should work.
The printer_redirection tuneable causes ASSIGN TO PRINTER statements to go to the print spooler rather than LPTn. Therefore, provided the printer attached to the USB has been installed properly there should be no problem printing to it.
There is no way to access ports directly in our product because the operating system APIs used for file handling do not handle USB port names.
The printer_redirection mechanism is the only way that accessing a printer connected via USB can be done.
To set the printer_redirection runtime tuneable you need to create a runtime configuration file and hen set the run time tuneable in this file. The default filename is called 'cobopt.cfg' and this is just a standard text file. However, the file can be any name of your choosing (eg; myconfig.cfg). Then, to have the runtime system access the file you need to use the cobconfig_ environment variable (note the underscore _ this is required).
Once you've set the cobconfig_ environment variable and have it pointing to the appropriate directory/filename you then need to insert the following in the configuration file:
set printer_redirection=TRUE
Make sure it is typed as is - it is case sensitive.
I've included the description of the COBCONFIG_ environment variable and then the printer_redirection runtime tuneable from the Net Express manuals.
----------------------------
Run-time Configuration File
You specify the run-time tunables in a run-time configuration file. You can create or edit the run-time configuration file with a text editor. It is an optional file - no error is issued if it does not exist. The filename is specified to Net Express using the environment variable COBCONFIG_ . For example, if you want to use a configuration file called myconf.cfg:
set COBCONFIG_=c:\\mydir\\myconf.cfg
Each run-time tunable appears on a new line. Blank lines are ignored. A comment line starts with a # character; however, as the configuration file is processed at run-time, we advise that you limit the number of comments, in order to keep to a minimum the time taken to process the configuration file.
The maximum number of characters permitted in a comment line is 80, including any new-line or carriage return characters that might be placed at the end of the line by some editors.
Format of a Run-time Tunable
Each run-time tunable is specified on one line in the run-time configuration file. The format is:
set tunable_name=value
where:
tunable_name The name of the run-time tunable.
value The value to be assigned to the run-time tunable.
Note that each space in the definition can be replaced with tabs or more than one space.
-----------------------------------------
The run-time tunable "printer_redirection=true" can be set in a .cfg file which is located by the COBCONFIG_ environment variable.
-----------------------------------------
printer_redirection
Redirects WRITE statements through the Win32 print spooler.
Syntax:
printer_redirection=TRUE
FALSE
Value:
TRUE Redirect WRITE statements to files defined with the ASSIGN TO PRINTER syntax through the Win32 print spooler, rather than sending the output
directly to the printer port.
FALSE Output is sent directly to the printer port.
Default:
FALSE
---------------------------------
As the default is FALSE you'll need to set it to true.
Please read the manual if you require further information regarding how to set or use either the COBCONFIG_ environment variable or the printer_redirection runtime tuneable.
