Click here to Skip to main content
15,891,748 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I print labels in SATO printer from my C#.net windows application. Normally I was printing by placing the controls in a form and using print document and graphics I was able to print in normal printers. But after installing SATO printer driver even I could not see the print preview.
Posted

1 solution

Sato Printers if ethernet based can just use a ASCII string sent to it through IP and PORT(9100). Example of code below:

public static bool SendPrintJob(string sendString, string ipAddress, int port)
        {
            bool bReturn = true;
            sendString.ThrowIfNullOrEmpty("sendString");
            ipAddress.ThrowIfNullOrEmpty("ipAddress");

            if (port <= 0)
                port = 9100;

            Socket sock = null;

            try
            {
                IPEndPoint remoteIP = new IPEndPoint(IPAddress.Parse(ipAddress), port);
                sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IAsyncResult results = sock.BeginConnect(remoteIP, null, null);
                bool success = results.AsyncWaitHandle.WaitOne(5000, true);

                if (!sock.Connected)
                {
                    //Raise error message to user that printer failed to print
                    bReturn = false;

                    //Socket error occured
                    Log.WriteToErrorLog("Error in socket connection: Could not connect to printer.", "", "Socket Error: SendPrintJob");
                }
                else
                {
                    byte[] sendData = Encoding.ASCII.GetBytes(sendString);
                    int result = sock.Send(sendData, sendData.Length, 0);

                    if (result == 0)
                    {
                        //Raise error message to user that printer failed to print
                        bReturn = false;

                        //Socket error occured
                        Log.WriteToErrorLog("Error in socket transmission: Could not send data to printer.", "", "Socket Error: SendPrintJob");
                    }
                }

                return bReturn;
            }
            finally
            {
                if (sock != null)
                    sock.Close();
            }
        }
 
Share this answer
 
Comments
mohad_arab 1-Feb-17 3:58am    
Great it works fine , but Any Idea , How To send Arabic (Unicode) as currently prints "????" instead of Arabic.

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