我目前正在进行一个项目来控制霍尼韦尔创世纪7580 G扫描仪使用C#,POS为.NET和POS4NET套件从霍尼韦尔。我希望获得当前的串行读取超时,因此我通过以下方式从DirectIO()方法调用POS4NET:
string command = "TRGSTO?.";
DirectIOData response = scanner.DirectIO(18, 1024, Encoding.ASCII.GetBytes(command));
byte[] buffer = (byte[])response.Object;
Console.WriteLine("$: Response: " + Encoding.ASCII.GetString(buffer));此代码打印:
"$:回复: TRGSTO20“
它缺少三个零(时间单位是毫秒)和ACK字符。我正期待着这个..。
"$:回复: TRGSTO20000ACK“
但是,如果我更改命令以获得不同的设置.
string command = "BEPPWR?.";
DirectIOData response = scanner.DirectIO(18, 1024, Encoding.ASCII.GetBytes(command));
byte[] buffer = (byte[])response.Object;
Console.WriteLine("$: Response: " + Encoding.ASCII.GetString(buffer));代码按预期工作,并打印
"$:回复: BEPPWR1ACK“
使用DirectIO()发送查询命令的正确方法是什么?
发布于 2017-11-28 04:52:53
响应数据是否可能已正确到达,并被转换为字符串,从而被视为以零结尾?
请使用BitConverter.ToString()而不是Encoding.ASCII.GetString()检查字节数组数据的内容。
发布于 2019-10-21 14:18:56
我通常用POS表示.NET和财政打印机POS。当我需要发送一个DirectIO时,我使用这种类型的代码来发送和接收响应:我希望它是有用的
string[] strObj = new string[1];
DirectIOData dirIO;
int iData;
strObj[0] = "01";
dirIO = posCommonFP.DirectIO(0, 1138, strObj);
iData = dirIO.Data;
strObj = (string[])dirIO.Object;https://stackoverflow.com/questions/46649399
复制相似问题