由于业务的需要,最近又弄了一台seuic PDA,和之前的调用方式略微不同,做个记录(侵删)
先引入要用的dll,这些一般都是由厂商提供/官网/度娘
简陋的界面
代码实现
Program.cs
using System;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
using SeuicSCAN;
namespace DDSmartDevice
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[MTAThread]
static void Main()
{
if (!SeuicPDA_A8.Init())
{
MessageBox.Show("条码端口初始化失败!");
Application.Exit();
}
else
{
try
{
SeuicPDA_A8.BeeperEnable(false);
Application.Run(new Form1());
Process.GetCurrentProcess().Kill();
}
catch (Exception E)
{
// TODO: 根据实际情况处理这个异常
MessageBox.Show(E.Message, "Exception");
}
}
}
}
}扫描界面的代码
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SeuicSCAN;
namespace DDSmartDevice
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
_OpenScan();
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 开启扫描
/// </summary>
private void _OpenScan()
{
SeuicPDA_A8.DataArrivedEvent += new SeuicPDA_A8.DataArrivedEventHandler(mScanner_DataArrivedEvent);
new Seuic_A8()._Open();
}
/// <summary>
/// 关闭扫描
/// </summary>
private void _CloseScan()
{
SeuicPDA_A8.DataArrivedEvent -= new SeuicPDA_A8.DataArrivedEventHandler(mScanner_DataArrivedEvent);
new Seuic_A8()._Close();
}
private void mScanner_DataArrivedEvent(string code)
{
try
{
code = code.Trim();
//把线程转到主窗体
if (this.InvokeRequired)
{
Action<string> delegateFun = new Action<string>(mScanner_DataArrivedEvent);
this.Invoke(delegateFun, code);
}
label1.Text = code;
}
catch (Exception ex)
{
if (ex is System.NotSupportedException)
{
//忽略线程安全错误(这里每次扫描都会这样,也不知道为什么了,不知是否厂商提供sdk的有问题)
}
else
{
MessageBox.Show("[扫描条码]出错!原因:" + ex.Message);
};
}
}
private void Fram_closed(object sender, EventArgs e)
{
_CloseScan();
}
}
}最后还要在pda内的那个文件里面加入这个dll才不会报错
版权声明:本文为qq_22056455原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。