Hello.
I am having a bit of a problem regarding chr(0)
Basically, I need to send Chr(0) as part of a string to a POS Printer (it resets the font to the standard size, family etc)
However Chr(0) seems to be a black hole.
As soon as it is added to a stringbuilder, anything appended after it disappears.
It I concatenate strings (ugly and inefficient, I know) it also makes and extra string additions disappear!
Can anybody suggest anything?
-
-
You should use a byte buffer instead... Strings are by definition finished after chr(0). Therefore it's just right that .NET ends each string after the first chr(0) is found and ignores all the memory afterwards.
-
D'OH!littleguru said:You should use a byte buffer instead... Strings are by definition finished after chr(0). Therefore it's just right that .NET ends each string after the first chr(0) is found and ignores all the memory afterwards.
So what you are basically saying, is that instead of building a string, I should build an array of bytes, and then send the byte array to the posprinter...
However I *think* that I need to pass a string to the posprinter, so surely if I convert the byte array back into string, it will terminate after the first chr(0).
hmm.
-
Confirmed. It needs to be a string that I pass to the posprinter.jh71283 said:
D'OH!littleguru said:*snip*
So what you are basically saying, is that instead of building a string, I should build an array of bytes, and then send the byte array to the posprinter...
However I *think* that I need to pass a string to the posprinter, so surely if I convert the byte array back into string, it will terminate after the first chr(0).
hmm.
-
What API are you working against? A totally managed API, a COM interface, a P/Invoke signature?jh71283 said:
Confirmed. It needs to be a string that I pass to the posprinter.jh71283 said:*snip*
C-style strings are, by definition, Chr(0)-terminated, so the API presumably doesn't work with those and expect it to work. Maybe it's just a matter of changing the interop signature. -
.Net strings (and StringBuilders), as well as COM string (BSTR), can contain zero characters without problems, as they keep their length separately.
However, if you were to attempt to display this string anywhere using any of the usual methods (nearly all of which use zero-terminated C-style strings internally), the string would appear to be cut off because it doesn't display anything beyond that character. Unfortunately, that also goes for the Visual Studio debugger. The string is there (check String(Builder).Length and you'll see it's the length of the whole thing not just up to the zero character). So while you can't see it, it's still there. I would just try to send that to the device and see if it works. -
Yggdrasil said:
What API are you working against? A totally managed API, a COM interface, a P/Invoke signature?jh71283 said:*snip*
C-style strings are, by definition, Chr(0)-terminated, so the API presumably doesn't work with those and expect it to work. Maybe it's just a matter of changing the interop signature.What API are you working against?
Microsoft POS for .NETI would just try to send that to the device and see if it works.
It just spits out a few blank lines and that's it.
I can't understand why they would choose chr(0) as the code to reset?
This was specified by Espon in the design of esc/pos, not MS, I might add. -
jh71283 said:Yggdrasil said:*snip*
It just spits out a few blank lines and that's it.
I can't understand why they would choose chr(0) as the code to reset?
This was specified by Espon in the design of esc/pos, not MS, I might add.
Or am I interpreting this incorrectly?
Please see attached Page - I want to set all options to OFF, and character Font A.
Seeing as this site is so bloody INFURIATING to use, the image is located at
http://img66.imageshack.us/my.php?image=escfs0.jpg
-
You are sending the full sequence, right? I.e. 0x1B, 0x21, 0x00jh71283 said: -
Have you tried following Microsoft's documentation instead of the printer's ?jh71283 said:
eg [PosPrinterClass]Print Mode - Characteristics that are remembered until explicitly changed.
Name
Data
Remarks
Font font selection
ESC|#fT
Selects a new font for the following data. Values for the character ‘#’ are as follows:
0 = Default font.1 = Select first font from the FontTypefaceList property.2 = Select second font from the FontTypefaceList property.And so on.
I think you'll find that the # (above) will be the the string form of number. ie "0" -> chr(30). Though I expect that below the covers, the class will follow the ESC/POS documentation, as you posted. -
I will try to look at some of this later....jh71283 said:
is this for the TM-T88III / IV printers ? or another model?
I work with the 88III / 88IV all the time.
when I set codes I am using the seperate codes and that works -- the one you are using is a short-hand to toggle several things at one time.
I am still using the ole /COM bits but have been planning to switch.
was it you and I that posted some about this before ?? can't recall it was at least 1-2 months back.
if you want to keep using the zero there may be a way to make it work but it may be that you have to skip string builder or you may have to get it to use ASCII encoding or some other tricks.
I bet by default the internal buffers used by SB use a char 0 terminator to find the end of the valid text.
normaly text strings do not contain values below 32 / space and by default .Net works in UNICODE which is not bytes
but the Epson Codes are Bytes not chars if you get what I mean ?
-
jh71283 said:Yggdrasil said:*snip*
It just spits out a few blank lines and that's it.
I can't understand why they would choose chr(0) as the code to reset?
This was specified by Espon in the design of esc/pos, not MS, I might add.this looks like it works:
StringBuilder Stb = new StringBuilder();
Stb.Append("foo \x1b!\x00 Barf Gog.");
String goog = Stb.ToString();
try appending "\x00" and see how that works.
the above makes a string that does have all of the values.
I am at home so I can't try sending it to the printer right now. -
Hi figuerres.... yeah we discusses PosPrinters a little while back.figuerres said:jh71283 said:*snip*this looks like it works:
StringBuilder Stb = new StringBuilder();
Stb.Append("foo \x1b!\x00 Barf Gog.");
String goog = Stb.ToString();
try appending "\x00" and see how that works.
the above makes a string that does have all of the values.
I am at home so I can't try sending it to the printer right now.
Athough it is not actually an Epson printer, all pos printers support ESC/Pos, although some have better support than others.
The reason I hoped to use the ESC ! method is that some printers do not like it if I send them a sequence of escapes, Such as
[FontA][Color Red][DoubleWidth]Hello blah blah
[DoubleWidth][Color Red] Hello Again
If you know what I mean....
Some printers will accept the first Double for example, and print the first line in Double, but the second [Double] seems to switch it back off!
However, some other printers, will ONLY print the second line in double if it is specified on that line, otherwise they revert to single.
From testing so far, the ESC "!" seems to work, but I Cannot select Font A (and Font B on some printers is MUCH smaller.)
As I said before I wish I could just tell people to buy Epson printers exclusively, at least they stick to the standard!
@RichardRudek
Thanks for the suggestion, but that is the situation I am trying to get out of for the reasons above.
For example If I want Double Width, Font A the Esc ! code is
ESC ! (32)
Whereas otherwise I have to Build it such asESC|0fT & ESC|2C
Which as I said, some printers are happy with, but not all

Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.