示例#1
0
        private void IndexWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            DateTime start = DateTime.Now;
            DateTime now   = DateTime.Now;
            TimeSpan ts    = now - start;

            while (true)
            {
                ts = now - start;
                //1秒后
                if (ts.TotalSeconds > 1)
                {
                    if (YYKeyenceReaderConsole.getForm() != null)
                    {
                        //关闭读码器
                        YYKeyenceReaderConsole.codeReaderOff();
                    }
                    break;
                }
                else
                {
                    now = DateTime.Now;
                }
            }
            if (MainWindow.getForm() != null)
            {
                //关闭录像机
                MainWindow.stopRecordVideo();
            }
        }
示例#2
0
 private void 读码器设置ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         //打开读码器设置窗体
         YYKeyenceReaderConsole.getForm().Show();
     }
     catch (Exception ex) {
         MessagePrompt.Show("打开读码器设置页面时出错,错误信息:" + ex.Message);
     }
 }
 private static void Listener_ScanerEvent(ScanerHook.ScanerCodes codes)
 {
     try
     {
         //字符串转utf-8编码
         string scanerString = codes.Result;
         //两个连续空格改一个
         scanerString = scanerString.Replace("  ", " ");
         byte[] byteArray = System.Text.Encoding.Default.GetBytes(scanerString);
         //更新扫码枪扫码数据到输入框中
         YYKeyenceReaderConsole.UpdateTextBox(ThreadingForm.getMyForm(), Encoding.UTF8.GetString(byteArray).TrimEnd());
     }
     catch (Exception ex)
     {
     }
 }
        private YYKeyenceReaderConsole()
        {
            InitializeComponent();
            this.Font = new Font("宋体", 10, FontStyle.Bold);
            //初始化客户端Socket连接读码器数组
            clientSocketInstance = new ClientSocket[READER_COUNT];
            //遍历数组时的索引
            int readerIndex = 0;
            //定义读码器发送命令的端口(默认为9003)
            int CommandPort = 9003;
            //定义读码器发送数据的端口(默认为9004)
            int DataPort = 9004;

            //设置控件值
            CommandPortInput.Text = Convert.ToString(CommandPort);
            DataPortInput.Text    = Convert.ToString(DataPort);
            try
            {
                //设置读码完成的声音文件路径
                audioFilePath = Application.StartupPath + "\\audio\\completed.wav";
                //读取本地目录config.txt文件,读出所有读码器IP地址
                string configPath = Application.StartupPath + "\\config.txt";
                string str        = File.ReadAllText(configPath);
                str = str.Replace("\n", "");
                string[] strIPArray = str.Split('\r');
                //两种方式初始化构造
                for (int i = 0; i < strIPArray.Length; i++)
                {
                    if (strIPArray[i].Length > 2)
                    {
                        //实例化客户端Socket连接读码器数组
                        clientSocketInstance[readerIndex] = new ClientSocket(strIPArray[i], CommandPort, DataPort);  // 9003 for command, 9004 for data
                        readerIndex++;
                    }
                }
            }
            catch (Exception e)
            {
                MessagePrompt.Show("实例化客户端连接读码器时错误,错误信息:" + e.Message);
            }
            finally {
                myselfForm = this;
            }
        }
示例#5
0
 private IndexWindow()
 {
     InitializeComponent();
     try
     {
         //获取模糊查询所需要的参数
         getSearchParam();
         //获取螺纹检验记录
         getThreadingProcessData();
         //设置datagridView字体
         this.dataGridView1.RowsDefaultCellStyle.Font = new Font("宋体", 18, FontStyle.Bold);
         DataGridViewCellStyle style = new DataGridViewCellStyle();
         style.Font = new Font("宋体", 18, FontStyle.Bold);
         //设置datagridView列和头部样式
         foreach (DataGridViewColumn col in this.dataGridView1.Columns)
         {
             col.HeaderCell.Style = style;
         }
         this.dataGridView1.EnableHeadersVisualStyles = false;
         myForm = this;
         //开启上传视频线程
         thread = new Thread(UploadVideo);
         thread.Start();
         thread.IsBackground = true;
     }
     catch (Exception e)
     {
         //thread.Abort();
     }
     finally {
         try
         {
             //初始化录像窗体
             MainWindow.getForm();
             //开启录像机
             if (MainWindow.recordStatus == 0)
             {
                 MainWindow.getForm().btnLogin_Click(null, null);
             }
             if (MainWindow.recordStatus == 1)
             {
                 MainWindow.getForm().btnPreview_Click_1(null, null);
             }
             //初始化读码器窗体
             YYKeyenceReaderConsole.getForm();
             //连接读码器
             if (YYKeyenceReaderConsole.readerStatus == 0)
             {
                 YYKeyenceReaderConsole.codeReaderConnect();
             }
             YYKeyenceReaderConsole.getForm().Show();
             YYKeyenceReaderConsole.getForm().Hide();
             //开启读码器,此处开启无法读码
             //if (YYKeyenceReaderConsole.readerStatus == 1)
             //    YYKeyenceReaderConsole.codeReaderLon();
             //初始化螺纹检验表单窗体
             ThreadingForm.getMyForm();
         }
         catch (Exception ex) {
             MessagePrompt.Show("初始化窗体异常,异常信息:" + ex.Message);
         }
     }
 }