[Solved] Send ESC/PoS To the Printer
Posted
#1
(In Topic #650)
Enthusiast

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
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
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
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)
Posted
Enthusiast

Chr : This function <COLOR color="#BF0000">only</COLOR> deals with ASCII characters (they start with &H20/32)
Print : The expressions are converted to strings by the <COLOR color="#008000">Str$</COLOR> function.
you can either use
or
Code (gambas)
Seems the same ???
https://forum.gambas.o…/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]
Posted
Guru

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
Print "hello"
Print "world"
"hello
world
"
Code
Print "hello";
Print "world";
"helloworld"
The get the same 2 as string assignments could be this…
Code (gambas)
- MyString = "hello" & gb.Lf & "world" & gb.Lf
- ' or..
- MyString = "hello" & "world"
But this will not work..
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)
Posted
Enthusiast

; 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 said
[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
Posted
Enthusiast

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
<IMG src="https://www.algpos.co.uk/webimage/EpsonPrintout.png">
</IMG>
1 guest and 0 members have just viewed this.



