Sending+raw+data+to+a+printer

//by Richard Russell, December 2006//

Normally BBC BASIC for Windows outputs to a printer using the Windows printer drivers. This is useful in presenting a uniform interface; you don't have to concern yourself with the particular manufacturer and model of printer. To change the font you can use ***PRINTERFONT** and to output graphics you can use ***HARDCOPY** (or the Windows API) secure in the knowledge that it will keep working even if you change your printer to a different type.

However there may very rarely be a requirement to bypass the printer driver and output raw data directly to the printer. For example it may be a specialised printer with a feature not normally accessible via the drivers. In that case you can use the procedure listed below to achieve it:

code format="bb4w" DEF PROCprintraw(S$) LOCAL P%     DIM P% LOCAL LEN(S$)+2 ?P% = LEN(S$) $(P%+2) = S$     SYS "Escape", @prthdc%, 19, 0, P%, 0 ENDPROC code This routine sends a character string directly to the current printer, bypassing the drivers.

To use the routine you must first output at least one conventional character to the printer, for example a space, to initialise it. For example you might use the code below to send data to a printer which accepts Hewlett Packard PCL5 commands:

code format="bb4w" VDU 2,1,32,3 PROCprintraw(CHR$27+"&l12E"+CHR$27+"(s1p24v0s0b410THello world!")     VDU 2,1,12,3 code This code first sets a top margin then selects a 24-point Times font before printing the string **Hello world!**