分享到
新浪微博
分享到
朋友圈
分享到
QQ空间
发布日期:2020-09-29 来源: 本站 阅读量(4460)
销邦X5手持终端/销邦wince手持终端二次开发,扫描头调用需要调用专门的支持的SDK库文件,通过销邦手持终端自定义的API进行获取手持终端扫描的条码。 销邦X5手持机核心代码如下: namespace SalesPoint.DeviceTest2 { public partial class FrmScan : Form { /// <summary> ///函数名称:SpGetScanSet ///函数功能:获取码制的开启情况 5600 4313 4500能用,其他的扫描头暂不支持 /// </summary> /// <param name="dwcode">码制</param> /// <param name="state">返回参数,0表示关闭,1表示打开</param> /// <param name="dwexten">暂时不使用/param> /// <returns>0--失败,1--成功</returns> [DllImport("spHardWareInterface.dll", EntryPoint = "SpGetScanSet")] internal static extern int SpGetScanSet(int dwcode, ref byte state, int dwExten); int scanCount = 0; int iDeviceType = 1; //扫描头类型 public FrmScan() { InitializeComponent(); } //初始化 private void Form1_Load(object sender, EventArgs e) { Sys.Initilize(); //硬件初始化 Thread.Sleep(500); Scanner.Initilize();//扫描头初始化 this.KeyPreview = true; //一定要设置此项,否则无法扫描 cbbHint.SelectedIndex = 0; cbbHint_SelectedIndexChanged(null, null); cbbScanCode.SelectedIndex = 0; scanCount = 0; lblCount.Text = "已扫描0条"; cbbScanType.Enabled = true; cbbScanCode.Enabled = false; } private void Form1_Closing(object sender, CancelEventArgs e) { Scanner.Deinitilize();//释放扫描头 Thread.Sleep(500); Sys.Deinitilize();//释放硬件 } //键盘按钮事件 private void Form1_KeyDown(object sender, KeyEventArgs e) { string BarcodeStr = string.Empty; if (e.KeyValue == 131)//Scan按键 { if(iDeviceType==1)//一维 BarcodeStr = Scanner.StartScan(ScanType.None); else if (iDeviceType == 2)//二维 { //二维码中如果有汉字的,出现乱码要如下处理,二维头(UTF8码制请改成UTF-8,OENCP码制请改成GB2312。。。) if (cbbScanCode.SelectedIndex !=-1) { if ("NULL" == cbbScanCode.SelectedItem.ToString()) { BarcodeStr = Scanner.StartScanDim2(ScanType.None); } if ("ASCII" == cbbScanCode.SelectedItem.ToString()) { BarcodeStr = Scanner.StartScanDim2(ScanType.None, Encoding.ASCII); byte[] Tempbuffer = Encoding.ASCII.GetBytes(BarcodeStr); BarcodeStr = Encoding.ASCII.GetString(Tempbuffer, 0, Tempbuffer.Length); } if ("UTF-7" == cbbScanCode.SelectedItem.ToString()) { BarcodeStr = Scanner.StartScanDim2(ScanType.None, Encoding.UTF7); byte[] Tempbuffer = Encoding.UTF7.GetBytes(BarcodeStr); BarcodeStr = Encoding.UTF7.GetString(Tempbuffer, 0, Tempbuffer.Length); } if ("UTF-8" == cbbScanCode.SelectedItem.ToString()) { BarcodeStr = Scanner.StartScanDim2(ScanType.None, Encoding.UTF8); byte[] Tempbuffer = Encoding.UTF8.GetBytes(BarcodeStr); BarcodeStr = Encoding.UTF8.GetString(Tempbuffer, 0, Tempbuffer.Length); } if ("GB2312" == cbbScanCode.SelectedItem.ToString()) { BarcodeStr = Scanner.StartScanDim2(ScanType.None, Encoding.Unicode); byte[] Tempbuffer = Encoding.Unicode.GetBytes(BarcodeStr); BarcodeStr = Encoding.Unicode.GetString(Tempbuffer, 0, Tempbuffer.Length); } } } //显示条码 if (BarcodeStr.Trim().Length > 0) { if (scanCount > 100) btnClean_Click(null, null); txtBarcode.Text += BarcodeStr + "
";//一维码默认码制 Scanner.ScanSuccessSound(SalesPoint.Device.Scan.Scanner._scansoundtype); //SalesPoint.Device.SoundPlay.Play("\绝对路径\提示声音.wav"); //如要换其他声音文件用此方法 scanCount++; lblCount.Text = "已扫描" + scanCount.ToString() + "条"; this.txtBarcode.Focus();//获取焦点 this.txtBarcode.Select(this.txtBarcode.TextLength, 0);//光标定位到文本最后 this.txtBarcode.ScrollToCaret();//滚动到光标处 } #region region 获取码制 string codeType; codeType = Scanner.GetCodeType(); txtCodeType.Text = codeType; #endregion endregion } else if (e.KeyValue == 8) { btnClean_Click(null, null); } else if (e.KeyValue == 27) { this.Close(); } } //设置扫描方式 private void cbbScanType_SelectedIndexChanged(object sender, EventArgs e) { try { if (cbbScanType.SelectedIndex == 0) { SalesPoint.Device.Scan.Scanner.SetTrigger(0);//单扫 } else if (cbbScanType.SelectedIndex == 1) { SalesPoint.Device.Scan.Scanner.SetTrigger(2);//连扫(如扫描头不支持则不改变) } else if (cbbScanType.SelectedIndex == 2) { SalesPoint.Device.Scan.Scanner.SetTrigger(3);//闪烁(如扫描头不支持则不改变) } cbbScanType.Update(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void brnExit_Click(object sender, EventArgs e) { this.Close(); } //清空数据 private void btnClean_Click(object sender, EventArgs e) { txtBarcode.Text = ""; scanCount = 0; lblCount.Text = "已扫描0条"; } //设置扫条提示 private void cbbHint_SelectedIndexChanged(object sender, EventArgs e) { if (cbbHint.SelectedItem.ToString() == "声音") SalesPoint.Device.Scan.Scanner._scansoundtype = ScanSoundType.Sound; else if (cbbHint.SelectedItem.ToString() == "声音加震动") { SalesPoint.Device.Scan.Scanner._scansoundtype = ScanSoundType.SoundAndMotor; } else if (cbbHint.SelectedItem.ToString() == "震动") { SalesPoint.Device.Scan.Scanner._scansoundtype = ScanSoundType.Motor; } else if (cbbHint.SelectedItem.ToString() == "无提示") { SalesPoint.Device.Scan.Scanner._scansoundtype = ScanSoundType.Closed; } } private void DeviceType1D_Click(object sender, EventArgs e) { iDeviceType = 1; //一维 DeviceType2D.Checked = false; DeviceType1D.Checked = true; cbbScanType.Enabled = true; cbbScanCode.Enabled = false; } private void DeviceType2D_Click(object sender, EventArgs e) { iDeviceType = 2; //二维 DeviceType1D.Checked = false; DeviceType2D.Checked = true; cbbScanType.Enabled = false; cbbScanCode.Enabled = true; } } } 注意:具体的开发DEMO,更多开发资料可以联系PDA导购网进行索取。 销邦X5手持终端/销邦winCE手持终端SDK请点击连接进行操作! 销邦手持终端二次开发,销邦X5手持机调用扫描头SDK,欢迎咨询PDA导购网! 商米收银机,商米手持机,商米POS机,商米双屏收银机,欢迎咨询PDA导购网! 商米安卓手持收银机POS机、商米单屏/双屏收银机、自助收银机,欢迎咨询PDA导购网 PDA导购网(www.pdadaogou.com)专业的条码手持终端、工业级PDA、RFID手持机选型导购网站! 条码手持终端、盘点机,RFID手持终端,安卓PDA选型,请联系PDA导购网免费给您推荐最合适的手持终端! 联系方式:柳工 手机(微信同号):15016095220 备注:PDA导购网销邦X5手持终端/销邦wince手持终端二次开发,扫描头调用