[Solved] Send ESC/PoS To the Printer

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

[Solved] Send ESC/PoS To the Printer

Post by AndyGable »

Hi Everyone,

Can some one help me please I need some advice

I and trying to store this command

Chr$(&H1B); chr$(40); in a Veriable called PrinterInitialize so I declared the following

Code: Select all

As String = Chr$(&H1B); chr$(40);
when Itried to run it i get a error saying the ; is not valid so I changed it to this

Code: Select all

As String = Chr$(&H1B) & ";" &  chr$(40)& ";"
and that allowed me to run the code but the printer is not seeing the chr$ commands on the print out I am getting


@;!;1;THIS IS A TEST PRINT

This is what I would do in BASIC

Code: Select all

PRINT #1, CHR$(&H1B);"@"; 'Initializes the printer (ESC @)
PRINT #1, CHR$(&H1B);"a";CHR$(1);'Specifies a centered printing position (ESC a)
PRINT #1, CHR$(&H1B);"!";CHR$(0); 'Specifies font A (ESC !)
PRINT #1, "January 14, 2002 15:00"; 
PRINT #1, CHR$(&H1B);"d";CHR$(3); 'Prints and 3 line feeding (ESC d)
PRINT #1, CHR$(&H1B);"a";CHR$(0); 'Selects the left print position (ESC a)
PRINT #1, CHR$(&H1B);"!";CHR$(1); 'Selects font B
PRINT #1, "TM-U210B $20.00";CHR$(&HA);
PRINT #1, "TM-U210D $21.00";CHR$(&HA);
PRINT #1, "PS-170 $17.00";CHR$(&HA);
PRINT #1, CHR$(&HA); 'Line feeding (LF)
PRINT #1, CHR$(&H1B);"!";CHR$(17); 'Selects double-height mode
PRINT #1, "TOTAL $58.00"; CHR$(&HA);
PRINT #1, CHR$(&H1B);"!";CHR$(0); 'Cancels double-height mode
PRINT #1, "------------------------------";CHR$(&HA);
PRINT #1, "PAID $60.00";CHR$(&HA);
PRINT #1, "CHANGE $ 2.00";CHR$(&HA);
PRINT #1, CHR$(&H1D);"V";CHR$(66);CHR$(0); 'Feeds paper & cut
’Drawer Kick (ESC p)
PRINT #1, CHR$(&H1B); CHR$(&H70); CHR$(&H0); CHR$(60); CHR$(120)
Last edited by AndyGable on Friday 30th April 2021 6:26pm, edited 1 time in total.
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: Send ESC/PoS To the Printer

Post by PJBlack »

WIKI says:
Chr : This function only deals with ASCII characters (they start with &H20/32)
Print : The expressions are converted to strings by the Str$ function.

you can either use
Dim sOut as String =Str(&H1B) & Str(40)
Print #1, sOut
or
Print #1, &H1B; 40; etc.

or
Print #1, Str(&H1B); Str(40); etc.
Seems the same ???
https://forum.gambas.one/viewtopic.php?f=4&t=1039

stevedee one of the board members has written and kindly provided a mega great and incredibly helpful program:

my little gambas helper

my recommendation to you would be to install the program and run it first before you start programming (it will also run gambas if you want it to) and if something doesn't work as it should then search for the keywords (in this case Chr, Str and Print) and most of the time an idea will come up

[DeepL is my friend]
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Send ESC/PoS To the Printer

Post by BruceSteers »

[edited]
The ; char is a string separator that terminates a string with no Linefeed but only in a Print command not a string assignment.

Ie.

Code: Select all

  Print "hello"
  Print "world"
Prints this
"hello
world
"

Code: Select all

  Print "hello";
  Print "world";
Prints...
"helloworld"

The get the same 2 as string assignments could be this...
MyString = "hello" & gb.Lf & "world" & gb.Lf
' or..
MyString = "hello" & "world"
But this will not work..
Public MyString As String = "hello"; "world"
' or
Dim Mystring As String
MyString = "hello"; "world"
I think you are misunderstanding it's use , i doubt the printer wants the ; char at all but your second method send the ; char to the printer along with the Chr(n).

so id suggest to loose the ; and just try & ...
Dim InitString as String = Chr$(&H1B) & chr$(40)

Or Pjblacks code looks good just also bare in mind what I have said about the ; char and it's use (also exactly what it is doing in your BASIC code example)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: Send ESC/PoS To the Printer

Post by PJBlack »

in Print the
; means sending continuous the values --> &H1B -> 40
;; means sending a space between the values --> &H1B -> &H20 -> 40
, means sending a tab between the values --> &H1B -> &H09 -> 40

and at last sign it means sending NO line feed
BruceSteers wrote: Friday 30th April 2021 8:40am [edited]
i doubt the printer wants the ;
yes ... the printer wants the bare command bytes ... if he got something else he has to filter out the unwanted signs
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Send ESC/PoS To the Printer

Post by AndyGable »

Thank-you everyone who helped with this

it was my fault I did not program the ESC code correctly (teach me to code at 2am)

Thank-you all again

I have added this image to show you all what your advice has helped me do

Image
Post Reply