国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

honeywell 1500/1300條碼槍的串口讀寫類

2019-11-17 02:34:33
字體:
供稿:網(wǎng)友

honeywell 1500/1300條碼槍的串口讀寫類

此類用于honeywell1500/1300條碼槍的串口讀寫,可實(shí)現(xiàn)控制條碼槍掃描,并從條碼槍中取得掃描的數(shù)據(jù)。使用條碼槍的串口模式有以下幾個(gè)好處:

(1)避免因文本框失去焦點(diǎn)而導(dǎo)致錄入失敗。

(2)可與自動(dòng)化設(shè)備配合。

/*----------------------------------------------------------------// 文件名:BarcodeScanner.cs// 文件功能描述:條碼掃描槍類。用于控制條碼槍進(jìn)行掃描。//// 創(chuàng)建標(biāo)識(shí):leo 2012.10.16//// 修改標(biāo)識(shí):// 修改描述://// 修改標(biāo)識(shí):// 修改描述://----------------------------------------------------------------*/using System;using System.Collections.Generic;using System.Text;using System.IO.Ports;using System.Windows.Forms;using System.Threading;using System.IO;namespace QMS.Infrastructure{    public class BarcodeScanner    {        //****************************************************** 字 段 **************************************************************************         /// <summary>        /// 串口對象。        /// </summary>        SerialPort comm = new SerialPort();        /// <summary>        /// 窗體對象。        /// </summary>        Form _frm;        //****************************************************** 屬 性 ***************************************************************************         /// <summary>        /// 返回條碼值。應(yīng)當(dāng)在條碼掃描完畢事件發(fā)生時(shí),再去取條碼值。        /// </summary>        public string Barcode        {            set;            get;        }        //*****************************************************  事 件 ***************************************************************************        /// <summary>        /// 掃描完畢事件。        /// </summary>        public event EventHandler ScanFinished;        //****************************************************** 方 法  *******************************************************************         /// <summary>        /// 打開設(shè)備。        /// </summary>        /// <param name="portName">串口號</param>        /// <param name="frm">窗體</param>        public void Open( string portName, Form frm )        {            try            {                // 初始化窗體對象                _frm = frm;                _frm.FormClosing += new FormClosingEventHandler( _frm_FormClosing );                //初始化SerialPort對象                comm.PortName = portName;                comm.BaudRate = 19200; //honeywell的是這個(gè)值                comm.Open();                comm.DataReceived += comm_DataReceived;   //添加事件注冊            }            catch( Exception e )            {                MessageBox.Show( e.Message );            }        }        /// <summary>        /// 條碼槍進(jìn)行掃描。        /// </summary>        public void Scan()        {            // 掃描超時(shí)監(jiān)視            //    tmr.Enabled = true;            // 觸發(fā)掃描            byte[] b = { 22, 84, 13 }; //十六進(jìn)制數(shù)為16 54 0d,括號中為這三個(gè)數(shù)的十進(jìn)制形式            string s = System.Text.Encoding.ASCII.GetString( b );            if( comm.IsOpen == true )            {                comm.Write( s );            }            else            {                MessageBox.Show( "無法觸發(fā)掃描槍掃描!請檢查連線或重啟程序" );            }        }        /// <summary>        /// 關(guān)閉設(shè)備。        /// </summary>        public void Close()        {            if( comm.IsOpen == true )            {                comm.Close();                comm.Dispose();            }        }        //******************************************************  內(nèi)部函數(shù)  *******************************************************************         /// <summary>        /// 串口數(shù)據(jù)接收函數(shù)。當(dāng)接收到數(shù)據(jù)時(shí),則引發(fā)ScanFinished事件。        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        void comm_DataReceived( object sender, SerialDataReceivedEventArgs e )        {            // 掃描超時(shí)監(jiān)視。數(shù)據(jù)返回,則關(guān)閉監(jiān)視            // tmr.Enabled = false;            // 讀取串口返回值            this.Barcode = comm.ReadLine().Trim();            // 引發(fā)事件             if( this.ScanFinished != null )            {                _frm.Invoke( new MethodInvoker( delegate                {                    this.ScanFinished( this, new EventArgs() );                } ) );            }        }        /// <summary>        /// 在窗體關(guān)閉的時(shí)候關(guān)閉串口連接。        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        void _frm_FormClosing( object sender, FormClosingEventArgs e )        {            this.Close();        }    }}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 陆川县| 肥西县| 富锦市| 儋州市| 固阳县| 苏州市| 南汇区| 昔阳县| 桐庐县| 松阳县| 铁力市| 子洲县| 永顺县| 余庆县| 剑川县| 滕州市| 含山县| 松溪县| 合阳县| 阿拉善右旗| 南丹县| 罗定市| 泾阳县| 阿克| 布尔津县| 临沂市| 泗洪县| 密云县| 鸡泽县| 灵台县| 巴彦淖尔市| 万宁市| 德令哈市| 永嘉县| 锡林郭勒盟| 普安县| 句容市| 樟树市| 江阴市| 阳曲县| 潼南县|