I'm using the lp command to print stuff to a thermal POS printer. All works fine when I'm printing formatted text and doing cuts.. etc. However, when I send the Drawer Kick command ESC p 0 25 250 it kicks the drawer and then I cannot print or kick after that without having to reset the printer.
Has anyone had this problem and do you know the fix?
What I've noted is all the commands that I send to the printer have a start command and an end. For example, to turn bold text on I have
ESC E \x01 and to turn it off I have ESC E \0, \0 being the null character. But the drawer kick command doesn't have the null character at the end, could that be screwing the printer queue for some reason? Maybe printer is expecting an end to the command somehow?
Can anyone help please?
Related
My code is currently printing a barcode and hri text easily, but I want everything to be printed dead centre on the label. Can someone please tell me when I should declare the alignment command? I tried declaring it at the beginning and just before the barcode print command, but the barcode is still printing in the top left corner.
Here is my align command:
def align_esc(self,esc,n):
'''
ESC|a|n
0<=n<=2,48<=n<=50
0,48 = Left; 1,49 = Mid; 2,50 = Right
'''
align = [esc,n]
align_prnt = bytearray(align)
return align
The reason I am not using escpos python library is because I am printing from an Android device.
Edit:
The above function is missing the following character on line 7:
align = [esc,97,n]
In the ESC a command description of EPSON, there are the following notes.
Are these notices on the ESC a command for your printer?
When Standard mode is selected, this command is enabled only when processed at the beginning of the line in Standard mode.
The justification has no effect in Page mode.
This command executes justification in the print area set by GS L and GS W.
This command justifies printing data (such as characters, all graphics, barcodes, and two-dimensional code) and space area set by HT, ESC $, and ESC \.
Settings of this command are effective until ESC # is executed, the printer is reset, or the power is turned off.
Often, the ESC a command is specified not after the beginning of the line but after printing a few characters or spaces.
For example, if you print with plain text instead of a barcode and it is not centered, then ESC a is not specified at the beginning of the line.
Change the ESC a command so that it is specified at the beginning of the line.
However, if the plain text is printed centered, the feature may not work for barcodes.
In that case, contact the printer vendor to determine if barcode alignment is available and how to do so.
Or there is no automatic function, it may be a method to adjust the print position with ESC \ etc.
The print position in the horizontal direction can be specified by either ESC $ or ESC \.
Only the starting point of the calculation is different. ESC $ is the left edge of the paper, and ESC \ is the print position at that time.
You won't need to use GS P.
I am trying to print the report for each iteration. Since each iteration takes a really long time to run, therefore, I use print together with end="\r" to show the current item being processed.
Here's the dummy code:
import time
y = list(range(50))
print("epoch\ttrain loss\ttest loss\ttrain avg\ttest avg\ttime\tutime")
for e in range(10):
for i in range(50):
print("training {}/{} batches".format(i,50), end = '\r')
time.sleep(0.05)
print('{}\t{:2f}\t{:2f}\t{:2f}\t{:2f}\t{:2.1f}\t{:2.1f}'.format(y[0]+e,y[1]+e,y[2]+e,y[3]+e,y[4]+e,y[5]+e,y[6]+e))
Expected Result
This is my expected result, where the progress information is completely erased after each iteration. (I am running it in Jupyter notebook, and it looks fine)
The Result that I am getting
However, when I run it on linux terminal, the progress information is not completely erased, and the result is overlaying on top of the progress.
Why is it so? How to solve it?
\r simply moves the cursor back to the beginning of the current line. Anything printed after the \r is printed "on top of" the content previously there. On a real printer/teletype this would be literally true, with two characters getting printed in the same position ("overstruck"). On a terminal, the new characters replace the old ones (but only in positions that you actually write to).
You can take advantage of this behavior of terminals by printing spaces. You need at least as many spaces as the content you want to erase, but not enough to make the terminal wrap to the next line (this may be impossible if the line was printed all the way to the last character).
In your case, you know that the line won't be more than 22 characters long, so you could use end='\r \r' (go back to the beginning of the line, print 22 blanks, then go back to the beginning of the line again).
\r option will set (move) the cursor to start. It will not clear the text.
You have to make sure your printed data has enough space to overwrite the previous printed data or be of the same length since just moving to the same line would not automatically clear the previous contents.
I have an application that communicates via USB over COM and I usually use Putty to develop. Some of the users will use Teraterm instead and want the user experience to be as similar as possible.
In Putty, I can send a 0x7F which is ASCII "DEL" and when that value is echo'd back from my application, Putty does a backspace+delete (destructive backspace). With Teraterm, Backspace sends 0x08 which is ASCII "BS" (backspace) and, as long as the "Transmit DEL by:" box for Backspace Key is not checked, the key is returned as 0x08 without any delete (non-destructive backspace).
Is there any way to enable configuration of Teraterm to move cursor position back one character and delete that character when it receives the 0x08 command?
This has been a long time with no answer, so hopefully you worked through it. I don't understand if this scripted through the teraterm macro or if you are just manually navigating through teraterm.
But if this is for a script (.ttl) file or just a command within teraterm, and you know what string is being sent that needs this, you can do the following:
wait "[insert string you are looking for here]"
send 8 127
Where 8 means backspace and 127 means delete. Hope that helps. But teraterm will accept multiple ascii codes in one send command. The wait command could also be further rounded out to accept a timer for the wait action before it performs anything. The wait command can also accept up to 10 strings to wait for: https://ttssh2.osdn.jp/manual/en/macro/command/wait.html
You can also find the ASCII code table for teraterm here: https://ttssh2.osdn.jp/manual/en/macro/appendixes/ascii.html
When I try to print some function name in minicom for linux-3.10 kernel and x86 board, I get extra spaces in each lineof minicom. I have switched on the Line Wrap in minicom but same problem exists. This does not happen with ARM board. It gets printed correctly in ARM board.
x86_64_start_kernel()
reset_early_page_tables()
The code is for printing each name on the border. Is there any setting to be done in minicom?
In minicom press Ctrl+A Z. This will show the menu. Then press U ("Add Carriage Ret"), and minicom will add the CR symbol to each LF symbol automatically.
PERMANENT SOLUTION
You can execute minicom -s as root, choose Screen and keyboard, then press T - Add carriage return, and Save setup as dfl to turn this option ON systemwide. Or you can save this configuration in a separate Config-file, and then use as minicom -D /dev/ttyUSB0 /etc/minicom/minirc.myconfig.
I am creating a small console app that needs a progress bar. Something like...
Conversion: 175/348 Seconds |========== | 50%
My question is, how do you erase characters already printed to the console? When I reach the 51st percentage, I have to erase this line from the console and insert a new line. In my current solution, this is what happens...
Conversion: 175/348 Seconds |========== | 50%
Conversion: 179/348 Seconds |========== | 52%
Conversion: 183/348 Seconds |========== | 54%
Conversion: 187/348 Seconds |=========== | 56%
Code I use is...
print "Conversion: $converted_seconds/$total_time Seconds $progress_bar $converted_percentage%\n";
I am doing this in Linux using PHP(only I will use the app - so please excuse the language choice). So, the solution should work on the Linux platform - but if you have a solution that's cross platform, that would be preferable.
I don't think you need to apologize for the language choice. PHP is a great language for console applications.
Try this out:
<?php
for( $i=0;$i<10;$i++){
print "$i \r";
sleep(1);
}
?>
The "\r" will overwrite the line with the new text. To make a new line you can just use "\n", but I'm guessing you already knew that.
Hope this helps! I know this works in Linux, but I don't know if it works in Windows or other operating systems.
To erase a previously printed character you have three options:
echo chr(8) . " "; echoes the back character, and will move the cursor back one place, and the space then overwrites the character. You can use chr(8) multiple times in a row to move back multiple characters.
echo "\r"; will return the cursor to the start of the current line. You can now replace the line with new text.
The third option is to set the line and column of the cursor position using ANSI escape codes, then print the replacement characters. It might not work with all terminals:
function movecursor($line, $column){
echo "\033[{$line};{$column}H";
}
\r did the trick.
For future reference, \b does not work in PHP in Linux. I was curious - so I did a couple of experiments in other languages as well(I did this in Linux - I don't know if the result will be the same in Windows/Mac)..
\b Works in...
Perl
Ruby
Tcl - with code puts -nonewline "Hello\b"
\b Doesn't work in
PHP - the code print "Hello\b"; prints out Hello\b
Python - code print "Hello\b" prints out Hello<new line> . Same result with print "Hello\b",
I'm not sure if it's the same in Linux but in Windows console apps you can print \r and the cursor will return to the first left position of the line allowing you to overwrite all the characters to the right.
You can use \b to move back a single character but since you're going to be updating your progress bar \r would be simpler to use than printing \b x number of times.
This seems to be pretty old topic but I will drop my 5 into.
for ($i; $i<_POSITION_; $i--) {
echo "\010"; //issue backspace
}
Found this on the internet some time ago, unfortunately don't remember where. So all credits goes to original author.
to erase a previously printed character, I print a backspace after it:
print "a"
print "\b"
will print nothing (actually it will print and then a backspace, but you probably won't notice it)