using System;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.IO.Ports;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Text;
using System.Drawing.Design;
using System.Drawing.Imaging;
namespace ShippingStation_csharp
{
class clsPrinter
{
public SerialPort ComPort1 = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
public SerialPort ComPort2 = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
///
[STAThread]
static void Main(string[] args)
{
}
public clsPrinter()
{
}
public void InitShippingPrinter(SerialPort m_pPortCom)
{
SendCommandToPrinter(m_pPortCom, "\nN");
SendCommandToPrinter(m_pPortCom, "D7");
SendCommandToPrinter(m_pPortCom, "S2");
SendCommandToPrinter(m_pPortCom, "ZT");
SendCommandToPrinter(m_pPortCom, "Q1800,36");
SendCommandToPrinter(m_pPortCom2, "q1200");
}
public void InitSerialPrinter(SerialPort m_pPortCom)
{
SendCommandToPrinter(m_pPortCom, "\nN");
SendCommandToPrinter(m_pPortCom, "D7");
SendCommandToPrinter(m_pPortCom, "S1");
SendCommandToPrinter(m_pPortCom, "ZT");
SendCommandToPrinter(m_pPortCom, "Q450,36");
SendCommandToPrinter(m_pPortCom, "q900");
}
public void PrintToPrinter(PrintPageEventHandler PagetoPrint)
{
PrintDocument tPrinter = new PrintDocument();
tPrinter.PrintPage += new PrintPageEventHandler(PagetoPrint);
tPrinter.Print();
}
public void ComPortData(SerialPort port, string cmd)
{
SendCommandToPrinter(port, cmd);
}
private static void SendTextFile(SerialPort port, string FileName)
{
port.Write(File.OpenText(FileName).ReadToEnd());
}
private void SendCommandToPrinter(SerialPort port, string cmd)
{
string str = null;
str=cmd + "\n";
port.Write(str);
}
}
}