打印机清空色带和清空纸张操作 请问思路应该怎么走?打印机是并口吧,我只做过串口读取数据的程序。如何向打印机发送指令呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用LPT1口就好了, [DllImport("kernel32")] static extern SafeFileHandle CreateFile( string filename, uint desiredAccess, uint shareMode, uint attributes, // really SecurityAttributes pointer uint creationDisposition, uint flagsAndAttributes, uint templateFile); private const uint GENERIC_READ = 0x80000000; private const uint GENERIC_WRITE = 0x40000000; private const int OPEN_EXISTING = 3; private const int INVALID_HANDLE_VALUE = -1; public static void PrintStringToPrinter(string as_str, string s_Port_) { string s_Port = s_Port_; switch (s_Port.ToUpper()) { case "LPT1": SafeFileHandle iHandle; iHandle = CreateFile("LPT1", GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if (iHandle.IsInvalid) { throw new Exception("Can't find the printer connecting to the port of LPT1"); } else { FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite); //fs.WriteTimeout=0; byte[] byteOut; Int32 dwCount = as_str.Length; byteOut = new byte[dwCount]; for (int i = 0; i < dwCount; i++) { byteOut[i] = System.Convert.ToByte(as_str[i]); } fs.Write(byteOut, 0, dwCount); fs.Flush(); fs.Close(); } break; } } 怎样将xml文件中的所有节点保存到一个XmlNodeList中? 求代码 C#网络编程 求助 求助通过循环的方法给一组label的属性发生改变???? word 的操作 C# 如何进行alpha混色 实现图片变暗 SRT字幕的正则表达式 C# windows service 哪位朋友有最新版本的Developer Express Editors和Developer Express Grids控件? 请教如何实现这样的功能?分不够再加!! 各位高手们,请教教小弟如何在C#下使用SetSystemTime这个API函数?(在线等待) 100分求一简单正则表达式 WPF的入口函数在哪里?
[DllImport("kernel32")]
static extern SafeFileHandle CreateFile(
string filename,
uint desiredAccess,
uint shareMode,
uint attributes, // really SecurityAttributes pointer
uint creationDisposition,
uint flagsAndAttributes,
uint templateFile);
private const uint GENERIC_READ = 0x80000000;
private const uint GENERIC_WRITE = 0x40000000;
private const int OPEN_EXISTING = 3;
private const int INVALID_HANDLE_VALUE = -1; public static void PrintStringToPrinter(string as_str, string s_Port_)
{
string s_Port = s_Port_;
switch (s_Port.ToUpper())
{
case "LPT1":
SafeFileHandle iHandle;
iHandle = CreateFile("LPT1", GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if (iHandle.IsInvalid)
{
throw new Exception("Can't find the printer connecting to the port of LPT1");
}
else
{
FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite);
//fs.WriteTimeout=0;
byte[] byteOut;
Int32 dwCount = as_str.Length;
byteOut = new byte[dwCount];
for (int i = 0; i < dwCount; i++)
{
byteOut[i] = System.Convert.ToByte(as_str[i]);
}
fs.Write(byteOut, 0, dwCount);
fs.Flush();
fs.Close();
}
break;
} }