send binary file to serial port

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 39
Reputation: jonnytabpni is an unknown quantity at this point 
Solved Threads: 0
jonnytabpni jonnytabpni is offline Offline
Light Poster

send binary file to serial port

 
0
  #1
May 17th, 2009
Hey folks,

I have an Epson POS printer which support printing via my COM port using ESC/POS. This all works well in my c# app. I have used Epson's BMP converter tool to convert a bmp file to a binary file which can be sent directly to the printer.

How would I get my c# app to send this binary file straight to COM1?

I am familiar with the basic sp.Write("lalala") and sp.Writeline("lalala") commands.

The binary file is only 4kb in size so do I really need a binarystreamer? Can I not just do something like fopen(logo.dat,br) ??

Your help is appreciated thanks
Last edited by jonnytabpni; May 17th, 2009 at 8:36 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: send binary file to serial port

 
0
  #2
May 18th, 2009
When you scrub off all the fluffy help methods like WriteLn etc, you see that all communications through the comport are actually in byte[] format. Your BMP can be placed into a byte array, and sent to the comport.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 7
Reputation: Mick Curley is an unknown quantity at this point 
Solved Threads: 2
Mick Curley Mick Curley is offline Offline
Newbie Poster

Re: send binary file to serial port

 
0
  #3
May 18th, 2009
Most Epson Printers should have onboard memory.
You should ony have to place your image in this memory and call it from the code. Which printer is it?
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 39
Reputation: jonnytabpni is an unknown quantity at this point 
Solved Threads: 0
jonnytabpni jonnytabpni is offline Offline
Light Poster

Re: send binary file to serial port

 
0
  #4
May 20th, 2009
Hi guys,

No, this printer doesn't have on-board memory. Its the TM-T88ii (One mark below the version which does have memory).

I don't think I can put the BMP into a byte array as this "binary file" is in special Epson ESC/POS code so need to be sent.

Now, could i put the binary file into a byte array?

Cheers
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 39
Reputation: jonnytabpni is an unknown quantity at this point 
Solved Threads: 0
jonnytabpni jonnytabpni is offline Offline
Light Poster

Re: send binary file to serial port

 
0
  #5
May 20th, 2009
this looks like it could do the job for me:
http://kseesharp.blogspot.com/2007/1...yte-array.html

I would have to put the number of byte of the file into the serielpor's Write method though
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 39
Reputation: jonnytabpni is an unknown quantity at this point 
Solved Threads: 0
jonnytabpni jonnytabpni is offline Offline
Light Poster

Re: send binary file to serial port

 
0
  #6
May 20th, 2009
by the way, i think I'm using completly wrong terms when I say "binary file". I think what I'm suppoed to say it "file with ESC/POS codes that outputs a bitmap"
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 7
Reputation: Mick Curley is an unknown quantity at this point 
Solved Threads: 2
Mick Curley Mick Curley is offline Offline
Newbie Poster

Re: send binary file to serial port

 
0
  #7
May 20th, 2009
Maybe you can send the image data to the printer using the above but I don't know if the desired result can be achieved.. i.e positioning of the image etc..
I have never worked with the TM88II just the TM88III upwards.
Is there no option to get rid of the TM88II as its about 7 years old now and replace it with a nice new TM88III that can handle images nicely
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: rodiepa26 is an unknown quantity at this point 
Solved Threads: 0
rodiepa26 rodiepa26 is offline Offline
Newbie Poster
 
0
  #8
Oct 9th, 2009
Please, I need some example about sending a bitmap to a printer without using OPOS. I connect the printer via an USB/Pararel converter and I have to use Generic / Text Only driver because the driver only lets me assign USB, LPT or COM ports.

I think that I can only use ESC/POS commands to send it.

Originally Posted by Mick Curley View Post
Maybe you can send the image data to the printer using the above but I don't know if the desired result can be achieved.. i.e positioning of the image etc..
I have never worked with the TM88II just the TM88III upwards.
Is there no option to get rid of the TM88II as its about 7 years old now and replace it with a nice new TM88III that can handle images nicely
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,211
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 572
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #9
Oct 9th, 2009
You can create a named pipe for LPT1 or which ever port the printer is on and send it data:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Management;
  8. using System.Net;
  9. using System.Reflection;
  10. using System.Runtime.InteropServices;
  11. using System.Windows.Forms;
  12. using Microsoft.SqlServer.Management.Smo;
  13. using Microsoft.SqlServer.Management.Smo.RegisteredServers;
  14. using Microsoft.Win32;
  15. using Microsoft.Win32.SafeHandles;
  16.  
  17.  
  18. [DllImport("kernel32.dll", SetLastError = true)]
  19. public static extern SafeFileHandle CreateNamedPipe(
  20. String pipeName,
  21. uint dwOpenMode,
  22. uint dwPipeMode,
  23. uint nMaxInstances,
  24. uint nOutBufferSize,
  25. uint nInBufferSize,
  26. uint nDefaultTimeOut,
  27. IntPtr lpSecurityAttributes);
  28. /* -------------------------------------------------------------------- */
  29. [DllImport("kernel32.dll", SetLastError = true)]
  30. public static extern int ConnectNamedPipe(
  31. SafeFileHandle hNamedPipe,
  32. IntPtr lpOverlapped);
  33. /* -------------------------------------------------------------------- */
  34. [DllImport("kernel32.dll", SetLastError = true)]
  35. public static extern SafeFileHandle CreateFile(
  36. String pipeName,
  37. uint dwDesiredAccess,
  38. uint dwShareMode,
  39. IntPtr lpSecurityAttributes,
  40. uint dwCreationDisposition,
  41. uint dwFlagsAndAttributes,
  42. IntPtr hTemplate);
  43.  
  44. //Inside a method:
  45. try
  46. {
  47. uint GENERIC_READ = (0x80000000);
  48. uint GENERIC_WRITE = (0x40000000);
  49. uint OPEN_EXISTING = 3;
  50. uint FILE_FLAG_OVERLAPPED = (0x40000000);
  51.  
  52. SafeFileHandle pipeHandle =
  53. CreateFile(
  54. "LPT1",
  55. GENERIC_READ | GENERIC_WRITE,
  56. 0,
  57. IntPtr.Zero,
  58. OPEN_EXISTING,
  59. FILE_FLAG_OVERLAPPED,
  60. IntPtr.Zero);
  61.  
  62. //could not get a handle to the named pipe
  63. if (pipeHandle.IsInvalid)
  64. return;
  65.  
  66. using (FileStream fStream = new FileStream(pipeHandle, FileAccess.Write))
  67. {
  68. char cOp = Convert.ToChar(7);
  69. byte bOp = Convert.ToByte(cOp);
  70. fStream.WriteByte(bOp);
  71. fStream.Flush();
  72. fStream.Close();
  73. }
  74. }
  75. catch { }
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC