Link to home
Start Free TrialLog in
Avatar of trevorhartman
trevorhartmanFlag for United States of America

asked on

sending files to COM

Hi,

I'm interfacing a thermal printer on COM3 via RS232.  From the command prompt, this is all I need:

copy 0.txt COM3: /b

That obviously copies my file to COM3 in binary mode.  Now, how do I do that in .NET?  (I'm new to serial communications and have no idea how to do it in .net)

Thanks - Trevor
ASKER CERTIFIED SOLUTION
Avatar of smegghead
smegghead
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trevorhartman

ASKER

the printer I'm working with is not a standard printer.. it is meant to be used as a sub assembly in kiosks, and it has its own set of commands... to make it print, i send a file in binary mode that contains a "^p" command. will your class still work in this case?

thanks - Trevor
yes, you can send anything to the printer. I take it you are talking about control-P ?? you can send any ascii character.
I've used this in the past to print to a receipt printer, which meant that I had to send certain escape sequences to switch fonts, and even to guillotine the paper after printing.

I'm sure this class will work for you.
great, thanks a lot for your help
i got the class working, but it ONLY works if i send files to the printer... the test file i have been sending contains this string:

^P|9|1|405796171|YOUR ESTABLISHMENT|YOUR LOCATION|CITY / STATE / ZIP|TEST COUPON| |405796171|04/12/2005|12:02:21|TICKET# X|FIFTY DOLLARS AND NO CENTS| |$50.00|Expires in 7 days|MACHINE# 0|405796171|^


i need to generate the string dynamically, so rather than create the string, write to file, send file, i want to just send the string directly.   I used:

success = RawPrinterHelper.SendStringToPrinter("\\\\planar\\FL", "^P|9|1|405796171|YOUR ESTABLISHMENT|YOUR LOCATION|CITY / STATE / ZIP|TEST COUPON| |405796171|04/12/2005|12:02:21|TICKET# X|FIFTY DOLLARS AND NO CENTS| |$50.00|Expires in 7 days|MACHINE# 0|405796171|^");

but it doesn't work?  any idea why?

thanks - Trevor
maybe you have to pass a form feed ?

What happens if you just send "Hello" ??
doesn't do anything if i just send "Hello"... it has an embedded proprietary printer langauage, and "^p" is the print command, everything after is parameters that populate a ticket template stored in the printer.
note: success returns true every time.. i think the printer is just not intepretting the string that is sent..  everything must be sent binary
ok, what if you send ^pHello ??

This works for me sending directly to a printer.
the printer only accepts strings in a very strict format, it requries that all parameters be present.  so "^pHello" doesnt do anything..  


in the SendStringToPrinter, it is converting the string to ANSI text.  do you know how i could convert it into binary instead?  i think that is the problem.
As far as I'm aware, ANSI is raw format.

You could always try this article.. it uses the same winspool function, but has an alternative way of calling it.

http://www.codeproject.com/useritems/pclprinting.asp

ok, thanks for the additional help on this one