我正在尝试使用简单的写入命令将字符串写入 Com5 上的内部打印机。 WriteLine 方法打印效果很好,但 Write 方法却不行。下面是我调用的代码。它只是调用 .NET 函数的简单包装函数。
public static void Write(string printString)
{
//intialize the com port
SerialPort com5 = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.One);
com5.Handshake = Handshake.XOnXOff;
com5.Open();
//write the text to the printer
com5.Write(printString);
Thread.Sleep(100);
com5.Close();
}
public static void WriteLine(string printString)
{
//intialize the com port
SerialPort com5 = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.One);
com5.Handshake = Handshake.XOnXOff;
com5.Open();
//write the text to the printer
com5.WriteLine(printString);
Thread.Sleep(100);
com5.Close();
}
最佳答案
WriteLine 将在字符串中追加一个新行字符。也许这会“刷新”缓冲区以使打印机响应输入。
关于C# SerialPort WriteLine 可以工作但不能写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17683103/