//#region 接收读码器读出的数据
        //public void Receive()
        //{
        //    try
        //    {
        //        while (true)
        //        {
        //            Byte[] recvBytes = new Byte[RECV_DATA_MAX];
        //            int recvSize = 0;
        //            //实际接收到的字节数
        //            for (int i = 0; i < READER_COUNT && clientSocketInstance[i] != null; i++)
        //            {
        //                if (clientSocketInstance[i].dataSocket != null)
        //                {
        //                    try
        //                    {
        //                        recvSize = clientSocketInstance[i].dataSocket.Receive(recvBytes);
        //                    }
        //                    catch (SocketException)
        //                    {
        //                        //
        //                        // Catch the exception, if cannot receive any data.
        //                        //
        //                        recvSize = 0;
        //                    }
        //                }
        //                else
        //                {
        //                    // MessageBox.Show(clientSocketInstance[i].readerDataEndPoint.ToString() + " is disconnected.\r\n");
        //                    continue;
        //                }

        //                if (recvSize == 0)
        //                {
        //                    //  MessageBox.Show(clientSocketInstance[i].readerDataEndPoint.ToString() + " has no data.\r\n");
        //                }
        //                else
        //                {
        //                    //
        //                    // Show the receive data after converting the receive data to Shift-JIS.
        //                    // Terminating null to handle as string.
        //                    //
        //                    recvBytes[recvSize] = 0;
        //                    SetText(Encoding.GetEncoding("Shift_JIS").GetString(recvBytes));
        //                    //this.SetText("[" + clientSocketInstance[i].readerDataEndPoint.ToString() + "] " + Encoding.GetEncoding("Shift_JIS").GetString(recvBytes) + "\r\n");

        //                    //MessageBox.Show(clientSocketInstance[i].readerDataEndPoint.ToString() + "\r\n" + Encoding.GetEncoding("Shift_JIS").GetString(recvBytes)+"\r\n");
        //                    //textbox_DataConsole.Text += clientSocketInstance[i].readerCommandEndPoint.ToString() + "LOFF sent.\r\n";
        //                    //textbox_DataConsole.Update();
        //                }
        //            }
        //            if (ACCURACY > 0)
        //                Thread.Sleep(ACCURACY);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MessagePrompt.Show("接收服务端发送的消息出错:" + ex.ToString());
        //    }


        //}
        //#endregion

        #region 接收数据读码器读出的数据
        public void codeReaderReceive()
        {
            try
            {
                while (true)
                {
                    //如果读码器尚未连接 线程暂停1秒中
                    if (readerStatus != 1)
                    {
                        Thread.Sleep(1000);
                        continue;
                    }
                    Byte[] recvBytes = new Byte[RECV_DATA_MAX];
                    int    recvSize  = 0;
                    //实际接收到的字节数
                    for (int i = 0; i < READER_COUNT && clientSocketInstance[i] != null; i++)
                    {
                        if (clientSocketInstance[i].dataSocket != null)
                        {
                            try
                            {
                                //让当前的读码器开始读取数据
                                recvSize = clientSocketInstance[i].dataSocket.Receive(recvBytes);
                            }
                            catch (SocketException ex)
                            {
                                recvSize = 0;
                            }
                        }
                        else
                        {
                            continue;
                        }
                        if (recvSize != 0)
                        {
                            recvBytes[recvSize] = 0;
                            //如果读取到的数据不是Error,则设置到指定的输入框中
                            if (!Encoding.UTF8.GetString(recvBytes).TrimEnd().Contains("ERROR"))
                            {
                                UpdateTextBox(ThreadingForm.getMyForm(), Encoding.UTF8.GetString(recvBytes).TrimEnd());
                                if (isPlayAudio)
                                {
                                    playAudio();
                                }
                            }
                            //更新读码器读出的数据到日志中
                            SetText(DateTime.Now.ToString() + "    " + Encoding.UTF8.GetString(recvBytes));
                        }
                    }
                    if (ACCURACY > 0)
                    {
                        Thread.Sleep(ACCURACY);
                    }
                }
            }
            catch (Exception ex)
            {
                SetText("读码器读数据时出错,错误信息:" + ex.ToString());
            }
        }
Beispiel #2
0
 private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         //打开螺纹检验窗体
         ThreadingForm.getMyForm().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 static void SetTextOfThreading(string text)
 {
     try
     {
         if (ThreadingForm.getMyForm().pingLbl.InvokeRequired)
         {
             SetLblTextCallbackOfThreading d = new SetLblTextCallbackOfThreading(SetTextOfThreading);
             ThreadingForm.getMyForm().pingLbl.Invoke(d, new object[] { text });
         }
         else
         {
             ThreadingForm.getMyForm().pingLbl.Text = text;
         }
     }
     catch (Exception ex)
     {
     }
 }
Beispiel #5
0
 private void button_enter_Click(object sender, EventArgs e)
 {
     try
     {
         //定义特殊的输入框名称数组(产线、用户名、密码、接箍编号、炉号、批号、机床号)
         string[] filterArr = { "txtProductionArea", "txtLoginName", "txtLoginPwd", "txtCoupingNo",
                                "txtHeatNo",         "txtBatchNo",   "txtMachineNo" };
         if (inputTxt != null)
         {
             inputTxt.Text             = Textbox_display.Text;
             this.Textbox_display.Text = "";
             //如果此时获取焦点的输入框的名称在数组中,则点击Enter后隐藏输入法
             if (filterArr.Contains(inputTxt.Name))
             {
                 Textbox_display.Focus();
                 //重置焦点
                 ThreadingForm.getMyForm().btnNone_Click(null, null);
                 this.Hide();
                 //此处是否要return??
                 return;
             }
         }
         //查询鼠标焦点所在的TextBox控件在控件集合中的索引
         TextBox tb = null; int index = 0;
         if (flag == 0)
         {
             if (ThreadingForm.flpTabOneTextBoxList != null)
             {
                 index = ThreadingForm.flpTabOneTextBoxList.IndexOf(inputTxt);
                 if (index != -1)
                 {
                     if (index < ThreadingForm.flpTabOneTextBoxList.Count - 1)
                     {
                         index++;
                     }
                     //设置鼠标焦点在控件集合索引为index的控件上
                     if (ThreadingForm.flpTabOneTextBoxList.Count > 0)
                     {
                         tb = ThreadingForm.flpTabOneTextBoxList[index];
                     }
                 }
             }
         }
         else if (flag == 1)
         {
             if (DetailForm.flpTabOneTextBoxList != null)
             {
                 index = DetailForm.flpTabOneTextBoxList.IndexOf(inputTxt);
                 if (index != -1)
                 {
                     if (index < DetailForm.flpTabOneTextBoxList.Count - 1)
                     {
                         index++;
                     }
                     //设置鼠标焦点在控件集合索引为index的控件上
                     if (DetailForm.flpTabOneTextBoxList.Count > 0)
                     {
                         tb = DetailForm.flpTabOneTextBoxList[index];
                     }
                 }
             }
         }
         if (tb != null)
         {
             tb.Focus();
         }
     }
     catch (Exception ex)
     {
     }
     finally
     {
         //清除关闭和Enter按钮的焦点,避免影响扫码枪的无意输出
         Textbox_display.Focus();
     }
 }
Beispiel #6
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);
         }
     }
 }
        public static void UpdateTextBox(Object form, string message)
        {
            try
            {
                //目前读码器读出的数据格式一般分为两种,一种时读出的量具编号,另一种时接箍编号、炉号、批号的拼接(空格拼接)
                //如果当前读码器读出的是量具编号
                if (ThreadingForm.isMeasuringToolTabSelected)
                {
                    //判断是否是跨线程访问控件
                    if (AlphabetKeyboardForm.getForm().Textbox_display.InvokeRequired)
                    {
                        UpdateTextBoxDelegate md = new UpdateTextBoxDelegate(UpdateTextBox);
                        // AlphabetKeyboardForm.getForm().Textbox_display.Invoke(md, new object[] { (object)AlphabetKeyboardForm.getForm(), message });
                        AlphabetKeyboardForm.getForm().Textbox_display.BeginInvoke(new Action(() => { AlphabetKeyboardForm.getForm().Textbox_display.Text = message; }));
                    }
                    else
                    {
                        //设置英文输入法中输入的内容为读码器读出的内容
                        AlphabetKeyboardForm.getForm().Textbox_display.Text = message;
                    }
                }
                else
                {
                    //将读码器读出的数据以空格分隔
                    string[] strArr = Regex.Split(message, "\\s+");
                    string   argHeatNo = string.Empty, argBatchNo = string.Empty, argCoupingNo = string.Empty;
                    //如果读码器读接箍内容则读出的数据格式目前如:"12323 43434 5454 5454"
                    if (strArr.Length >= 1)
                    {
                        if (strArr.Length > 3)
                        {
                            argHeatNo    = strArr[1]; //炉号
                            argBatchNo   = strArr[2]; //批号
                            argCoupingNo = strArr[3]; //接箍编号

                            //判断是否是跨线程访问控件
                            if (ThreadingForm.getMyForm().txtCoupingNo.InvokeRequired)
                            {
                                UpdateTextBoxDelegate md = new UpdateTextBoxDelegate(UpdateTextBox);
                                //设置表单上接箍编号、炉号、批号控件内容
                                if (!string.IsNullOrWhiteSpace(argCoupingNo))
                                {
                                    ThreadingForm.getMyForm().txtCoupingNo.BeginInvoke(new Action(() => { ThreadingForm.getMyForm().txtCoupingNo.Text = argCoupingNo; }));
                                }
                                //ThreadingForm.getMyForm().txtCoupingNo.Invoke(md, new object[] { ThreadingForm.getMyForm(),  argCoupingNo });
                                if (!string.IsNullOrWhiteSpace(argHeatNo))
                                {
                                    ThreadingForm.getMyForm().txtHeatNo.BeginInvoke(new Action(() => { ThreadingForm.getMyForm().txtHeatNo.Text = argHeatNo; }));
                                }
                                //ThreadingForm.getMyForm().txtHeatNo.Invoke(md, new object[] { ThreadingForm.getMyForm(), argHeatNo });
                                if (!string.IsNullOrWhiteSpace(argBatchNo))
                                {
                                    ThreadingForm.getMyForm().txtBatchNo.BeginInvoke(new Action(() => { ThreadingForm.getMyForm().txtBatchNo.Text = argBatchNo; }));
                                }
                                //ThreadingForm.getMyForm().txtBatchNo.Invoke(md, new object[] { ThreadingForm.getMyForm(),  argBatchNo });
                            }
                            else
                            {
                                //设置表单上接箍编号、炉号、批号控件内容
                                if (!string.IsNullOrWhiteSpace(argCoupingNo))
                                {
                                    ThreadingForm.getMyForm().txtCoupingNo.Text = argCoupingNo;
                                }
                                if (!string.IsNullOrWhiteSpace(argHeatNo))
                                {
                                    ThreadingForm.getMyForm().txtHeatNo.Text = argHeatNo;
                                }
                                if (!string.IsNullOrWhiteSpace(argBatchNo))
                                {
                                    ThreadingForm.getMyForm().txtBatchNo.Text = argBatchNo;
                                }
                            }
                        }
                    }
                    else//数字键盘
                    {
                        //判断是否是跨线程访问控件
                        if (NumberKeyboardForm.getForm().Textbox_display.InvokeRequired)
                        {
                            UpdateTextBoxDelegate md = new UpdateTextBoxDelegate(UpdateTextBox);
                            NumberKeyboardForm.getForm().Textbox_display.BeginInvoke(new Action(() => { NumberKeyboardForm.getForm().Textbox_display.Text = message; }));
                            //NumberKeyboardForm.getForm().Textbox_display.Invoke(md, new object[] { (object)NumberKeyboardForm.getForm(), message });
                        }
                        else
                        {
                            //设置数值输入法中输入的内容为读码器读出的内容
                            NumberKeyboardForm.getForm().Textbox_display.Text = message;
                        }

                        //设置当前焦点所在文本框内容
                        if (ThreadingForm.fpcusTxt != null)
                        {
                            if (ThreadingForm.fpcusTxt.InvokeRequired)
                            {
                                UpdateTextBoxDelegate md = new UpdateTextBoxDelegate(UpdateTextBox);
                                ThreadingForm.fpcusTxt.BeginInvoke(new Action(() => { ThreadingForm.fpcusTxt.Text = message; }));
                                //ThreadingForm.fpcusTxt.Invoke(md, new object[] { (object)ThreadingForm.getMyForm(), message });
                            }
                            else
                            {
                                //设置英文输入法中输入的内容为读码器读出的内容
                                ThreadingForm.fpcusTxt.Text = message;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }