LB Booster
« Sending printer control codes »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:55am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Sending printer control codes  (Read 347 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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:

User Image

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.
« Last Edit: May 15th, 2015, 10:08pm by Richard Russell » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls