init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Zhaizj.Framework.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// 钱箱控制
|
||||
/// </summary>
|
||||
public class POSPrinter
|
||||
{
|
||||
const int OPEN_EXISTING = 3;
|
||||
string prnPort = "COM1";
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||
private static extern IntPtr CreateFile(string lpFileName,
|
||||
int dwDesiredAccess,
|
||||
int dwShareMode,
|
||||
int lpSecurityAttributes,
|
||||
int dwCreationDisposition,
|
||||
int dwFlagsAndAttributes,
|
||||
int hTemplateFile);
|
||||
|
||||
public POSPrinter()
|
||||
{
|
||||
this.prnPort = "LPT1 ";
|
||||
//this.prnPort = "USB001";
|
||||
}
|
||||
public POSPrinter(string prnPort)
|
||||
{
|
||||
this.prnPort = prnPort;
|
||||
}
|
||||
public void PrintLine()
|
||||
{
|
||||
new Thread(new ThreadStart(OpenMoneyBox)).Start();
|
||||
}
|
||||
|
||||
private void OpenMoneyBox()
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr iHandle = CreateFile(prnPort, 0x40000000, 0, 0, OPEN_EXISTING, 0, 0);
|
||||
if (iHandle.ToInt32() == -1)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite);
|
||||
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
|
||||
sw.Write(((char)27).ToString() + "p" + ((char)0).ToString() + ((char)60).ToString() + ((char)255).ToString());
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user