Hi, I need some assistance. I'ved been searching the web for days now and can't find an example that really helps me. I have an EPSON TM-T88IV printer through which I want to open a cash drawer. I have this class in my project: -
using System;
-
using System.IO;
-
using System.Runtime.InteropServices;
-
-
namespace PrintDataGrid
-
/* For a standard cash drawer, there's a physical cable that runs from the cash drawer and plugs into the receipt printer.
-
• To open the drawer, you issue a command to the printer. The printer will send a signal to the cash drawer that kicks open the drawer.
-
• For a standard epson receipt printer such as the Epson TM-T88III receipt printer, the command is:
-
fwrite($handle, chr(27). chr(112). chr(0). chr(100). chr(250));
-
• For other receipt printers, you should be able to find the command in their user's manual. (Try the above code first. Most probably it will work. Receipt printers have been in existence for a long time. They have more or less adopted the same standard.)
-
• A standard receipt printer such as the Epson TM-T88III receipt printer uses the parallel port.
-
• To print to the parallel-port receipt printer, you print through port PRN (exactly the same as printing from DOS prompt).
-
• From within PHP-GTK2, you need to first establish the connection with the printer by using
-
$handle = fopen("PRN", "w");
-
• Thereafter, to print anything to the printer, you just "write" to it like the file handle: fwrite($handle, 'text to printer');
-
• There are newer receipt printer that uses USB. I believe you should be able to print to such printers through PRN too.
-
*/
-
{
-
public class RawPrinterHelper
-
{
-
// Structure and API declarions:
-
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
-
public class DOCINFOA
-
{
-
[MarshalAs(UnmanagedType.LPStr)] public string pDocName;
-
[MarshalAs(UnmanagedType.LPStr)] public string pOutputFile;
-
[MarshalAs(UnmanagedType.LPStr)] public string pDataType;
-
}
-
[DllImport("winspool.Drv", EntryPoint="OpenPrinterA", SetLastError=true,CharSet=CharSet.Ansi, ExactSpelling=true,CallingConvention=CallingConvention.StdCall)]
-
public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)]
-
string szPrinter, out IntPtr hPrinter, long pd);
-
[DllImport("winspool.Drv", EntryPoint="ClosePrinter", SetLastError=true,ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
-
public static extern bool ClosePrinter(IntPtr hPrinter);
-
[DllImport("winspool.Drv", EntryPoint="StartDocPrinterA", SetLastError=true,CharSet=CharSet.Ansi, ExactSpelling=true,CallingConvention=CallingConvention.StdCall)]
-
public static extern bool StartDocPrinter( IntPtr hPrinter, Int32 level,[In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);
-
[DllImport("winspool.Drv", EntryPoint="EndDocPrinter", SetLastError=true,ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
-
public static extern bool EndDocPrinter(IntPtr hPrinter);
-
[DllImport("winspool.Drv", EntryPoint="StartPagePrinter", SetLastError=true,ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
-
public static extern bool StartPagePrinter(IntPtr hPrinter);
-
[DllImport("winspool.Drv", EntryPoint="EndPagePrinter", SetLastError=true,ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
-
public static extern bool EndPagePrinter(IntPtr hPrinter);
-
[DllImport("winspool.Drv", EntryPoint="WritePrinter", SetLastError=true,ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
-
public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten );
-
[DllImport("kernel32.dll", EntryPoint="GetLastError", SetLastError=false, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
-
public static extern Int32 GetLastError();
-
public static bool SendBytesToPrinter( string szPrinterName, IntPtr pBytes, Int32 dwCount)
-
{
-
Int32 dwError = 0, dwWritten = 0;
-
IntPtr hPrinter = new IntPtr(0);
-
DOCINFOA di = new DOCINFOA();
-
bool bSuccess = false; // Assume failure unless you specifically succeed.
-
di.pDocName = "My C#.NET RAW Document";
-
di.pDataType = "RAW";
-
if( OpenPrinter( szPrinterName, out hPrinter, 0 ) )
-
{
-
if( StartDocPrinter(hPrinter, 1, di) )
-
{
-
if( StartPagePrinter(hPrinter) )
-
{
-
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
-
EndPagePrinter(hPrinter);}
-
EndDocPrinter(hPrinter);
-
}
-
ClosePrinter(hPrinter);
-
}
-
if( bSuccess == false )
-
{
-
dwError = GetLastError();
-
}
-
return bSuccess;
-
}
-
public static bool SendFileToPrinter( string szPrinterName, string szFileName )
-
{
-
FileStream fs = new FileStream(szFileName, FileMode.Open);
-
BinaryReader br = new BinaryReader(fs);
-
Byte []bytes = new Byte[fs.Length];
-
bool bSuccess = false;
-
IntPtr pUnmanagedBytes = new IntPtr(0);
-
int nLength;
-
nLength = Convert.ToInt32(fs.Length);
-
bytes = br.ReadBytes( nLength );
-
pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
-
Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
-
bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
-
Marshal.FreeCoTaskMem(pUnmanagedBytes);
-
return bSuccess;
-
}
-
public static bool SendStringToPrinter( string szPrinterName, string szString )
-
{
-
IntPtr pBytes;
-
Int32 dwCount;
-
dwCount = szString.Length;
-
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
-
SendBytesToPrinter(szPrinterName, pBytes, dwCount);
-
Marshal.FreeCoTaskMem(pBytes);
-
return true;
-
}
-
public static bool OpenCashDrawer1( string szPrinterName)
-
{
-
//27,112,48,55,121
-
Int32 dwError = 0, dwWritten = 0;
-
IntPtr hPrinter = new IntPtr(0);
-
DOCINFOA di = new DOCINFOA();
-
bool bSuccess = false;
-
di.pDocName = "OpenDrawer";
-
di.pDataType = "RAW";
-
if( OpenPrinter( szPrinterName, out hPrinter, 0 ) )
-
{
-
if( StartDocPrinter(hPrinter, 1, di) )
-
{
-
if( StartPagePrinter(hPrinter) )
-
{
-
int nLength;
-
byte[] DrawerOpen = new byte[] { 07 };
-
nLength = DrawerOpen.Length;
-
IntPtr p = Marshal.AllocCoTaskMem(nLength);
-
Marshal.Copy(DrawerOpen, 0, p, nLength);
-
bSuccess = WritePrinter(hPrinter, p, DrawerOpen.Length, out dwWritten);
-
EndPagePrinter(hPrinter);
-
Marshal.FreeCoTaskMem(p);
-
}
-
EndDocPrinter(hPrinter);
-
}
-
ClosePrinter(hPrinter);
-
}
-
if( bSuccess == false )
-
{
-
dwError = GetLastError();
-
}
-
return bSuccess;
-
}
-
public static bool FullCut( string szPrinterName)
-
{
-
//27, 109
-
Int32 dwError = 0, dwWritten = 0;
-
IntPtr hPrinter = new IntPtr(0);
-
DOCINFOA di = new DOCINFOA();
-
bool bSuccess = false;
-
di.pDocName = "FullCut";
-
di.pDataType = "RAW";
-
if( OpenPrinter( szPrinterName, out hPrinter, 0 ) )
-
{
-
if( StartDocPrinter(hPrinter, 1, di) )
-
{
-
if( StartPagePrinter(hPrinter) )
-
{
-
int nLength;
-
byte[] DrawerOpen = new byte[] { 27, 100, 51 };
-
nLength = DrawerOpen.Length;
-
IntPtr p = Marshal.AllocCoTaskMem(nLength);
-
Marshal.Copy(DrawerOpen, 0, p, nLength);
-
bSuccess = WritePrinter(hPrinter, p, DrawerOpen.Length, out dwWritten);
-
EndPagePrinter(hPrinter);
-
Marshal.FreeCoTaskMem(p);
-
}
-
EndDocPrinter(hPrinter);
-
}
-
ClosePrinter(hPrinter);
-
}
-
if( bSuccess == false )
-
{
-
dwError = GetLastError();
-
}
-
return bSuccess;
-
}
-
}
-
}
-
then in my windows form I have a button through which I want when a user clicks on it it opens the cash drawer...my code for that button is : -
RawPrinterHelper.OpenCashDrawer1("EPSON TM-T88IV");
-
But that doesn't do anything whatsoever...si mply returns bSuccess as false...On this link: http://pages.prodigy.n et/daleharris/popopen.htm i found the code for my printer which is : Epson TM-88IV Drawer codes: 27,112,48,55,12 1 Cutter codes: 27, 109. I even implemented that in the full cut function of the class but still doesn't work.
Any input will be greatly appreciated. My printer works perfectly, the cash drawer simply does not open....please shed some light on the matter...maybe im missing something else since in vb you must convert it into a string using this BASIC code...
POPOPEN$ = CHR$(27) + CHR$(112) + CHR$(48) + CHR$(55) + CHR$(121)
Now all you have to do to open your cash drawer is to send the string to the printer using...
LPRINT POPOPEN$
But i need the code in C#.
Thanks...
3 28612 Plater 7,872
Recognized Expert Expert
Assuming your printer writing functions are correct...your code never shows you sending the 127 112 48 55 121.
I see 07 for open and 27 100 51 for full cut, but never your drawer opener sequence?
Assuming your printer writing functions are correct...your code never shows you sending the 127 112 48 55 121.
I see 07 for open and 27 100 51 for full cut, but never your drawer opener sequence?
Yeah I tried it including the codes but still nothing happens.
this is the comment I got on the code im using: -
/* For a standard cash drawer, there's a physical cable that runs from the cash drawer and plugs into the receipt printer.
-
• To open the drawer, you issue a command to the printer. The printer will send a signal to the cash drawer that kicks open the drawer.
-
• For a standard epson receipt printer such as the Epson TM-T88III receipt printer, the command is:
-
fwrite($handle, chr(27). chr(112). chr(0). chr(100). chr(250));
-
• For other receipt printers, you should be able to find the command in their user's manual. (Try the above code first. Most probably it will work. Receipt printers have been in existence for a long time. They have more or less adopted the same standard.)
-
• A standard receipt printer such as the Epson TM-T88III receipt printer uses the parallel port.
-
• To print to the parallel-port receipt printer, you print through port PRN (exactly the same as printing from DOS prompt).
-
• From within PHP-GTK2, you need to first establish the connection with the printer by using
-
$handle = fopen("PRN", "w");
-
• Thereafter, to print anything to the printer, you just "write" to it like the file handle: fwrite($handle, 'text to printer');
-
• There are newer receipt printer that uses USB. I believe you should be able to print to such printers through PRN too.
-
*/
-
I am using a USB connection to the printer, but i see the code in this comment is PHP. I would need to know how to use it using C#. Any ideas?
Plater 7,872
Recognized Expert Expert
Well wait, it's in a USB port?
All the code you were writing was for talking on a parallel port though?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Scott A. Keen |
last post by:
Hi,
I'm getting tasked with writing an ASP application deployed throughout the
company's intranet where all the workstations will be running Internet
Explorer 6.0.
It's a retail business, and some of the workstations are Point-Of-Sale and
will need to have cash drawers and bar-code scanners.
The project managers want this as a web-application because of the ease of
|
by: PW |
last post by:
I have an electronic cash drawer as part of a point-of-sale installation.
You're supposed to be able to automatically open the cash drawer with some
printer commands (drawer is connected to the receipt printer) but I can't
get it to open automatically. I want it to open when the customers receipt
is printed.
How do you send printer escape sequences to a windows printer via ASP ?
The cash drawer model is ... Posiflex CR-4100 Cash Drawer
|
by: Tor Inge Schulstad |
last post by:
Hi
I'm developing a POS software using an Epson TM-T88iii printer with a
cash drawer connected to the printer. The printer is connected via a usb
interface to the pc.
Can anyone tell me how I can open the cash drawer from my VB.NET
application? The printer driver requires me to use a soft font named
"control" in the printer, and print the letter "A", but if I'm right,
the .NET framework does not support using soft fonts...
|
by: samozluk |
last post by:
I am using Ms Access 2003 to produce a customer receipt, the printer is the Posiflex PP-7000 II Usb thermal printer and it is meant to open the cash drawer. Can someone please give me the code to add to the report to open the cash draw.
Thanks in advance.
|
by: fidamon |
last post by:
hi
if any body can help me with that question i will be thankfull
How to open a cash drawer connected to serial comm
it has no name no user manual and nothing but a serial port connection and a power supply connection
Fidamon
| |
by: CyberKnight |
last post by:
Hello Friends,
What function that enable the cash drawer in a POS, using visual basic coding. Thanks.
|
by: danishce |
last post by:
Hi, I've been trying to configure the cash drawer connected directly to the CPU of the IBM Surepos PC. The cash drawer IBM P/N is 74F6178, IBM FRU P/N is 93F1901. The cash drawer port is connected to the 3A port on the CPU. Does anybody know how to configure this to open the cash drawer because i have no manual and documentation for the cash drawer?
Regards:
Danish Majid
|
by: imlambo |
last post by:
I am designing a point of sale and i am stuck on how to open a cash drawer. Since my system is going to be used by many clients i need help on a design which can open all cash drawers. Or just for EPSON cash drawer. I need VB.net 2003 source code i any one has it.
Help me I am stuck.
rgds
|
by: ARC |
last post by:
I have a user asking if I could put in a code that will open a register
drawer. My understanding is the receipt printer will normally send the code
the cash drawer. Is there a vba function that someone can share that will
open a drawer without printing? Or does it depend on the drawer? I suppose
if it's just a sequence of characters, then it could be made customizable to
work for many different users. Any ideas?
Thanks!
Andy
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |