http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 4083|回复: 2

[Winform] 读取USB数据遇到的问题

[复制链接]
发表于 2013-4-8 23:34:45 | 显示全部楼层 |阅读模式
流程:启动一个窗体程序,初始化时启动USB设备,并将当前窗体的句柄传至设备,然后在设备有数据流入时更加消息ID解析到读取到的数据
问题:启动时将句柄作为参数传递给设备后无法监听到设备的消息ID
尝试:多次插拔设备或重启设备偶尔能够获取到设备的消息ID

请教解决办法!?


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-4-9 08:01:22 | 显示全部楼层
楼主调试下看看获取的是什么,具体为什么获取不到还需要看你的代码才知道分享一部分代码上来吧
 楼主| 发表于 2013-4-9 13:58:58 | 显示全部楼层
[code=csharp]public partial class CheckTicket2WM : Form
    {
        public CheckTicket2WM()
        {
            InitializeComponent();
        }
        //设备状态
        public Boolean state = true;

        protected override void DefWndProc(ref Message msg)
        {
            Console.WriteLine("消息句柄MSG:" + msg.Msg);
            if (msg.Msg == 123)
            {
                IntPtr wp = new IntPtr((int)msg.WParam);

                byte[] wpbuf = new byte[((int)msg.LParam)];
                Marshal.Copy(wp, wpbuf, 0, ((int)msg.LParam));

                string strBC = System.Text.Encoding.GetEncoding("UTF-8").GetString(wpbuf, 0, ((int)msg.LParam));

                string result = strBC.Trim();

                this.getInfo(result);
            }
            else
            {
                base.DefWndProc(ref msg);

            }

        }
     
        private void btnRestart_Click(object sender, EventArgs e)
        {
            Dll_Camera.ReleaseDevice();
            Dll_Camera.StartDevice();
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            this.getInfo(this.txtNo.Text);
            this.txtNo.Text = "";
            this.txtNo.Focus();
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            this.txtNo.Text = "";
            this.txtNo.Focus();
        }

        private void CheckTicket2WM_Load(object sender, EventArgs e)
        {
            //通过消息得到解码信息
            Dll_Camera.GetAppHandle(this.Handle);

            this.timer1.Enabled = true;
            this.timer1.Interval = 10;
            this.timer2.Enabled = true;
            this.timer2.Interval = 10;
        }

        private void CheckTicket2WM_Closing(object sender, FormClosingEventArgs e)
        {
            DeviceUtils.releaseDevice();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int result = Dll_Camera.GetDevice();
            if (result == 1)
            {
                if (!DeviceUtils.started)
                {
                    state = true;
                    this.timer2.Enabled = true;
                    this.timer2.Interval = 10;
                    DeviceUtils.startDevice();
                }
            }
            else
            {
                state = false;
                DeviceUtils.started = false;

            }

        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            int findr =  Dll_Camera.GetDevice();

            if (findr == -1){
                DeviceUtils.started = false;
                Dll_Camera.ReleaseLostDevice();
            }


            if (!DeviceUtils.started)
            {
                this.timer2.Enabled = false;
                Dll_Camera.ReleaseDevice();
                MessageBox.Show("设备连接已断开!");
            }
        }
    }[/code]
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-17 16:16

© 2014-2021

快速回复 返回顶部 返回列表