[Solved] Send ESC/PoS To the Printer

Post

Posted
Rating:
#1 (In Topic #650)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
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

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)
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
WIKI says:
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

Code (gambas)

  1. Dim sOut as String =Str(&H1B) & Str(40)
  2. Print #1, sOut

or

Code (gambas)

  1. Print #1, &H1B; 40; etc.
or

Code (gambas)

  1. Print #1, Str(&H1B); Str(40); etc.

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]
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
[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

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

Code

  Print "hello";
  Print "world";
Prints…
"helloworld"

The get the same 2 as string assignments could be this…

Code (gambas)

  1. MyString = "hello" & gb.Lf & "world" & gb.Lf
  2. ' or..
  3. MyString = "hello" & "world"
  4.  

But this will not work..

Code (gambas)

  1. Public MyString As String = "hello"; "world"
  2. ' or
  3. Dim Mystring As String
  4. MyString = "hello"; "world"
  5.  

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)
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
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 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
Online now: No Back to the top

Post

Posted
Rating:
#5
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
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

<IMG src="https://www.algpos.co.uk/webimage/EpsonPrintout.png"> </IMG>
Online now: No Back to the top
1 guest and 0 members have just viewed this.