seuic PDA

由于业务的需要,最近又弄了一台seuic PDA,和之前的调用方式略微不同,做个记录(侵删)

先引入要用的dll,这些一般都是由厂商提供/官网/度娘


简陋的界面

seuic PDA_第1张图片

代码实现

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
    {
        /// 
        /// 应用程序的主入口点。
        /// 
        [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;
            }
        }


        /// 
        /// 开启扫描
        /// 
        private void _OpenScan()
        {
            SeuicPDA_A8.DataArrivedEvent += new SeuicPDA_A8.DataArrivedEventHandler(mScanner_DataArrivedEvent);
            new Seuic_A8()._Open();
        }

        /// 
        /// 关闭扫描
        /// 
        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 delegateFun = new Action(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才不会报错


源代码咯







你可能感兴趣的:(其他开发记录)