资源简介

USB条码枪可以应用于任何程序,而串口就必须得为其单独开发,这个软件实现了对串口条码枪结果的转发,模拟按键实现。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace Scanner2Keyborad
{
    public partial class Form1 : Form
    {
        SerialPort sp;
        NotifyIcon notifyicon = new NotifyIcon();
        ContextMenu notifyContextMenu = new ContextMenu();
        MenuItem miShow = new MenuItem(“显示“);
        MenuItem miExit = new MenuItem(“退出“);

        public Form1()
        {
            InitializeComponent();
            InitUI();
        }
        private void InitUI()
        {
            sp = new SerialPort();
            //sp.ReceivedBytesThreshold = 1;
            
            notifyicon.Icon = Scanner2Keyborad.Properties.Resources.bitbug_favicon;
            notifyicon.DoubleClick += notifyicon_DoubleClick;
            miShow.Click += miShow_Click;
            miExit.Click += miExit_Click;
            notifyContextMenu.MenuItems.Add(miShow);
            notifyContextMenu.MenuItems.Add(miExit);
            notifyicon.ContextMenu = notifyContextMenu;
            cmbPort.Items.AddRange(SerialPort.GetPortNames());
            cmbParity.Items.AddRange(Enum.GetNames(typeof(System.IO.Ports.Parity)));
            cmbStopBits.Items.AddRange(Enum.GetNames(typeof(System.IO.Ports.StopBits)));
        }

        void miExit_Click(object sender EventArgs e)
        {
            this.Close();
        }

        void miShow_Click(object sender EventArgs e)
        {
            ShowForm();
        }

        void notifyicon_DoubleClick(object sender EventArgs e)
        {
            ShowForm();
        }
        void ShowForm()
        {
            if (WindowState == FormWindowState.Minimized)
            {
                //还原窗体显示 
                WindowState = FormWindowState.Normal;
                //激活窗体并给予它焦点 
                this.Activate();
                //任务栏区显示图标 
                this.ShowInTaskbar = true;
                //托盘区图标隐藏 
                notifyicon.Visible = false;
            }
        }
        void sp_DataReceived(object sender SerialDataReceivedEventArgs e)
        {
            byte[] buff=new byte[1024];
            int length = sp.BytesToRead;
            sp.Read(buff 0 length);
            byte[] data = new byte[length];
            Array.Copy(buff 0 data 0 length);
            Send(data);
        }
        void Send(byte[] data)
        {
            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] == 13)
                {
                    System.Windows.Forms.SendKeys.SendWait(“{ENTER}“);
                }
                else if (data[i] >= 32 && data[i] <= 126)
                {
                    System.Windows.Forms.SendKeys.SendWait(ASCIIEncoding.ASCII.GetString(new byte[] { data[i] }));
                }
            }
            if (cbIsEnte

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      31232  2013-10-12 13:29  Scanner2Keyborad\Scanner2Keyborad\bin\Debug\Scanner2Keyborad.exe

     文件      36352  2013-10-12 13:29  Scanner2Keyborad\Scanner2Keyborad\bin\Debug\Scanner2Keyborad.pdb

     文件      21464  2013-10-12 13:22  Scanner2Keyborad\Scanner2Keyborad\bin\Debug\Scanner2Keyborad.vshost.exe

     文件        340  2013-10-12 13:18  Scanner2Keyborad\Scanner2Keyborad\bin\Debug\system.cfg

     文件       6662  2013-10-12 13:29  Scanner2Keyborad\Scanner2Keyborad\Form1.cs

     文件      10832  2013-10-12 13:29  Scanner2Keyborad\Scanner2Keyborad\Form1.Designer.cs

     文件      12549  2013-10-12 13:29  Scanner2Keyborad\Scanner2Keyborad\Form1.resx

     文件        789  2013-10-12 09:00  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6340  2013-10-12 12:47  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        954  2013-10-12 13:29  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\Scanner2Keyborad.csproj.FileListAbsolute.txt

     文件        895  2013-10-12 13:29  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\Scanner2Keyborad.csproj.GenerateResource.Cache

     文件       1339  2013-10-12 09:05  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\Scanner2Keyborad.csprojResolveAssemblyReference.cache

     文件      31232  2013-10-12 13:29  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\Scanner2Keyborad.exe

     文件       4852  2013-10-12 13:29  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\Scanner2Keyborad.Form1.resources

     文件      36352  2013-10-12 13:29  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\Scanner2Keyborad.pdb

     文件       4860  2013-10-12 12:47  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\Scanner2Keyborad.Properties.Resources.resources

     文件       4608  2013-10-12 12:45  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件        477  2013-10-12 09:00  Scanner2Keyborad\Scanner2Keyborad\Program.cs

     文件       1370  2013-10-12 09:00  Scanner2Keyborad\Scanner2Keyborad\Properties\AssemblyInfo.cs

     文件       3272  2013-10-12 12:45  Scanner2Keyborad\Scanner2Keyborad\Properties\Resources.Designer.cs

     文件       6213  2013-10-12 12:45  Scanner2Keyborad\Scanner2Keyborad\Properties\Resources.resx

     文件       1103  2013-10-12 09:00  Scanner2Keyborad\Scanner2Keyborad\Properties\Settings.Designer.cs

     文件        249  2013-10-12 08:59  Scanner2Keyborad\Scanner2Keyborad\Properties\Settings.settings

     文件       4286  2013-10-12 12:44  Scanner2Keyborad\Scanner2Keyborad\Resources\bitbug_favicon.ico

     文件       4286  2013-10-12 12:43  Scanner2Keyborad\Scanner2Keyborad\scanner.ico

     文件       3871  2013-10-12 12:47  Scanner2Keyborad\Scanner2Keyborad\Scanner2Keyborad.csproj

     文件       2274  2013-10-12 09:46  Scanner2Keyborad\Scanner2Keyborad\SerializableHelper.cs

     文件        938  2013-10-12 09:00  Scanner2Keyborad\Scanner2Keyborad.sln

    ..A..H.     32768  2013-10-12 11:05  Scanner2Keyborad\Scanner2Keyborad.v11.suo

     目录          0  2013-10-12 12:45  Scanner2Keyborad\Scanner2Keyborad\obj\Debug\TempPE

............此处省略12个文件信息

评论

共有 条评论