我正在使用指纹上传,然后以pcx格式打印图像。
Step1使用TCP端口将图像上传到打印机,我使用命令:
IMAGE LOAD "bigfoot.1",1746,""\r\n打印机返回消息"OK“。然后使用socket将bigfo.1的字节数据发送给打印机。
步骤2打印图像“bigfo.1”:
PRPOS 200,200
DIR 3
ALIGN 5
PRIMAGE "bigfoot.1"
PRINTFEED
RUN出现问题时,打印机返回消息"Image not found“。所以我提出了上传失败的可能性。所以我打开软件PrintSet4检查镜像,镜像已经存在于TMP.Odd中了!最后,我使用PrintSet4代替我的套接字应用程序上传图片,添加文件并申请后,我使用step2打印命令打印图片,效果很好!上传图片的C#代码如下:
public void SendFile(string filePath, string CR_LF)
{
FileInfo fi = new FileInfo(filePath);
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
byte[] byteFile = new byte[fs.Length];
string cmd = "IMAGE LOAD \"" + fi.Name + "\"," + byteFile.Length.ToString() + ",\" \"" + CR_LF;
ClientSocket.Send(encode.GetBytes(cmd));
fs.Read(byteFile, 0, byteFile.Length);
Thread.Sleep(1000);
ClientSocket.Send(byteFile);
}
}发布于 2014-02-26 10:01:34
我已经修改了你的代码并使用了串口。
public void SendFile(string filePath)
{
SerialPort port = new SerialPort("COM3", 38400, Parity.None, 8, StopBits.One);
port.Open();
FileInfo fi = new FileInfo(filePath);
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
byte[] byteFile = new byte[fs.Length];
// string cmd = "IMAGE LOAD \"" + fi.Name + "\"," + teFile.Length.ToString()+ ",\"\"" + CR_LF;
string cmd = "IMAGE LOAD " + "\"" + fi.Name + "\"" + "," + byteFile.Length.ToString() + "," + "\"S\"";
port.WriteLine(cmd);
fs.Read(byteFile, 0, byteFile.Length);
port.Write(byteFile,0,byteFile.Count());
int count = byteFile.Count();
int length = byteFile.Length;
}
}所以我注意到问题出在使用CR_LF。相反,我使用了port.WriteLine(cmd),它的作用与添加行分隔符相同。它运行得很好。
https://stackoverflow.com/questions/21082648
复制相似问题