使用C#按下数据逻辑存储器设备上的扫描按钮时的备用事件
本文关键字:扫描 按钮 事件 备用 数据 存储器 使用 | 更新日期: 2023-09-27 18:21:55
我使用C#2003作为Datalogic Memor应用程序。我研究过当按下设备的"扫描按钮"时会触发KeyPress事件。捕获它是if(e.KeyChar == 13)
,但它不起作用。有其他选择吗?
尝试安装Datalogic SDK 2_0_0_0您可以从Datalogic网站下载。
然后添加对datalogic API的引用:
C:'Program Files'Microsoft.NET'SDK'CompactFramework'v3.5'WindowsCE'Datalogic.API.dll
现在你可以用这种方式使用API:
在您的表格声明上:
private DecodeEvent dcdEvent;
private DecodeHandle hDcd;
关于您的表单加载事件:
// Attempt to load a handle to the decoder.
try
{
hDcd = new DecodeHandle(DecodeDeviceCap.Exists | DecodeDeviceCap.Barcode);
}
catch(DecodeException)
{
MessageBox.Show("Exception loading barcode decoder.", "Decoder Error");
return;
}
// Now that we've got a connection to a barcode reading device, assign a
// method for the DcdEvent. A recurring request is used so that we will
// continue to get barcode data until our dialog is closed.
DecodeRequest reqType = (DecodeRequest)1 | DecodeRequest.PostRecurring;
// Initialize all events possible
//dcdEvent = new DecodeEvent(hDcd, reqType);
dcdEvent = new DecodeEvent(hDcd, reqType, this);
dcdEvent.Scanned += new DecodeScanned(dcdEvent_Scanned);
这是您的事件监听器:
private void dcdEvent_Scanned(object sender, DecodeEventArgs e)
{
CodeId cID = CodeId.NoData;
string dcdData = string.Empty;
// Obtain the string and code id.
try
{
dcdData = hDcd.ReadString(e.RequestID, ref cID);
}
catch(Exception)
{
MessageBox.Show("Error reading string!");
return;
}
string result = "Barcode Text: " + dcdData;
result +=" AND Barcode Code Id : " + cID.ToString();
MessageBox.Show(result);
}
关于您的表单关闭事件:
if(dcdEvent.IsListening)
{
dcdEvent.StopScanListener();
}
if (hDcd != null)
{
hDcd.Dispose();
}
对于Datalogic Memor X3,我使用DLScannerListener,如下所示:
DLScanner Scanner = new DLScanner();
Scanner.init();
Scanner.scanEnable();
Scanner.Listeners += new DLScannerListener(scanner_notify);
然后我在方法scanner_notify
中执行逻辑
private void scanner_notify(DLScannerEvent scannerEvent, DLScanner sender)
{
//Write your code here
}