Is anyone aware of a library suitable for writing an image in .TMB format?
The .TMB format is suitable for printing logos from a Epson thermal receipt printer.
After about an hour or so of looking at binary data, I came to the following conclusion:
A *.TMB image is really just a serialized ESC/POS command to print a raster image.
Using the following command:
od -t a -v [YOUR_TMB_FILE] | head
we can view the binary data, as ASCII character data, in the beginning of the TMB file.
I had a file that looked something like this:
0000000 gs v 0 nul 5 nul P nul del del del del del del del del
0000020 del del del del del del del del del del del del del del del del
... snipped for brevity ...
According to the ESC/POS Programming Guide, the ASCII command to print a raster image is:
GS V 0
Hmm.. Interesting!
On a whim, I decided to convert 5 and P to their decimal equivalents, which are 53 and 80 respectively, the exact dimensions of my .TMB image (actually, its 80x53)!
Everything fell into place after this. The remainder of a .TMB file is just the binary image data.
Here is a one-off Python script I wrote to test my theory:
1 out = open('test.TMB', 'wb')
2
3 width = 80
4 height = 53
5
6 NUL = chr(0)
7 GS = chr(29)
8 V = chr(118)
9 ZERO = chr(48)
10
11 W = chr(width)
12 H = chr(height)
13
14 out.write(GS)
15 out.write(V)
16 out.write(ZERO)
17 out.write(NUL)
18
19 out.write(H)
20 out.write(NUL)
21 out.write(W)
22 out.write(NUL)
23
24 for y in range(0, height):
25 for x in range(0, width):
26 out.write(chr(127)) # looks like `del` in ASCII mode
27
28 out.close()
Related
I am working in Windows 10 and I have text files resulting from another process that I want to edit using a batch file. I've shortened the example, File-1 (shown below with line numbers) for this post. They are all formatted this way, but much longer and with more sections:
1 Album 1 - 1982,,,
2 ('Song 1'),
3 ('Song 2'),
4 |===================|
5 Album 2 - 1978,,,
6 ('Song 1'),
7 ('Song 2'),
After each line with a string of 3 commas (lines 1 and 5) I want to insert two new lines of text from File-2 before the existing lines in File-1 (lines 2 and 6).
The two lines in File-2 to insert are:
NEW LINE 1
NEW LINE 2
The desired output would then be:
1 Album 1 - 1982,,,
2 NEW LINE 1
3 NEW LINE 2
4 ('Song 1'),
5 ('Song 2'),
6 |===================|
7 Album 2 - 1978,,,
8 NEW LINE 1
9 NEW LINE 2
10 ('Song 1'),
11 ('Song 2'),
The closest I've come so far as an experiment is a batch file (that I found and adapted) that finds the 3 commas and replaces them with 3 dots.
#echo off &setlocal
set "search=,,,"
set "replace=..."
(for /f "delims=" %%i in (a.txt) do (
set "word=%%i"
setlocal enabledelayedexpansion
set "word=!word:%search%=%replace%!"
echo(!word!
endlocal
)
)
Output of the adapted batch file to the screen:
1 Album 1 - 1982...
2 ('Song 1'),
3 ('Song 2'),
4 |===================|
5 Album 2 - 1978...
6 ('Song 1'),
7 ('Song 2'),
I don't need to change the commas to dots (that was just a test to see if I could make the batch file stop and do something at each instance of a unique string).
My dilemma is that I have searched for hours and can't find how to insert File-2 text in the two proper places of File-1. I've found many explanations on how to insert another file's text at one point or at the end of a first file (using the "type" command), but not at more than one specific point found from the search. Also, File-2 text might be more than two lines in the future, so that is why I want to use an external file to hold it.
All I really want to do right now is:
Find a known string (3 commas).
Read boilerplate text from a text file and insert it below the lines with the found strings, into the the file sitting in the batch file memory.
For testing, I am echoing this to the screen, but once I am able to get the right output, I can edit the batch file to redirect output to a file. I know there are easier ways of doing this using python or C, but it seems it should be easy to do this way with a small correction.
UPDATE
I corrected my batch file per #aschipfl, and made new input files for easier debugging.
a.txt:
A LINE 1,,,
A LINE 2
b.txt:
B LINE 1
B LINE 2
I methodically tried three versions of the FIND statement starting with the #aschipfl original but there is no interaction with b.txt.
if not "!word!"=="!word:%search%=!" find /V ",,," < "!infile2!"
if not "!word!"=="!word:%search%=!" < "!infile2!" find /V ",,,"
if not "!word!"=="!word:%search%=!" find /V ",,," type "!infile2!"
The fourth combination does interact with b.txt as shown below it.
if not "!word!"=="!word:%search%=!" type "!infile2!" find /V ",,,"
C:\Users\Pete\Documents\test>test.bat
A LINE 1,,,
b.txt
B LINE 1
B LINE 2The system cannot find the file specified.
Error occurred while processing: find.
The system cannot find the file specified.
Error occurred while processing: /V.
The system cannot find the file specified.
Error occurred while processing: ,,,.
A LINE 2
C:\Users\Pete\Documents\test>
Now, the batch file reads both lines of both input files but with errors as shown (complete with blank lines, copied directly from screen).
You should not try to replace ,,, by ,,, + line-break + multi-line text from another file, rather should you, after echo(!word!, check whether the current line contains ,,, by if not "!word!"=="!word:,,,=!", and if so, just type out the other text file by type "File-2.txt", or by find /V "" < "File-2.txt" in case its contents may not be terminated with a final line-break:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "infile1=%~dp0File-1.txt"
set "infile2=%~dp0File-2.txt"
set "outfile=con"
set "search=,,,"
> "%outfile%" (
rem // The strange unquoted option string syntax disables the `eol` character:
for /F usebackq^ delims^=^ eol^= %%i in ("%infile1%") do (
set "word=%%i"
setlocal EnableDelayedExpansion
echo(!word!
rem // Try to remove search string; if result differs, search string occurred:
if not "!word!"=="!word:%search%=!" find /V "" < "!infile2!"
endlocal
)
)
endlocal
exit /B
One way to do this in a cmd batch-file would be to use PowerShell. If you are on a supported Windows platform, PowerShell is available. This uses a regex to insert the content of another file.
powershell -NoLogo -NoProfile -Command ^
(Get-Content -Path .\afile1.txt) -replace ',,,', ^
\",,,$([Environment]::NewLine)$(Get-Content -Raw -Path .\afile2.txt)\"
Example:
C:>type afile1.txt
1 Album 1 - 1982,,,
2 ('Song 1'),
3 ('Song 2'),
4 |===================|
5 Album 2 - 1978,,,
6 ('Song 1'),
7 ('Song 2'),
C:>type afile2.txt
NEW LINE 1
NEW LINE 2
C:>powershell -NoLogo -NoProfile -Command ^
More? (Get-Content -Path .\afile1.txt) -replace ',,,', ^
More? \",,,$([Environment]::NewLine)$(Get-Content -Raw -Path .\afile2.txt)\"
1 Album 1 - 1982,,,
NEW LINE 1
NEW LINE 2
2 ('Song 1'),
3 ('Song 2'),
4 |===================|
5 Album 2 - 1978,,,
NEW LINE 1
NEW LINE 2
6 ('Song 1'),
7 ('Song 2'),
How do I get Windows 10 to get CodePages to correctly display?
STOP PRESS
More investigation (creating echo of x80-ff) shows Windows is fine, it's a GAWK print (or terminal/driver) issue
As shown in following screenshot of GAWK then ECHO of CP737 ...
There are some non-ASCII and non-English characters that I want that are available in different Windows Codepages, but they don't display properly in Windows 10 CMD windows (Microsoft Windows [Version 10.0.17134.590]). The font used is Courier New (16pt). NB Code used is faulty but PoC is correct
The displayed blocks 80-FF almost (but not quite) duplicate CP1252 except from CP737 which is surprising bare, and shows the substitution char '?' for most positions.
What magic do I invoke to make the code pages more closely resemble what they should be? For reference I've been looking at Code page 437 and similar.
The code to generate the character blocks is from gawk:
# gawk -f HiAscii.awk
BEGIN {
#SEP = "><" # insert " SEP " into strings
print " <0123456789ABCEF>" #yeah, D is missing, but principle okay
for(hi = 0x80; hi < 0x100; hi += 0x10){
line = sprintf("%X <", hi)
for(lo = 0x01; lo < 0x10; ++lo){ #yeah, these limits are wrong but screenshots already done
line = line sprintf("%c%s", hi + lo, "")
}
print line
}
print " <0123456789ABCEF>" # yeah D missing
print
exit
}
and the batch file to run is
#ver
#echo "437 = DOS Latin US"
#chcp 437
#gawk -f HiAscii.awk
#echo "737 = DOS Greek"
#chcp 737
#gawk -f HiAscii.awk
#echo "850 = DOS Latin 1"
#chcp 850
#gawk -f HiAscii.awk
#echo "860 = DOS Portugese"
#chcp 860
#gawk -f HiAscii.awk
#echo "869 = DOS Greek2"
#chcp 869
#gawk -f HiAscii.awk
#echo "1252 = Super ISO8859-1"
#chcp 1252
#gawk -f HiAscii.awk
I have three files in a directory
File 1:
a b
c d
File 2:
1 2
3 4
File 3:
e f
g h
I know that in windows command prompt, when I type "copy * new.txt", I get a file called new.txt which looks like the following.
a b
c d
1 2
3 4
e f
g h
In command prompt, how would I combine the files horizontally, so I get the following for my combined file?
a b 1 2 e f
c d 3 4 g h
You can install some proper (Unix/Linux) tools from here and do it like this:
paste -d" " file1 file2 file3
a b 1 2 e f
c d 3 4 g h
#echo off
setlocal EnableDelayedExpansion
3< File2.txt 4< File3.txt (
for /F "delims=" %%a in (File1.txt) do (
set "line1=%%a"
set /P "line2=" <&3
set /P "line3=" <&4
echo !line1! !line2! !line3!
)
)
Further details at this site.
You should use the batch-file tag for any "command prompt" related question.
You should upvote and select answers that had been useful to you, otherwise the people may refuse to answer your future questions.
I am writing a windows script to read in a txt file with 9 columns of data
I want to write this data out to a csv file to be loaded into a database.
I have found that one column is sometimes blank, so I would like to enter code 'rdp'
another column has mostly numbers, but for reason some values are a '.' (presumably indicating value less than 1. I would like to change these values to '0'
my code
for /F %%b in (c:\ts_users\newfiles_list.txt) do (
for /F "tokens=1,2,3,4,5,6,7,8,9" %%i in (%%b) do (
echo %%i,%%j,%%k,%%l,%%m,!idle!,%%o %%p,%%q >>%%~nb.csv
)
)
this manages to read in the txt file, then write it out as a csv.
column k is sometimes empty, column n sometimes has a '.'
I have tried variations of
set var=rdp
if %%k="" then set !k:=!var!
which doesnt work, so I a little stumped (after googling internet for days)
current input
201401241611 USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME eu1ptsw002
201401241611 julie.noble rdp-tcp#9 3 Active 18 24/01/2014 14:24 eu1ptsw002
201401241611 svc.perfmon18 7 Disc 3 24/01/2014 14:15 eu1ptsw002
201401241611 reto.hofstetter 10 Disc 40 24/01/2014 10:57 eu1ptsw002
201401241611 lester.valentin 14 Disc 1:16 24/01/2014 11:53 eu1ptsw002
201401241611 philippe.bachmann 15 Disc 2 24/01/2014 12:45 eu1ptsw002
201401241611 patrik.soderlund rdp-tcp#2 21 Active 24 24/01/2014 07:42 eu1ptsw002
current output
201401241611,USERNAME,SESSIONNAME,ID,STATE,,TIME LOGON,TIME
201401241611,julie.noble,rdp-tcp#9,3,Active,,24/01/2014 14:24,eu1ptsw002
201401241611,svc.perfmon18,7,Disc,3,,14:15 eu1ptsw002,
201401241611,reto.hofstetter,10,Disc,40,,10:57 eu1ptsw002,
201401241611,lester.valentin,14,Disc,1:16,,11:53 eu1ptsw002,
201401241611,philippe.bachmann,15,Disc,2,,12:45 eu1ptsw002,
201401241611,patrik.soderlund,rdp-tcp#2,21,Active,,24/01/2014 07:42,eu1ptsw002
required output
201401241611,USERNAME,SESSIONNAME,ID,STATE,,TIME LOGON,TIME
201401241611,julie.noble,rdp-tcp#9,3,Active,18,24/01/2014 14:24,eu1ptsw002
201401241611,svc.perfmon18,rdp,7,Disc,3,24/01/2014 14:15,eu1ptsw002
201401241611,reto.hofstetter,rdp,10,Disc,40,24/01/2014 10:57,eu1ptsw002,
201401241611,lester.valentin,rdp,14,Disc,1:16,24/01/2014 11:53,eu1ptsw002
201401241611,philippe.bachmann,rdp,15,Disc,2,24/01/2014 12:45,eu1ptsw002
201401241611,patrik.soderlund,rdp-tcp#2,21,Active,24,24/01/2014 07:42,eu1ptsw002
#echo off &setlocal disableDelayedExpansion
for /f "delims=" %%a in (file) do (
set "line=%%~a"
setlocal enabledelayedexpansion
set "line=!line:,.,=,0,!"
set "line=!line:,,=,rdp,!"
echo(!line!
endlocal
)
maybe someone can help me...
I have a list (containing also cyrillic letters) like this (channels.txt):
#EXTINF:-1,5 канал Россия
http://95.189.57.162:1234/udp/233.7.70.6:5000
#EXTINF:-0,ТВ3
http://95.189.57.161:1234/udp/233.7.70.7:5000
#EXTINF:-1,ТНТ
rtmp://95.189.54.166:1234/udp/233.7.70.8:5000
#EXTINF:-2,Disney Channel
mms://95.189.52.146:1234/udp/233.7.70.9:5000
#EXTINF:-1,49 Канал
http://95.189.51.163:1234/udp/233.7.70.11:5000
The line begining with #EXTINF: gives the name of a TV channel. Channels are:
5 канал Россия
ТВ3
ТНТ
Disney Channel
49 Канал
The next line is the link to that channel.
Which command or batch script could create a txt file for each channel of the list and put inside the corresponding link? For this example:
5 канал Россия.txt --> http://95.189.57.162:1234/udp/233.7.70.6:5000
ТВ3.txt --> http://95.189.57.161:1234/udp/233.7.70.7:5000
ТНТ.txt --> rtmp://95.189.54.166:1234/udp/233.7.70.8:5000
Disney Channel.txt --> mms://95.189.52.146:1234/udp/233.7.70.9:5000
49 Канал.txt --> http://95.189.51.163:1234/udp/233.7.70.11:5000
I would really appreciate any help!
Many thanks!
try this:
#ECHO OFF &SETLOCAL ENABLEDELAYEDEXPANSION
FOR /f "tokens=2 delims=:" %%a IN ('chcp') DO SET /a CurrentCodePage=%%a 2>nul
CHCP 1251 >nul
FOR /f "tokens=1*delims=," %%a IN ('type file.txt') DO (
SET "link=%%a"
SET "channel=%%b"
IF DEFINED channel (SET "fname=!channel!"
) ELSE (ECHO !link!)>"!fname!.txt"
)
CHCP %currentCodePage% >nul
dir output is with code page 850:
06/29/2013 08:38 AM 48 49 ?????.txt
06/29/2013 08:38 AM 47 5 ????? ??????.txt
06/29/2013 08:38 AM 46 Disney Channel.txt
06/29/2013 08:38 AM 47 ??3.txt
06/29/2013 08:38 AM 47 ???.txt
dir output is with code page 1251:
06/29/2013 08:38 AM 48 49 Канал.txt
06/29/2013 08:38 AM 47 5 канал Россия.txt
06/29/2013 08:38 AM 46 Disney Channel.txt
06/29/2013 08:38 AM 47 ТВ3.txt
06/29/2013 08:38 AM 47 ТНТ.txt
For more information about cmd and code pages click here.