【求 C# 打开钱箱代码】
--------------------编程问答-------------------- 先顶下,不要沉了,急 --------------------编程问答-------------------- 写入byte[]数据到打印机,怎么弄出这么多ToString? --------------------编程问答--------------------代码是网上找的。
菜鸟,不太懂,请大侠指点下,如何操作,谢谢 --------------------编程问答-------------------- --------------------编程问答--------------------
--------------------编程问答--------------------
[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);
#region 开钱箱
/// <summary>
/// 开钱箱
/// </summary>
public void OpenDrawer()
{
try
{
IntPtr iHandle = CreateFile("LPT1", 0x40000000, 0, 0, 3, 0, 0);
if (iHandle.ToInt32() == -1)
{
MessageBox.Show("没有连接打印机或者打印机端口未打开!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
SafeFileHandle handle = new SafeFileHandle(iHandle, true);
FileStream fs = new FileStream(handle, 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 (Exception e)
{
MessageBox.Show(e.Message);
}
}
#endregion
关键的代码都和我一样,
我就是写了红色代码没反应 --------------------编程问答-------------------- 有高手吗 --------------------编程问答-------------------- 端口是串口COM1的,能不能用这个代码 --------------------编程问答-------------------- 串口COM1打不开
补充:.NET技术 , C#