MT2070与Windows CE5.0一起运行,并通过蓝牙连接到底座STB2078。但每次我得到"发送失败"而ResultCode是" E_INCORRECT_MODE"。
问题是不明白他们的意思" INCORRECT_MODE"我将它设置为DECODE,并通过RawData将其设置为源?
ScannerServicesClient scannerServices;
scannerServices = new ScannerServicesClient();
SCANNERSVC_MODE mode;
if(scannerServices.Connect(true))
{
Logger("start service with decode rights"); // primitiv method to see what happen
scannerServices.GetMode(out mode);
if (mode != SCANNERSVC_MODE.SVC_MODE_DECODE)
{
mode = SCANNERSVC_MODE.SVC_MODE_DECODE;
if (scannerServices.SetMode(mode) != RESULTCODE.E_OK)
{
Logger("cant set mode: " + mode.ToString());
}
}
// wanna know which connection is use
string connection = "";
switch (scannerServices.HostParameters.CurrentConnection)
{
case SCANNERSVC_DATA_CONNECTION.NO_CONNECTION:
connection = "Not connected";
break;
case SCANNERSVC_DATA_CONNECTION.BLUETOOTH:
connection = scannerServices.HostParameters.BluetoothConnection.ToString();
break;
case SCANNERSVC_DATA_CONNECTION.RS232:
connection = scannerServices.HostParameters.RS232Connection.ToString();
break;
case SCANNERSVC_DATA_CONNECTION.USB_CABLE:
connection = scannerServices.HostParameters.USBConnection.ToString();
break;
}
Logger(connection);
ScannerHostParameters scnHost = new ScannerHostParameters(scannerServices);
//example hello
string input = "hello"; //what should send
byte[] output = new byte[input.Length]; //field with converted data
byte source = 0; //<-- what mean source? i sum all byte-value but this cant be correct
for (int i = 0; i < input.Length; ++i)
{
output[i] = Convert.ToByte(input[i]);
source += output[i];
}
RawData rawData = new RawData(output, input.Length, source);
//RawParameters rawParam = new RawParameters();
//rawParam.BaudRate = RawParameters.RawBaudRates.RAWSERIAL_9600;
//rawParam.Type = RawParameters.RawHostType.Auto;
RESULTCODE result = scannerServices.SendRawData(rawData, 2000);
if(result == RESULTCODE.E_OK)
{
Logger("successful send");
}
else
{
Logger("Send failed: " + result.ToString());
}
Logger("ScannerService kill");
scannerServices.Disconnect();
}
Logger("\n");
scannerServices.Dispose();
scannerServices = null;
感谢您的帮助! (对不起我的英语)
答案 0 :(得分:0)
在某些时候(你正在设置模式的地方 - 我在设置模式后立即执行)你会想要这样做:
//set raw mode
if (RESULTCODE.E_OK != scannerServices.SetAttributeByte((ushort)ATTRIBUTE_NUMBER.ATT_MIA_HOSTNUM, (byte)ENUM_HOSTS.HOST_RAW))
{
throw new Exception("Can't set RAW mode");
scannerServices.Disconnect();
scannerServices.Dispose();
return;
}
你在哪里:
RawData rawData = new RawData(output, input.Length, source);
您可以将来源保留为0:
RawData rawData = new RawData(output, input.Length, 0);
不幸的是,在编程时我并不是最棒的,所以我只是偶然发现了我的扫描仪工作原理。文档不是很好,事实上我发现它非常缺乏。甚至摩托罗拉的人们似乎也不太了解它或如何编程。我至少在一点上被他们误导了。
我使用扫描仪的CDC COM端口仿真模式,以便它显示在设备管理器中的端口下(我需要扫描仪使用我们使用COM端口的旧程序)。此外还需要一个驱动程序。
根据您使用扫描仪的方式,上述内容可能有效,也可能无效。