943,769 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 6911
  • C# RSS
May 17th, 2009
0

send binary file to serial port

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
jonnytabpni is offline Offline
39 posts
since May 2009
May 18th, 2009
0

Re: send binary file to serial port

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.
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006
May 18th, 2009
0

Re: send binary file to serial port

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?
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Mick Curley is offline Offline
7 posts
since Apr 2009
May 20th, 2009
0

Re: send binary file to serial port

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
Reputation Points: 10
Solved Threads: 0
Light Poster
jonnytabpni is offline Offline
39 posts
since May 2009
May 20th, 2009
0

Re: send binary file to serial port

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
Reputation Points: 10
Solved Threads: 0
Light Poster
jonnytabpni is offline Offline
39 posts
since May 2009
May 20th, 2009
0

Re: send binary file to serial port

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"
Reputation Points: 10
Solved Threads: 0
Light Poster
jonnytabpni is offline Offline
39 posts
since May 2009
May 20th, 2009
0

Re: send binary file to serial port

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
Reputation Points: 10
Solved Threads: 2
Newbie Poster
Mick Curley is offline Offline
7 posts
since Apr 2009
Oct 9th, 2009
0
Re: send binary file to serial port
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.

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rodiepa26 is offline Offline
1 posts
since Oct 2009
Oct 9th, 2009
0
Re: send binary file to serial port
You can create a named pipe for LPT1 or which ever port the printer is on and send it data:
C# Syntax (Toggle Plain Text)
  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 { }
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: C# Generate Fixtures
Next Thread in C# Forum Timeline: Mouse Hook Help...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC