by Jim Chapman (jc@cknet.net)
| Editor's note: Jim describes a method to write directly to the printer port. Jim's technique may not work for Windows NT, which does not allow direct a program direct access to the printer. |
I had the occasion to need to send control codes to a cash drawer from within A5. In the Alpha 4 days we could just put a calculated field that evaluated to a control code on a report. In trying this approach in Alpha 5 I was unable to get it to work, so I decided to write a small utility executable that I could call from within Alpha 5 to do this task.
The first version of this utility had hard coded control codes for the particular process that was needed. My partner that I was working with (Mark B.) happened to comment that it would be nice if the utility had the flexibility to be used when different control codes were needed. What a novel idea, flexibility. With this inspiration, I wrote a small exe (in Turbo Pascal 7.0) that accepts command line parameters that can be called from with Alpha 5 with sys_shell(). I named the file SendStr.exe.
SendStr.exe accepts numerical parameters on the command line. By entering SendStr at a command prompt the program will print to screen a short list of instructions. By supplying a minimum of two appropriate parameters, the program will run without any output to the screen so it should be virtually unnoticeable from within Alpha 5. Be warned however, that if you only supply one parameter, or where the first parameter is something other than 1, 2, 3, or 4, the program will write to the computer screen a copyright message and a short list of instructions.
This utility will allow you to send output to either lpt1, lpt2, com1, or com2, where the output is directed is determined by the first parameter. The first parameter must be a number between 1 & 4 inclusive. 1 represents lpt1, 2 represents lpt2, 3 represents com1 and 4 represents com2. So the command: Sendstr 1 xx (xx representing a second parameter), would send xx to lpt1. Each parameter after that must be the decimal representation of the ascii character you wish to send to the device, usually a printer.
For instance, to send the string 'JIM' to a printer on lpt1, followed by a form feed:
sendstr 1 74 73 77 12
1 denotes output to lpt1, 74, 73, 77 are the decimal codes for J,I,M respectively, and 12 is the ascii code for a form feed. Each parameter needs only to be separated by a space. From within A5, assuming that sendstr.exe is in the root directory of the c: drive, the following should work:
sys_shell("c:sendstr.exe 1 74 73 77 12", 2)
The most common use of this utility would be to send a escape character to a printer followed by printer command characters to control the functions of a printer. This utility should make it easy to send these control characters to printers or other devices from within A5. Feel free to use this as you wish, but as a word of caution, this is just written and lightly tested. I didn't do any bounds checking except for the first parameter, and I haven't checked it with anything except a printer on lpt1.
Download the SendStr.exe utility.
10/12/00
Don't forget, we need your feedback to make this site better!