Esempio n. 1
0
        //重置端口 传入PLC数据读取文件和 端口
        public void RestartConneect(DataTable dt)
        {
            DeviceShutDown();

            ConstantMethod.Delay(50);

            portParam = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);

            if (!ConstantMethod.DTFindPort())
            {
                MessageBox.Show(Constant.ConnectMachineFail);
                Application.Exit();
                System.Environment.Exit(0);
            }

            if (dataFormLst.Count > 0)
            {
                SetPlcReadDMData(dt);
            }
            if (portParam.m_portName != null)
            {
                SetComm(portParam);
            }
            CommError = 0;
        }
Esempio n. 2
0
        public easycomMangager(PortParam portparam)
        {
            SerialPort           = new SerialPortListener(portparam.m_portName, portparam.m_baudRate);
            SerialPort.PortName  = portparam.m_portName;
            SerialPort.BaudRate  = portparam.m_baudRate;
            SerialPort.DataBits  = portparam.m_dataBits;
            SerialPort.StopBits  = portparam.m_stopbits;
            SerialPort.Parity    = portparam.m_parity;
            SerialPort.Handshake = portparam.m_handshake;
            SerialPort.ReceivedBytesThreshold = portparam.m_receivedBytesThreshold;
            SerialPort.ReceiveTimeout         = portparam.m_receiveTimeout;
            SerialPort.SendInterval           = portparam.m_sendInterval;
            SerialPort.ReadBufferSize         = portparam.m_readBufferSize;

            SerialPort.OnSerialPortReceived += new OnReceivedData(XJPLC_SerialPort_Received);

            m_buffer = new List <byte>();

            ErrorConnTimer = new System.Timers.Timer(Constant.XJConnectTimeOut);  //这里0.3 秒别改 加到常量里 工控机性能不行

            ErrorConnTimer.Enabled = false;

            ErrorConnTimer.AutoReset = true;

            ErrorConnTimer.Elapsed += new System.Timers.ElapsedEventHandler(ErrorConnTimerEvent);

            ErrorConnCount = 0;

            DataProcessEventArgs = new CommEventArgs();

            openPort();
        }
Esempio n. 3
0
        void Init()
        {
            PortParam portParam = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);

            eCom = new easyCom(portParam);
            eCom.EventDataProcess += new commDataProcess(Dataprocess);
            sendHeart();
        }
Esempio n. 4
0
        /// <summary>
        /// 设置端口 传入串口数据
        /// 如果以后要重新连接 或者更改串口了 可以使用这个函数
        /// </summary>
        /// <param name="portParam0"></param>
        public void SetComm(PortParam portParam0)
        {
            if (comManager != null)
            {
                comManager.DeviceClear();
                comManager = null;
            }

            portParam = portParam0;


            comManager = new XJCommManager(portParam);
            //设置数据处理委托事件
            comManager.EventDataProcess += new xjplc.commDataProcess(Dataprocess);

            //命令打包类重新确认
            comManager.SetXJPLCcmd(XJPLCcmd);
        }
Esempio n. 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            PortParam p = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);

            device.RestartConneect(device.DataFormLst[0]);

            if (device.getDeviceData())
            {
                ConstantMethod.ShowInfo(rtbResult, "成功 ");
                //device.StartUpdateUI();
            }
            else
            {
                ConstantMethod.ShowInfo(rtbResult, "连接设备失败! ");
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Esempio n. 6
0
        //复位所有状态位和缓冲
        //复位之后假定 硬件端口不会变化,那端口不会关闭
        //
        public void DeviceClear()
        {
            //ConstantMethod.XJFindPort(1);
            PortParam
                portParam0 = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);

            m_SerialPort.PortName = portParam0.m_portName;

            ErrorConnCount         = 0;
            ErrorConnTimer.Enabled = false;
            isDeviceReady          = false;
            isGoToGetData          = false;
            isWriteCmd             = false;
            status = false;

            m_buffer.Clear();
            ConstantMethod.Delay(50);
            closePort();
        }
Esempio n. 7
0
        /// <summary>
        /// 设置端口 传入串口数据
        /// 如果以后要重新连接 或者更改串口了 可以使用这个函数
        /// </summary>
        /// <param name="portParam0"></param>
        public void SetComm(PortParam portParam0)
        {
            if (comManager != null)
            {
                comManager.Reset();
                comManager = null;
            }

            portParam = portParam0;


            comManager = new DTCommManager(portParam);
            //设置数据处理委托事件
            comManager.EventDataProcess += new xjplc.commDataProcess(Dataprocess);

            //命令打包类重新确认
            comManager.SetDTPLCcmd(DTPLCcmd);

            //GC.Collect();
            //GC.WaitForPendingFinalizers();
        }
Esempio n. 8
0
        public XJDevice(List <string> filestr, PortParam p0)
        {
            IsCommSet   = true;
            XJPLCcmd    = new XJPLCPackCmdAndDataUnpack();
            DataFormLst = new List <DataTable>();
            CSVData     = new CsvStreamReader();
            dgShowLst   = new List <DataGridView>();

            //获取监控数据 dataformLst 填充
            GetPlcDataTableFromFile(filestr);

            //找一下串口 不存在就报错 退出
            portParam = p0;// ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);

            if (!SerialPort.GetPortNames().Contains(portParam.m_portName))
            {
                MessageBox.Show(Constant.NoSerialPort + portParam.m_portName);
                ConstantMethod.AppExit();
            }

            //监控第一个列表数据 考虑下 这个还要不要 因为已经有一个 shift在后面了
            if (dataFormLst.Count > 0)
            {
                SetPlcReadDMData(dataFormLst[0]);
            }

            //设置端口
            SetComm(p0);

            //监控通讯
            WatchCommTimer = new System.Timers.Timer(Constant.XJRestartTimeOut);  //这里1.5 秒别改 加到常量里 工控机性能不行

            WatchCommTimer.Enabled = false;

            WatchCommTimer.AutoReset = true;

            WatchCommTimer.Elapsed += new System.Timers.ElapsedEventHandler(WatchTimerEvent);
        }
Esempio n. 9
0
        private void test()
        {
            portparam = new PortParam();

            if (!ConstantMethod.XJFindPort(1))
            {
                MessageBox.Show(Constant.ConnectMachineFail);
                Application.Exit();
            }

            portparam = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);

            device = new XJDevice(strDataFormPath);

            if (device.DataFormLst.Count > 0)
            {
                dgv.DataSource = device.DataFormLst[0];

                dataGridView2.DataSource = device.DataFormLst[1];

                dataGridView3.DataSource = device.DataFormLst[2];
                //dgvIO.DataSource = evokDevice.DataFormLst[2];
            }
            //device.SetShowDataGridView(dgv);
            //获取其他监控窗口的数据
            // device.GetPlcDataTableFromFile(strDataFormPath);

            if (device.getDeviceData())
            {
                ConstantMethod.ShowInfo(rtbResult, "成功 ");
                // device.StartUpdateUI();
            }
            else
            {
                ConstantMethod.ShowInfo(rtbResult, "连接设备失败! ");
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 针对信捷PLC 进行设备的存在获取
        /// </summary>
        /// <returns></returns>


        public XJDevice(List <string> filestr)
        {
            XJPLCcmd    = new XJPLCPackCmdAndDataUnpack();
            DataFormLst = new List <DataTable>();
            CSVData     = new CsvStreamReader();
            dgShowLst   = new List <DataGridView>();

            //获取监控数据 dataformLst 填充
            GetPlcDataTableFromFile(filestr);

            //找一下串口 不存在就报错 退出
            if (!ConstantMethod.XJFindPort(1))
            {
                MessageBox.Show(DeviceId + Constant.ConnectMachineFail);
                //报错 在外面调试 需要隐藏
                //ConstantMethod.AppExit();
            }

            portParam = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);

            //监控第一个列表数据 考虑下 这个还要不要 因为已经有一个 shift在后面了
            if (dataFormLst.Count > 0)
            {
                SetPlcReadDMData(dataFormLst[0]);
            }

            //设置端口
            SetComm(portParam);

            //监控通讯
            WatchCommTimer = new System.Timers.Timer(Constant.XJRestartTimeOut);  //这里1.5 秒别改 加到常量里 工控机性能不行


            WatchCommTimer.AutoReset = true;

            WatchCommTimer.Elapsed += new System.Timers.ElapsedEventHandler(WatchTimerEvent);
        }
Esempio n. 11
0
        void Init(List <string> filestr)
        {
            DataFormLst = new List <DataTable>();
            CSVData     = new CsvStreamReader();
            dgShowLst   = new List <DataGridView>();

            //获取监控数据 dataformLst 填充
            GetPlcDataTableFromFile(filestr);

            //找一下串口 不存在就报错 退出
            if (!ConstantMethod.DTFindPort())
            {
                MessageBox.Show(Constant.ConnectMachineFail);
                System.Environment.Exit(0);
            }

            portParam = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);

            //监控第一个列表数据
            if (dataFormLst.Count > 0)
            {
                SetPlcReadDMData(dataFormLst[0]);
            }

            //设置端口
            SetComm(portParam);

            //监控通讯
            WatchCommTimer = new System.Timers.Timer(Constant.XJRestartTimeOut);  //这里1.5 秒别改 加到常量里 工控机性能不行

            //测试先隐藏
            WatchCommTimer.Enabled = false;

            WatchCommTimer.AutoReset = true;

            WatchCommTimer.Elapsed += new System.Timers.ElapsedEventHandler(WatchTimerEvent);
        }
Esempio n. 12
0
        bool findPort()
        {
            SerialPort m_serialPort = new SerialPort();

            string[] str = SerialPort.GetPortNames();

            List <string> portNameLst = new List <string>();
            PortParam     portparam0  = new PortParam();


            portparam0 = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);
            ConstantMethod.fileCopy(Constant.ConfigSerialportFilePath, Constant.ConfigSerialportFilePath_bak);

            for (int i = 0; i < (str.Length + 1); i++)
            {
                try
                {
                    if (i == 0)
                    {
                        m_serialPort.PortName = portparam0.m_portName;
                    }
                    else
                    {
                        if (!str[i - 1].Equals(portparam0.m_portName))
                        {
                            m_serialPort.PortName = str[i - 1];
                        }
                        else
                        {
                            continue;
                        }
                    }
                    m_serialPort.BaudRate        = portparam0.m_baudRate;
                    m_serialPort.Parity          = portparam0.m_parity;
                    m_serialPort.StopBits        = portparam0.m_stopbits;
                    m_serialPort.Handshake       = portparam0.m_handshake;
                    m_serialPort.DataBits        = portparam0.m_dataBits;
                    m_serialPort.ReadBufferSize  = 1024;
                    m_serialPort.WriteBufferSize = 1024;
                    m_serialPort.ReadTimeout     = 100;
                    if (!m_serialPort.IsOpen)
                    {
                        m_serialPort.Open();
                    }
                    byte[] resultByte = new byte[Constant.XJExistByteIn.Count()];

                    m_serialPort.Write(Constant.XJExistByteOut, 0, Constant.XJExistByteOut.Length);

                    ConstantMethod.Delay(200);

                    m_serialPort.Read(resultByte, 0, Constant.XJExistByteIn.Count());

                    if (ConstantMethod.compareByteStrictly(resultByte, Constant.XJExistByteIn))
                    {
                        //rtbResult.AppendText("连接成功" + m_serialPort.PortName);
                        ConstantMethod.SetPortParam(Constant.ConfigSerialportFilePath, Constant.PortName, m_serialPort.PortName);
                        return(true);
                    }
                }
                catch
                {
                    //rtbResult.AppendText("连接失败" + m_serialPort.PortName);
                    //throw new SerialPortException(
                    //string.Format("无法打开串口:{0}", m_serialPort.PortName));
                    //continue;
                }
                finally { m_serialPort.Close(); };
            }

            return(false);
        }
Esempio n. 13
0
        public void Init()
        {
            PortParam p0 = new PortParam();
            PortParam p1 = new PortParam();
            PortParam p2 = new PortParam();

            p0 = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);
            p1 = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath1);
            p2 = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath2);

            //初始化设备
            List <string> strDataFormPath0 = new List <string>();

            strDataFormPath0.Add(Constant.PlcDataFilePathAuto);
            strDataFormPath0.Add(Constant.PlcDataFilePathHand);
            strDataFormPath0.Add(Constant.PlcDataFilePathParam);
            strDataFormPath0.Add(Constant.PlcDataFilePathIO);

            List <string> strDataFormPath1 = new List <string>();

            strDataFormPath1.Add(Constant.PlcDataFilePathAuto1);
            strDataFormPath1.Add(Constant.PlcDataFilePathHand1);
            strDataFormPath1.Add(Constant.PlcDataFilePathParam1);
            strDataFormPath1.Add(Constant.PlcDataFilePathIO1);

            List <string> strDataFormPath2 = new List <string>();

            strDataFormPath2.Add(Constant.PlcDataFilePathAuto2);
            strDataFormPath2.Add(Constant.PlcDataFilePathHand2);
            strDataFormPath2.Add(Constant.PlcDataFilePathParam2);
            strDataFormPath2.Add(Constant.PlcDataFilePathIO2);

            csvop   = new CsvStreamReader();
            optsize = new OptSize();
            op0     = new OptSize();
            op1     = new OptSize();
            op2     = new OptSize();
            if (propertyA)
            {
                evokWork0 = new EvokXJWork(strDataFormPath0, p0);
            }

            if (propertyB)
            {
                evokWork1 = new EvokXJWork(strDataFormPath1, p1);
            }

            if (propertyC)
            {
                evokWork2 = new EvokXJWork(strDataFormPath2, p2);
            }


            InitWork();

            UpdateTimer.Enabled = true;

            doorLst = new doorTypeInfo();

            workMan = new workManager();
        }
Esempio n. 14
0
 public EvokXJDevice(List <string> strfile, PortParam p0) : base(strfile, p0)
 {
 }
Esempio n. 15
0
        public void Init()
        {
            PortParam p0 = new PortParam();
            PortParam p1 = new PortParam();
            PortParam p2 = new PortParam();

            p0 = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath);
            p1 = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath1);
            p2 = ConstantMethod.LoadPortParam(Constant.ConfigSerialportFilePath2);

            //初始化设备
            List <string> strDataFormPath0 = new List <string>();

            strDataFormPath0.Add(Constant.PlcDataFilePathAuto);
            strDataFormPath0.Add(Constant.PlcDataFilePathHand);
            strDataFormPath0.Add(Constant.PlcDataFilePathParam);
            strDataFormPath0.Add(Constant.PlcDataFilePathIO);

            List <string> strDataFormPath1 = new List <string>();

            strDataFormPath1.Add(Constant.PlcDataFilePathAuto1);
            strDataFormPath1.Add(Constant.PlcDataFilePathHand1);
            strDataFormPath1.Add(Constant.PlcDataFilePathParam1);
            strDataFormPath1.Add(Constant.PlcDataFilePathIO1);

            List <string> strDataFormPath2 = new List <string>();

            strDataFormPath2.Add(Constant.PlcDataFilePathAuto2);
            strDataFormPath2.Add(Constant.PlcDataFilePathHand2);
            strDataFormPath2.Add(Constant.PlcDataFilePathParam2);
            strDataFormPath2.Add(Constant.PlcDataFilePathIO2);

            csvop       = new CsvStreamReader();
            opXiaLiao   = new OptSize();
            opDoorShell = new OptSize();
            opDoorBan   = new OptSize();
            if (propertyA)
            {
                evokWork0 = new EvokXJWork(strDataFormPath0, p0);
            }

            if (propertyB)
            {
                evokWork1 = new EvokXJWork(strDataFormPath1, p1);
            }

            if (propertyC)
            {
                evokWork2 = new EvokXJWork(strDataFormPath2, p2);
            }

            InitWork();

            UpdateTimer.Enabled = true;


            doorLst = new doorTypeInfo();

            workMan = new workManager();

            LoadData(dgSize, Constant.DoorSizeFile);
            LoadData(dgDoorBan, Constant.DoorBanFile);
            LoadData(dgDoorShell, Constant.DoorShellFile);

            startDevice = startClick;

            rtbResult.Text    = "门芯板信息";
            richTextBox7.Text = "下料锯信息";
            richTextBox8.Text = "门皮信息";
        }