Example #1
0
        private void But_Dis_Click(object sender, EventArgs e)
        {
            plc.Close();
            timer1.Stop();
            But_Connect.BackColor = Color.White;
            But_Dis.BackColor     = Color.Red;
            plcStat = false;

            lblX0.BackColor = Color.White;
            lblX1.BackColor = Color.White;
            lblX2.BackColor = Color.White;
            lblX3.BackColor = Color.White;
            lblX4.BackColor = Color.White;
            lblX5.BackColor = Color.White;
            lblX6.BackColor = Color.White;
            lblX7.BackColor = Color.White;
            lblY7.BackColor = Color.White;
            lblY0.BackColor = Color.White;
            lblY1.BackColor = Color.White;
            lblY2.BackColor = Color.White;
            lblY3.BackColor = Color.White;
            lblY4.BackColor = Color.White;
            lblY5.BackColor = Color.White;
            lblY6.BackColor = Color.White;
            lblY7.BackColor = Color.White;
        }
        /// <summary>
        /// モニタ終了ボタンクリック
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EndButton_Click(object sender, EventArgs e)
        {
            int ret;    //コントロールのメソッドの戻り値

            //結果表示の消去
            ClearDisplay();

            try {
                //Close関数処理の実行
                ret = ActUtlType.Close();
                ShowMessage(ret);
                if (ret != SUCCESS)
                {
                    return;
                }
                //Closeが成功した場合、LogicalStationNumberテキストボックスを有効にする。
                LogicalStationNumberText.Enabled   = true;
                this.LogicalStationNumberText.Text = "";
                CPUTypeText.Text = "";
                this.C0Text.Text = "";
                this.Y3Text.Text = "";

                this.Timer.Enabled = false;
            } catch (Exception exception) {
                MessageBox.Show(exception.Message, Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
 public bool ClosePLC()
 {
     lock (this)
     {
         try
         {
             if (_isOpen == false)
             {
                 return(true);
             }
             int result = actUtlType.Close();
             if (result != 0)
             {
                 message = "PLC关闭失败,错误代码:" + (uint)result;
                 return(false);
             }
             else
             {
                 _isOpen = false;
                 message = "PLC关闭成功";
                 return(true);
             }
         }
         catch (Exception ex)
         {
             _isOpen = true;
             message = "error:\n" + ex.Message;
             return(false);
         }
     }
 }
Example #4
0
        public void Disconnect()
        {
            int returncode;

            returncode = plc.Close();
            if (returncode == 0)
            {
                isConnected = false;
            }
        }
Example #5
0
 /// <summary>
 /// Đóng các Thread khi tắt chương trình
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void FMain_FormClosed(object sender, FormClosedEventArgs e)
 {
     plcThread.Abort();
     try { dataThread.Abort(); } catch { }
     plcFX3G.Close();
 }
Example #6
0
 private void Button3_Click(object sender, EventArgs e)
 {
     plc.Close();
 }
Example #7
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     Fx1s.Close();
     _cameraMV.DisconnectAll();
 }
Example #8
0
        /// <summary>
        /// main   collecting workTime from PLC and  insert into DataBase
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // create ActUtlType object
            ActUtlType actUtlType = new ActUtlType();

            // logicalStationNumbet
            actUtlType.ActLogicalStationNumber = 1;
            // not set password, is null
            actUtlType.ActPassword = "";
            //List<string> workTime = new List<string>();
            Dictionary <int, int[]> beforeDict = null;

            for (int i = 1; i <= 1; i++)
            {
                beforeDict = InitStartDataTime(i, actUtlType);
            }

            while (true)

            {
                try
                {
                    int iReturnCode = actUtlType.Open();
                    if (iReturnCode == 0)

                    {
                        //  Set value of i  based on the quantity of seats
                        for (int i = 1; i <= 1; i++)
                        {
                            Int16  lineNumber    = GetLineNumber(actUtlType);
                            Int16  seatNumber    = GetSeatNumber(i, actUtlType);
                            string startDateTime = GetStartDateTime(i, actUtlType);
                            string endDateTime   = GetEndDateTime(i, actUtlType);
                            int    workTime      = GetWorkTime(i, actUtlType);
                            bool   isSensorExist = CheckSensorIsExist(i, actUtlType);
                            Dictionary <int, int[]> currentDict = CurrentStartDataTime(i, actUtlType);

                            if (workTime <= 0 || workTime > 3600)
                            {
                                continue;
                            }
                            if (beforeDict[i].All(currentDict[i].Contains) && (beforeDict[i].Count() == currentDict[i].Count()))
                            {
                                continue;
                            }
                            ExcueteInsertToSqlServer(lineNumber, seatNumber, startDateTime, endDateTime, workTime, isSensorExist);
                            beforeDict[i] = currentDict[i];
                        }


                        actUtlType.Close();
                        //System.Threading.Thread.Sleep(1000);  // sleep  1s
                    }

                    else

                    {
                        Console.WriteLine("PLC connecting  fail! please check wire and reconnecting");
                    }
                }
                catch (Exception ex)

                {
                    Console.WriteLine(ex.ToString());
                    Console.ReadKey();
                }
            }
        }
Example #9
0
 public void disconnect()
 {
     plc.Close();
 }