コード例 #1
0
ファイル: ConnectPLC.cs プロジェクト: wjy192787/learning
        public void connectPLC()
        {
            int iReturnCode;                    //Return code
            int iLogicalStationNumber = 1;      //LogicalStationNumber for ActUtlType

            //
            //Processing of Open method
            //
            try
            {
                //Set the value of 'LogicalStationNumber' to the property.
                lpcom_ReferencesUtlType.ActLogicalStationNumber = iLogicalStationNumber;

                ////Set the value of 'Password'.
                //lpcom_ReferencesUtlType.ActPassword = txt_Password.Text;

                //The Open method is executed.
                iReturnCode = lpcom_ReferencesUtlType.Open();
                //}
                //When the Open method is succeeded, disable the TextBox of 'LogocalStationNumber'.
                if (iReturnCode == 0)
                {
                    isPLCConnected = true;
                    Thread PLC_Thread = new Thread(new ThreadStart(PLC_MONITOR));
                    PLC_Thread.IsBackground = true;
                    PLC_Thread.Start();
                }
                //The return code of the method is displayed by the hexadecimal.
            }
            //Exception processing
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        public void PLCOpen()
        {
            int iReturnCode;                //Return code

            //LogicalStationNumber for ActUtlType

            //
            //Processing of Open method
            //
            try
            {
                //Form_menu.StatusPLCLog("Open PLC Connection");
                StatusPLCLog = "Open PLC Connection";
                //Check the 'LogicalStationNumber'.(If succeeded, the value is gotten.)
                if (GetLogicalStationNumber(out int iLogicalStationNumber) != true)
                {
                    //If failed, this process is end.
                    return;
                }

                //Set the value of 'LogicalStationNumber' to the property.
                plc.ActLogicalStationNumber = iLogicalStationNumber;

                //Set the value of 'Password'.
                //plc.ActPassword = txt_Password.Text;

                //The Open method is executed.
                iReturnCode = plc.Open();

                //When the Open method is succeeded, set the connected status.
                if (iReturnCode == 0)
                {
                    Connected = true;
                    //Form_menu.StatusPLCLog("Open PLC Connection Succeed");
                    StatusPLCLog = "Open PLC Connection Succeed";
                    //ButtonSendingStatus(true);
                }
                else
                {
                    Connected = false;
                    //Form_menu.StatusPLCLog("Open PLC Connection Failed");
                    StatusPLCLog = "Open PLC Connection Failed";
                    //ButtonSendingStatus(false);
                }
                _plcConnectionStatus = iReturnCode;
            }
            //Exception processing
            catch (Exception exception)
            {
                Debug.WriteLine(exception.Message);
                //MessageBox.Show(exception.Message,
                //                  "Open Method", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }