Example #1
0
        public Reader()
        {
            InitializeComponent();
            ButtonProperty.SetProperty(btnRead, true);
            ButtonProperty.SetProperty(btnReadWrite, true);
            if (GlobalParameter.UseMode.Equals("1"))
            {
                #region 測試後不用要刪除

                PLCMethod.PLC_Connect();
                Thread.Sleep(1000);

                #endregion 測試後不用要刪除

                // PLC連線、條碼讀取器連線
                try
                {
                    if (!GlobalData.PLC初始連線是否成功)
                    {
                        MessageBox.Show("PLC連線失敗:請檢查PLC連線IP、機台是否異常。"); return;
                    }
                    if (!GlobalData.PLC線路異常)
                    {
                        ThreadPool.QueueUserWorkItem(DM8120讀取2D碼執行緒);
                    }
                    else
                    {
                        MessageBox.Show("PLC線路異常。"); return;
                    }

                    bool check = LiveviewFormProperty.ReadConnect(liveviewForm1, readerAccessor, GlobalParameter.ReadIP);
                    if (!check)
                    {
                        MessageBox.Show("條碼讀取器連線異常。"); return;
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Exception錯誤");
                    MessageBox.Show("Exception錯誤:" + ex.Message);
                    return;
                }

                // Hoioke機台連線
                try
                {
                    IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(GlobalParameter.HiokiIP), 32006);
                    this.socket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                    Thread tread = new Thread(new ThreadStart(CheckSocketConnect));
                    tread.Start();
                    this.socket.Connect(ipe);
                }
                catch (Exception)
                {
                    MessageBox.Show("Hiorki連線: Hiorki機台連線異常,請檢查IP位置或網路線路是否異常。");
                }
            }
        }
Example #2
0
        public FormStart()
        {
            InitializeComponent();
            SetDefultEvent();

            // 條碼讀取器,預設顯示還是不顯示
            label3.Visible = lblCCD.Visible = liveviewForm1.Visible = false;
            ToolStripMenuItemSW(false, "FormStart");
            DefultListViewInit();
            ThreadPool.QueueUserWorkItem(日期時間執行緒);
            if (GlobalParameter.UseMode.Equals("1"))
            {
                // PLC連線
                PLCMethod.PLC_Connect();
                Thread.Sleep(1000);
                if (GlobalData.PLC初始連線是否成功)
                {
                    ThreadPool.QueueUserWorkItem(警示燈執行緒);
                }
                else
                {
                    MessageBox.Show("PLC連線失敗:請檢查PLC連線IP、機台是否異常。"); return;
                }

                // 雷射功能連線
                try
                {
                    SerialPortMethod.LaserOpenPort(GlobalParameter.LaserSerialPort);
                    if (LaserConnectionPort.LaserPort.IsOpen)
                    {
                        ModelSTS modelSTS = LaserExecuteWrite.執行STS狀態請求讀取(LaserCommand.STS狀態請求讀取);
                        formStartModel.LSR雷射狀態 = modelSTS.LSRStatus; formStartModel.SHT遮光閥狀態 = modelSTS.SHTStatus;
                        DefultLaserControll();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("請檢查雷射是否斷線、未開機、未開啟REMOTE。" + ex.Message);
                    return;
                }

                // 條碼讀取器連線
                try
                {
                    bool check = LiveviewFormProperty.ReadConnect(liveviewForm1, readerAccessor, GlobalParameter.ReadIP);
                    if (!check)
                    {
                        MessageBox.Show("條碼讀取器連線異常、請確認IP位置。");
                        return;
                    }
                    label3.Visible = lblCCD.Visible = liveviewForm1.Visible = true;
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Exception錯誤");
                    MessageBox.Show("Exception錯誤:" + ex.Message);
                    return;
                }

                // Hoioke機台連線
                try
                {
                    IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(GlobalParameter.HiokiIP), 32006);
                    this.socket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                    Thread tread = new Thread(new ThreadStart(CheckSocketConnect));
                    tread.Start();
                    this.socket.Connect(ipe);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Hiorki連線: Hiorki機台連線異常,請檢查IP位置或網路線路是否異常。" + ex.Message);
                }
            }
        }