示例#1
0
 private void CChaSetting_Load(object sender, EventArgs e)
 {
     try
     {
         plc = new PLCController(getPort());
         if (!plc.Connect())
         {
             MessageBox.Show("连接PLC设备失败!", "错误");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
示例#2
0
 void closeMachine()
 {
     try
     {
         PLCController plc = new PLCController(getPort());
         if (plc.Connect())
         {
             plc.SendCommand((PLCResponse)6);
             plc.Disconnect();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
示例#3
0
        public bool connect()
        {
            bool re = false;

            try
            {
                if (mPLCType == PLC_TYPE.PLC_BJ)
                {
                    mModbus = new CModbusRtuBasePLC();
                    if (mModbus.OpenPort(CConfig.mPLCComPort))
                    {
                        //软件准备
                        mModbus.WriteDO(5, false);
                        Thread.Sleep(500);
                        byte[] a = mModbus.ReadDIs();
                        if (a == null || a[4] == 0)
                        {
                        }
                        else
                        {
                            //软件启动
                            mModbus.WriteDO(3, true);
                            Thread th = new Thread(GetDIStatus);
                            th.IsBackground = true;
                            th.Start();
                            re = true;
                        }
                    }
                }
                if (mPLCType == PLC_TYPE.PLC_XD || mPLCType == PLC_TYPE.PLC_DLX)
                {
                    mPlc = new PLCController(CConfig.mPLCComPort);
                    mPlc.OnPLCDataReported += Plc_OnPLCDataReported;
                    re = mPlc.Connect();
                }
            }
            catch (Exception)
            {
                re = false;
            }
            return(re);
        }
示例#4
0
 public virtual bool ConnectPlc()
 {
     plc.OnPLCDataReported += Plc_OnPLCDataReported;
     return(plc.Connect());
 }