Author |
Topic: Sending printer control codes (Read 347 times) |
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Sending printer control codes
« Thread started on: May 15th, 2015, 10:07pm » |
|
Over at the Official Liberty BASIC Support Group there is a discussion about how to send a special printer escape sequence (specifically, in the OP's case, to open the cash drawer of a Point Of Sale terminal).
This can be achieved using the Windows Escape API function which is designed for the purpose. However that function requires the printer DC, which is not very easily discovered in LB4. Fortunately, using a tiny bit of embedded BBC BASIC code, it is easy to find the printer DC in LBB.
I don't have a suitable printer on which to test the OP's specific requirement, but what I do have is a conventional Windows printer (a Brother laser printer) which will accept PCL5 commands. The program below sends the PCL5 command for 'italic' followed by a short string, using the Escape API. It then, just for demonstration purposes, outputs some conventional text using LPRINT:
Code: lprint chr$(0);
!printerDC = @prthdc%
escSeq$ = chr$(27) + "(s1S This is some italic text"
escLen = len(escSeq$)
inData$ = chr$(escLen) + chr$(escLen / 256) + escSeq$
calldll #gdi32, "Escape", printerDC as ulong, _PASSTHROUGH as long, _
escLen+2 as long, inData$ as ptr, 0 as long, ret as long
lprint "The quick brown fox jumps over the lazy dog."
dump Note the initial LPRINT of a NUL character - chr$(0) - which initialises the printer driver ready to accept the Escape sequence, without actually printing anything.
To prove this really works here is the printout I get. You can see that the 'escape sequence' has resulted in italic text in the printer's default font, whereas the conventionally-output text is displayed in LBB's default font:
Of course I cannot contribute to the discussion at the LB Yahoo group, so perhaps somebody would care to post a link to this thread.
Richard.
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: Sending printer control codes
« Reply #1 on: May 16th, 2015, 06:48am » |
|
... and this should be what the OP needs to open the cash drawer on his till (untested):
Code:SUB OpenDrawer
lprint chr$(0);
!printerDC = @prthdc%
escSeq$ = chr$(27)+chr$(7)+chr$(11)+chr$(55)+chr$(7)
escLen = len(escSeq$)
inData$ = chr$(escLen) + chr$(escLen / 256) + escSeq$
calldll #gdi32, "Escape", printerDC as ulong, _PASSTHROUGH as long, _
escLen+2 as long, inData$ as ptr, 0 as long, ret as long
dump
END SUB This assumes the printer has already been selected.
Richard.
|
|
Logged
|
|
|
|
|