Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a Cash Drawer details as below :

Quote:
Model: D41SRB
SKU: D41SRB
Electronic Cash Drawer Black 16",
Roller, 24V Epson STD RJ11, Stainless front
5 Bill/5 Coin
1mm steel case
Two extra brackets inside top of case for added durability


It is connected to
Quote:
EPSON TM-T88V Receipt
via RJ11 plugged into Printer.
How can I open this drawer from my C# POS application when sale is made. I checked drawer from Printer Preference to open after printing it works fine.

What I have tried:

I tried writing code as stated HERE It gave me error port is closed . So I changed it to :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace cashdrawertest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private SerialPort serialPort1 = new SerialPort();

        public void OpenPort()
        {
            //serialPort1.PortName = "COM1";
            serialPort1.PortName = "ESDPRT001";
            serialPort1.Encoding = Encoding.ASCII;
            serialPort1.BaudRate = 38400;
            serialPort1.Parity = System.IO.Ports.Parity.None;
            serialPort1.DataBits = 8;
            serialPort1.StopBits = System.IO.Ports.StopBits.One;
            serialPort1.DtrEnable = true;
            try
            {
                serialPort1.Open();
            }
            catch (Exception ex)
            {
                serialPort1.Close();
                serialPort1.Open();
            }
//            serialPort1.Open();
        }

        public void InitializePrinter()
        {
            serialPort1.Write(Char.ConvertFromUtf32(27) + char.ConvertFromUtf32(64));
        }

        public void OpenDrawer()
        {
            serialPort1.Write(char.ConvertFromUtf32(27) +
               char.ConvertFromUtf32(112) +
               char.ConvertFromUtf32(0) +
               char.ConvertFromUtf32(5) +
               char.ConvertFromUtf32(5));
        }
        private void button1_Click(object sender, EventArgs e)
        {
            OpenDrawer();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            serialPort1.PortName = "COM1";
            //serialPort1.PortName = "ESDPRT001";
            serialPort1.Encoding = Encoding.ASCII;
            serialPort1.BaudRate = 38400;
            serialPort1.Parity = System.IO.Ports.Parity.None;
            serialPort1.DataBits = 8;
            serialPort1.StopBits = System.IO.Ports.StopBits.One;
            serialPort1.DtrEnable = true;
            try
            {
                serialPort1.Open();
            }
            catch (Exception ex)
            {
                serialPort1.Close();
                serialPort1.Open();
            }
        }
    }
}


I checked Port under printer properties it has ESDPRT001 for
Quote:
EPSON TM-T88V Receipt


Again it says same thing Port is Closed. So please help. Thanks
Posted
Updated 4-Mar-18 19:25pm

1 solution

Put a breakpoint on the first line in your OpenDrawer method, and run your app in the debugger. Check the condition of the SerialPort object when the breakpoint gets hit.

But ... two things:
1) When you copy code at random from the internet, it's a good idea to think about what you are doing - you aren't doing that or you wouldn't have the same code repeated in your Load event handler and your OpenPort method that you never call.
2) When you copy code from the internet, you might want to copy it all - and call the InitializePrinter method at some point.
3) When you copy code from the internet, it's a very good idea to think about it and check that the COM port you are trying to use is in fact the right one for your printer - COM1 may not be the right port. Always prove communications using a terminal program such as HyperTerminal before you even start to write code to make sure that everything is working before adding another layer of confusion.

That code is ... um ... poor. I know, I know - you didn't write it. But "if it fails to open, just try again" is a poor way to do anything ...
 
Share this answer
 
Comments
markwhite1 5-Mar-18 1:46am    
I have this code in developer PC and setup runs on Client PC. Any tutorial or sample to run hyper terminal for drawer?
OriginalGriff 5-Mar-18 2:31am    
Google:
https://www.google.co.uk/search?q=hyperterminal+tutorial&oq=HyperTerminal+tutoi&aqs=chrome.1.69i57j0l5.6630j0j7&sourceid=chrome&ie=UTF-8
markwhite1 5-Mar-18 3:36am    
I am trying to run hyperterminal, in connect to- it has USB Soft modem, TCP/IP Winsock and COM3. When I select COM3 (as USB Soft modem is not the one) then it says its already in use. I also found out the code for my printer to open drawer dont know how to use it. I am sorry for being so naive
OriginalGriff 5-Mar-18 3:54am    
So you are trying to connect HT to COM3 and your software to COM1? You need to decide which is which...

Try looking to see if there are any device drivers or other software for the printer installed that might be using the port.
Remember, I can't do anything directly - I have no access at all to your machine(s) and no idea what you have plugged in where!
markwhite1 5-Mar-18 7:06am    
I tried COM1, COM3, ESDPRT001(under printer preference port) but same results. However for plugging Epson Printer connected to PC via USB and Cash Drawer via RJ11 to printer.Sorry if I am being naive.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900