コード例 #1
0
ファイル: WorkForm.cs プロジェクト: w7789475/EVOK
        private void startOptShow()
        {
            stbtn.Enabled       = false;
            loadDataBtn.Enabled = false;
            optBtn.Enabled      = false;
            button10.Enabled    = false;
            qClr.Enabled        = false;
            autoSLBtn.Enabled   = false;
            ccBtn.Enabled       = false;
            UserData.ReadOnly   = true;
            stopBtn.Enabled     = false;
            pauseBtn.Enabled    = false;
            resetBtn.Enabled    = false;
            printcb.Enabled     = false;
            if (rtbResult != null)
            {
                rtbResult.Clear();
            }
            ConstantMethod.ShowInfo(rtbResult, Constant.InOPT);

            设备ToolStripMenuItem.Enabled = false;
        }
コード例 #2
0
 public bool SetMultiPleDValue(DTPlcInfoSimple stDTPlcInfoSimple, int[] value0)
 {
     if (stDTPlcInfoSimple != null && stDTPlcInfoSimple.BelongToDataform != null)
     {
         WriteMultiPleDMData(
             stDTPlcInfoSimple.Addr,
             value0,
             stDTPlcInfoSimple.Area,
             stDTPlcInfoSimple.Mode);
         ConstantMethod.DelayWriteCmdOk(Constant.WriteCommTimeOut, ref value0[0], ref stDTPlcInfoSimple);
         //可能时间太久 要等下
         if (value0[0] == stDTPlcInfoSimple.ShowValue)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
コード例 #3
0
 public void GetPlcDataTableFromFile(List <string> strfile)
 {
     if (strfile != null && strfile.Count > 0)
     {
         foreach (string s in strfile)
         {
             if (ConstantMethod.FileIsUsed(s))
             {
                 MessageBox.Show(Constant.FileIsInUse);
                 ConstantMethod.AppExit();
             }
             if (File.Exists(s) && (Path.GetExtension(s).Equals(Constant.CSVFileEX)))
             {
                 CSVData.FileName = s;
             }
             //确认表格 //这个要隔离出来 方便以后可以单独调用 针对用户更改读取内容
             if (CSVData.CheckCSVFile(Constant.PLCstrCol))
             {
                 DataTable dataForm0 = new DataTable();
                 dataForm0 = CSVData.OpenCSV(CSVData.FileName);
                 if (dataForm0 != null && dataForm0.Rows.Count > 0)
                 {
                     DataFormLst.Add(dataForm0);
                 }
                 else
                 {
                     MessageBox.Show(Constant.ReadPlcInfoFail);
                     ConstantMethod.AppExit();
                 }
             }
             else
             {
                 MessageBox.Show(Constant.ReadPlcInfoFail);
                 Application.Exit();
                 System.Environment.Exit(0);
             }
         }
     }
 }
コード例 #4
0
ファイル: SocServerManger.cs プロジェクト: w7789475/EVOK
        public bool ConnectMachine()
        {
            for (int i = 0; i < 3; i++)
            {
                if (Status)
                {
                    SetCmdOutIn(Constant.DTExistByteOutIn, Constant.DTExistByteOutIn);
                    SendMsgByte(DTPLCcmd.CmdOut.ToArray());
                    ConstantMethod.Delay(Constant.ReadSocTimeOut, ref isDeviceReady);

                    if (IsDeviceReady)
                    {
                        ErrorConnTimer.Enabled = true;
                        //设备准好后
                        // IsSetReadDDataOut = true;
                        break;
                    }
                }
            }

            return(IsDeviceReady);
        }
コード例 #5
0
ファイル: XJDevice.cs プロジェクト: w7789475/EVOK
        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);
        }
コード例 #6
0
ファイル: DTCommManager.cs プロジェクト: w7789475/EVOK
        /// <summary>
        /// 连接PLC 步骤: 打开串口 发送设备是否存在命令
        /// </summary>
        /// <returns></returns>
        public bool ConnectMachine()
        {
            Reset();

            //目前只是打开窗口 后续要增加打开串口后 返回协议 是否正确
            openPort();

            //询问设备是否存在 收到的数据 变成 回复的长度
            for (int i = 0; i < 3; i++)
            {
                if (status)
                {
                    SetCmdOutIn(Constant.DTExistByteOutIn, Constant.DTExistByteOutIn);

                    //这里要进行几个步骤的操作
                    //第一发送存在的命令码
                    //第二发送设置的命令码
                    //等待连接 约300秒

                    m_SerialPortListener.Send(DTPLCcmd.CmdOut.ToArray());

                    ConstantMethod.Delay(Constant.ReadCommTimeOut, ref isDeviceReady);

                    if (isDeviceReady)
                    {
                        //设备准好后
                        IsSetReadDDataOut = true;
                        //测试先隐藏
                        ErrorConnTimer.Enabled = true;
                        break;
                    }
                }
            }

            m_buffer.Clear();

            return(isDeviceReady);
        }
コード例 #7
0
        public void InitParam()
        {
            //datasource 改变会出发 selectindex 改变事件  这样就会打条码导致 模式被自动修改
            //所以早点设置好 然后在 那个selectindexchanged事件里增加 通讯正常判断
            // printcb.DataSource = Constant.printBarcodeModeStr;
            printcb.Items.AddRange(Constant.printBarcodeModeStr);
            LogManager.WriteProgramLog(Constant.ConnectMachineSuccess);
            evokWork          = ConstantMethod.GetWork();
            evokWork.MainForm = this;
            evokWork.SetUserDataGridView(UserData);
            evokWork.SetRtbWork(rtbWork);
            evokWork.SetRtbResult(rtbResult);
            evokWork.SetPrintReport();
            evokWork.InitDgvParam(dgvParam);
            evokWork.InitDgvIO(dgvIO);
            evokWork.SetShowCnt(comboBox2);

            errorList = evokWork.ErrorList;

            warnList = evokWork.WarningList;

            UpdateTimer.Enabled = true;
        }
コード例 #8
0
ファイル: WorkForm.cs プロジェクト: w7789475/EVOK
 private int ReadCSVData()
 {
     if (DialogExcelDataLoad.ShowDialog() == DialogResult.OK)
     {
         if (evokWork.showFilePathLabel == null)
         {
             evokWork.showFilePathLabel = label13;
         }
         evokWork.SetDataShowCb(listBox1);
         evokWork.SetDataShowLbl(label13);
         ConstantMethod.SaveDirectoryByFileDialog(DialogExcelDataLoad);
         int num = ConstantMethod.IsWhichFile(DialogExcelDataLoad.FileName);
         if (num == Constant.CsvFile)
         {
             evokWork.LoadCsvData(DialogExcelDataLoad.FileName, Constant.OpenCsvWithOutCheck);
         }
         if (num == Constant.ExcelFile)
         {
             evokWork.LoadExcelData(DialogExcelDataLoad.FileName);
         }
     }
     return(0);
 }
コード例 #9
0
ファイル: sqlManager.cs プロジェクト: w7789475/EVOK
        public bool open()
        {
            if (conn == null)
            {
                return(false);
            }
            if (conn.State == ConnectionState.Closed)
            {
                try
                {
                    conn.OpenAsync();
                    ConstantMethod.Delay(3000);

                    return(Status);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }

            return(false);
        }
コード例 #10
0
ファイル: WorkForm.cs プロジェクト: w7789475/EVOK
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult dr = MessageBox.Show("是否继续关闭程序?", "关闭提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);//触发事件进行提示

            if (dr == DialogResult.No)
            {
                e.Cancel = true;//就不退了
                return;
            }
            else
            {
                e.Cancel = false;//退了
            }

            UpdateTimer.Enabled   = false;
            FileSaveTimer.Enabled = false;
            if (evokWork != null)
            {
                evokWork.Dispose();
            }
            ConstantMethod.Delay(100);
            Environment.Exit(0);
        }
コード例 #11
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, "连接设备失败! ");
            }
        }
コード例 #12
0
ファイル: XJDevice.cs プロジェクト: w7789475/EVOK
        /// <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);
        }
コード例 #13
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);
        }
コード例 #14
0
        private void optBtn_Click(object sender, EventArgs e)
        {
            optBtn.Enabled   = false;
            optBtn.BackColor = Color.Red;
            rtbResult.Clear();
            rtbWork.Clear();
            startOptShow();

            /****单机启动
             * optSize.Len = 24400;//evokWork.lcOutInPs.ShowValue;
             * optSize.Dbc = 0;//evokWork.dbcOutInPs.ShowValue;
             * optSize.Ltbc = 0;/// evokWork.ltbcOutInPs.ShowValue;
             * optSize.Safe = 0;// evokWork.safeOutInPs.ShowValue;
             ***/

            /***
             * // if (!evokWork.AutoMes)
             * // {
             *  ConstantMethod.ShowInfo(rtbResult, optSize.OptNormal(rtbResult));
             * // }
             ****/
            //现场 去掉测长
            // if (!evokWork.AutoMes)
            //{
            optSize.Len  = evokWork.lcOutInPs.ShowValue;
            optSize.Dbc  = evokWork.dbcOutInPs.ShowValue;
            optSize.Ltbc = evokWork.ltbcOutInPs.ShowValue;
            optSize.Safe = evokWork.safeOutInPs.ShowValue;
            //不排版模式
            ConstantMethod.ShowInfo(rtbResult, optSize.OptNormal(rtbResult));
            // ConstantMethod.ShowInfo(rtbResult, optSize.NoOpt(rtbResult));
            // }

            stopOptShow();
            optBtn.BackColor = Color.Transparent;
            optBtn.Enabled   = true;
        }
コード例 #15
0
ファイル: EvokDTWork.cs プロジェクト: w7789475/EVOK
        /// <summary>
        /// 正常测长切割
        /// </summary>
        private void CutWorkThread()
        {
            //从哪一根开始切 暂定 从第一根 开始
            int CutProCnt = 0;

            if (optSize.ProdInfoLst.Count > 0)
            {
                for (int i = CutProCnt; i < optSize.ProdInfoLst.Count; i++)
                {
                    ConstantMethod.ShowInfo(rtbWork, "第" + (i + 1).ToString() + "根木料开始切割");

                    //plc 计数器 清零
                    CountClr();
                    // 每根数据下发
                    DownLoadDataNormal(i);
                    //开始切割进程
                    CutLoop(i);
                }
            }
            else
            {
                MessageBox.Show(Constant.noData);
            }
        }
コード例 #16
0
ファイル: EvokDTWork.cs プロジェクト: w7789475/EVOK
        public void DgvInOutEdit(int rowIndex, bool editEnable)
        {
            string s        = evokDevice.DataForm.Rows[rowIndex]["param1"].ToString();
            string str2     = evokDevice.DataForm.Rows[rowIndex]["param2"].ToString();
            string userdata = evokDevice.DataForm.Rows[rowIndex]["addr"].ToString();
            string area     = "D";
            int    addr     = 0;

            ConstantMethod.SplitAreaAndAddr(userdata, ref addr, ref area);
            int result = 0;
            int num4   = 0;

            if (int.TryParse(s, out result) && int.TryParse(str2, out num4))
            {
                if (XJPLCPackCmdAndDataUnpack.AreaGetFromStr(area) < 3)
                {
                    evokDevice.DPlcInfo[result].IsInEdit = editEnable;
                }
                else
                {
                    evokDevice.MPlcInfoAll[result][num4].IsInEdit = editEnable;
                }
            }
        }
コード例 #17
0
        //摄像头云台复位
        bool  PTReset()
        {
            byte dirByte = CmdOutReadyGo[3];// (byte)(0x20 | CwEnable << 3 );

            dirByte = ConstantMethod.set_bit(dirByte, 5, true);

            dirByte = ConstantMethod.set_bit(dirByte, 6, false);

            dirByte = ConstantMethod.set_bit(dirByte, 7, false);

            dirByte = ConstantMethod.set_bit(dirByte, 8, false);

            CmdOutReadyGo[3] = dirByte;

            ResetOk = false;

            PTInRst = true;

            /***
             * int cwEn = cwEnable;
             * byte[] cmdOutTemp = CmdOutReadyGo.ToArray();
             * byte dirByte = (byte)(0x10 | cwEn << 3);
             * cmdOutTemp[3] = dirByte;
             *
             * CmdOutReadyGo = cmdOutTemp;
             *
             * PTInRst = true;
             ***/

            ConstantMethod.Delay(5000, ref resetOk);
            PTInRst = false;

            StopPT();

            return(resetOk);
        }
コード例 #18
0
ファイル: FormTest.cs プロジェクト: w7789475/EVOK
        public void WriteBitTest()
        {
            List <byte[]> value = new List <byte[]>();

            byte[] value0 = { 0x00, 0x00 };
            byte[] value1 = { 0 };
            byte[] value2 = { 0 };
            value.Add(value0);
            value.Add(value1);
            value.Add(value2);

            int[] addr  = { 45, 20, 0 };
            int[] id    = { Constant.MXAddrId, Constant.MXAddrId, Constant.MXAddrId };
            int[] count = { 15, 1, 1 };

            List <byte> cmdInLst = new List <byte>(); //反馈可变

            dtClient.CmdOut = DTTcpCmdPackAndDataUnpack.PackWriteBitCmd(addr, id, count, value, cmdInLst);
            dtClient.sendTestData();

            ConstantMethod.ShowInfo(richTextBox1, ConstantMethod.byteToHexStr(dtClient.CmdOut));

            ConstantMethod.ShowInfo(richTextBox1, ConstantMethod.byteToHexStr(cmdInLst.ToArray()));
        }
コード例 #19
0
        public bool SetMValueON(PlcInfoSimple p)
        {
            if (p == null || p.BelongToDataform == null || p.Area == null || p.Mode == null)
            {
                return(false);
            }
            int value0 = 1;

            if (p != null && p.BelongToDataform != null)
            {
                WriteSingleMData(p.Addr, value0, p.Area, p.Mode);
            }

            ConstantMethod.DelayWriteCmdOk(Constant.XJConnectTimeOut, ref value0, ref p);

            if (value0 == p.ShowValue)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #20
0
        //摄像头云台右
        void PackPTRight()
        {
            byte dirByte = CmdOutReadyGo[3];// (byte)(0x20 | CwEnable << 3 );

            dirByte = ConstantMethod.set_bit(dirByte, 5, false);

            dirByte = ConstantMethod.set_bit(dirByte, 6, false);

            dirByte = ConstantMethod.set_bit(dirByte, 7, false);

            dirByte = ConstantMethod.set_bit(dirByte, 8, true);

            CmdOutReadyGo[3] = dirByte;

            PTRight = true;

            /****
             * byte[] cmdOutTemp = CmdOutReadyGo.ToArray();
             * byte dirByte = (byte)(0x80 | cwEn << 3);
             * cmdOutTemp[3] = dirByte;
             * PTRight = true;
             * CmdOutReadyGo = cmdOutTemp;
             ***/
        }
コード例 #21
0
        void Init(List <string> filestr)
        {
            splitDLst = new List <int>();
            splitMLst = new List <int>();

            DataFormLst = new List <DataTable>();
            CSVData     = new CsvStreamReader();
            dgShowLst   = new List <DataGridView>();

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

            MPlcInfo = new List <DTTcpPlcInfo>();
            DPlcInfo = new List <DTTcpPlcInfo>();


            serverParam = ConstantMethod.LoadServerParam(Constant.ConfigServerPortFilePath);

            //设置端口 放前面 因为SetPlcReadDMData 要用tcpclientManager
            SetComm(serverParam);
            //监控第一个列表数据
            if (dataFormLst.Count > 0)
            {
                SetPlcReadDMData(dataFormLst[0]);
            }

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

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

            WatchCommTimer.AutoReset = true;

            WatchCommTimer.Elapsed += new System.Timers.ElapsedEventHandler(WatchTimerEvent);
        }
コード例 #22
0
 public void WriteData(byte[] data)
 {
     //这里可以增加发送命令延时
     ConstantMethod.Delay(50);
     SerialPort.Send(data.ToArray());
 }
コード例 #23
0
ファイル: WorkForm.cs プロジェクト: w7789475/EVOK
        /// <summary>
        /// 控件tag 名称和plcsimple 结合起来
        /// plcsimple name只要包含 就可以和这个控件联合起来了
        /// </summary>
        public void SetControlInEvokWork()
        {
            ConstantMethod.
            CheckAllCtrls(this, allCtrls);
            foreach (Control control in allCtrls)
            {
                if (control.Tag != null)
                {
                    if ((control.Parent == tabPage1) || (control.Parent.Parent == tabPage1))
                    {
                        foreach (PlcInfoSimple simple in evokWork.PsLstAuto)
                        {
                            if (ConstantMethod.setControlInPlcSimple(simple, control))
                            {
                                break;
                            }
                            //增加了判断 只要匹配到 就自动跳出来 下一个 201904251220;
                        }
                        continue;
                    }

                    if ((control.Parent != null && control.Parent == tabPage2) ||
                        (control.Parent.Parent != null && control.Parent.Parent == tabPage2) ||
                        (control.Parent.Parent.Parent != null && control.Parent.Parent.Parent == tabPage2) ||
                        (control.Parent.Parent.Parent.Parent != null && control.Parent.Parent.Parent.Parent == tabPage2) ||
                        (control.Parent.Parent.Parent.Parent.Parent != null && control.Parent.Parent.Parent.Parent.Parent == tabPage2))
                    {
                        foreach (PlcInfoSimple simple2 in evokWork.PsLstHand)
                        {
                            if (ConstantMethod.setControlInPlcSimple(simple2, control))
                            {
                                break;
                            }
                        }
                        continue;
                    }
                    if ((control.Parent == tabPage3) ||
                        (control.Parent.Parent == tabPage3) ||
                        control.Parent.Parent.Parent == tabPage3 ||
                        control.Parent.Parent.Parent.Parent == tabPage3)
                    {
                        foreach (PlcInfoSimple simple3 in evokWork.PsLstParam)
                        {
                            if (ConstantMethod.setControlInPlcSimple(simple3, control))
                            {
                                break;
                            }
                        }
                        continue;
                    }
                    if (control.Parent == tabPage4)
                    {
                        foreach (PlcInfoSimple simple4 in evokWork.PsLstIO)
                        {
                            if (ConstantMethod.setControlInPlcSimple(simple4, control))
                            {
                                break;
                            }
                        }
                        continue;
                    }
                }
            }
        }
コード例 #24
0
        private bool FindIndexInPlcInfo(DataTable datafm, List <DTPlcInfo> dAll, List <List <DTPlcInfo> > mAll)
        {
            foreach (DataRow row in datafm.Rows)
            {
                if (row == null)
                {
                    continue;
                }

                int    mAddr = 0; //地址
                int    mArea;
                string strSplit1;
                string strSplit2; //地址区域
                string DSmode;    //单字还是双字

                strSplit1 = Regex.Replace(row["addr"].ToString().Trim(), "[A-Z]", "", RegexOptions.IgnoreCase);

                //取字母
                strSplit2 = Regex.Replace(row["addr"].ToString().Trim(), "[0-9]", "", RegexOptions.IgnoreCase);
                strSplit1 = strSplit1.Trim();
                strSplit2 = strSplit2.Trim();

                DSmode = row["mode"].ToString().Trim();

                //地址超了 无效 暂且定XDM 最大69999
                if (!int.TryParse(strSplit1, out mAddr) || (mAddr < 0) || (mAddr > Constant.XJMaxAddr))
                {
                    continue;
                }
                int count;
                if (!int.TryParse(row["count"].ToString().Trim(), out count))
                {
                    continue;
                }

                mArea = DTPLCPackCmdAndDataUnpack.AreaGetFromStr(strSplit2);

                if (mArea > Constant.HM_ID)
                {
                    mAddr = ConstantMethod.GetXYAddr8To10(mAddr);
                }

                mAddr = DTPLCPackCmdAndDataUnpack.AreaGetFromStr(mAddr, strSplit2);

                if (mArea < 0)
                {
                    continue;
                }
                if (row["param1"] != null && row["param2"] != null)
                {
                    int[] s = FindValueIndexFromDPlcInfo(mAddr, mArea, DSmode);

                    row["param1"] = s[0];
                    row["param2"] = s[1];
                    //让集合 把dataform 也保存下 方便更新数据
                    if (mArea < Constant.M_ID)
                    {
                        if (!(s[0] > -1))
                        {
                            continue;
                        }
                        DPlcInfo[s[0]].BelongToDT = datafm;
                        DPlcInfo[s[0]].Row        = datafm.Rows.IndexOf(row);
                    }
                    else
                    {
                        if (!(s[0] > -1 && s[1] > -1))
                        {
                            continue;
                        }
                        MPlcInfoAll[s[0]][s[1]].BelongToDT = datafm;
                        MPlcInfoAll[s[0]][s[1]].Row        = datafm.Rows.IndexOf(row);
                    }
                }
            }
            return(true);
        }
コード例 #25
0
ファイル: PlcWork.cs プロジェクト: w7789475/EVOK
 public void SetPage(int id)
 {
     if ((evokDevice.DataFormLst.Count > 1) && (evokDevice.DataFormLst[id].Rows.Count > 0))
     {
         AllPlcSimpleLst[id].Clear();
         foreach (DataRow row in evokDevice.DataFormLst[id].Rows)
         {
             if (row != null)
             {
                 string str = row["bin"].ToString();
                 if (!string.IsNullOrWhiteSpace(str))
                 {
                     PlcInfoSimple item = new PlcInfoSimple(str);
                     try
                     {
                         item.Mode             = row["mode"].ToString();
                         item.RowIndex         = evokDevice.DataFormLst[id].Rows.IndexOf(row);
                         item.BelongToDataform = evokDevice.DataFormLst[id];
                         int    addr     = 0;
                         string area     = "D";
                         string userdata = row["addr"].ToString();
                         string str4     = row["param3"].ToString();
                         string str5     = row["param4"].ToString();
                         if (!string.IsNullOrWhiteSpace(str4))
                         {
                             item.ShowStr.Add(str4);
                         }
                         if (!string.IsNullOrWhiteSpace(str5))
                         {
                             item.ShowStr.Add(str5);
                         }
                         ConstantMethod.SplitAreaAndAddr(userdata, ref addr, ref area);
                         item.Area = area;
                         item.Addr = addr;
                         if (row.Table.Columns.Contains("param7"))
                         {
                             string str6 = row["param7"].ToString();
                             if (!string.IsNullOrWhiteSpace(str6))
                             {
                                 item.Ration = int.Parse(str6);
                             }
                         }
                         if (row.Table.Columns.Contains("param8"))
                         {
                             string str7 = row["param8"].ToString();
                             if (!string.IsNullOrWhiteSpace(str7))
                             {
                                 item.MaxValue = int.Parse(str7);
                             }
                         }
                         if (row.Table.Columns.Contains("param9"))
                         {
                             string str8 = row["param9"].ToString();
                             if (!string.IsNullOrWhiteSpace(str8))
                             {
                                 item.MinValue = int.Parse(str8);
                             }
                         }
                         AllPlcSimpleLst[id].Add(item);
                     }
                     catch (Exception)
                     {
                     }
                 }
             }
         }
     }
 }
コード例 #26
0
ファイル: sysInfo.cs プロジェクト: w7789475/EVOK
 void Init()
 {
     ConstantMethod.CheckAllCtrls(this, allCtrls);
 }
コード例 #27
0
ファイル: DTTcpClientManager.cs プロジェクト: w7789475/EVOK
        void DTPLC_TCPClient_Received()
        {
            while (true)
            {
                try
                {
                    Application.DoEvents();
                    byte[] buffer = new byte[1024];
                    int r = socketDt.Receive(buffer);
                    if (r > 0)
                    {                      
                        byte[] array_buffer = new byte[r];
                        Array.Copy(buffer,array_buffer,r);

                        Thread.Sleep(10);
                        if (IsRePackCmdReadDMDataOut)
                        {
                            if (IsRepackDone)
                            {
                                SetReadCmd();
                                //if(ConstantMethod.compareByte(array_buffer, SetDMCmdIn.ToArray())))
                                isRePackCmdReadDMDataOut = false;
                            }
                        }
                        else                     
                        if (isWriteCmd) //如果则写数据
                        {                

                            if (ConstantMethod.compareByte(array_buffer, SetDMCmdIn.ToArray()))
                            {
                                isWriteCmd = false;                           
                            }
                            else
                            {
                                CmdOut = SetDMCmdOut.ToArray();// CmdOutLst[0].ToArray();
                                CmdIn  = SetDMCmdIn.ToArray();// CmdInLst[0].ToArray();                                
                            }                                              
                        }
                        else
                        {
                            if ((EventDataProcess != null))
                            {

                                if (ConstantMethod.compareByte(array_buffer, Constant.IsDtAsPlcTcpExitIn))
                                {
                                   SetReadCmd();
                                }
                                else
                                //判断数据是否正确                             
                                if (array_buffer.Count() == CmdIn.Count())
                                {
                                    SetReadCmd();
                                    isDeviceReady = true;
                                    DataProcessEventArgs.Byte_buffer = array_buffer.ToArray();
                                    EventDataProcess(this, DataProcessEventArgs);
                                }else
                                SetReadCmd();
                            }
                        }
                        GetData();
                        //获取到数据 显示
                       // ConstantMethod.ShowInfo(showRichTextBox, ConstantMethod.byteToHexStr(array_buffer));  
                                                                                  
                    }
                    else
                    {
                        throw new Exception("Error Recevie Data");
                    }                                                                                                                
                }
                catch (Exception ex)
                {

                   // throw new Exception("Error Recevie Data0");
                    // ConstantMethod.ShowInfo(r1, ex.Message);
                }
            }
        }
コード例 #28
0
ファイル: DTTcpClientManager.cs プロジェクト: w7789475/EVOK
        public event socDataProcess EventDataProcess;//利用委托来声明事件

        #region 数据写操作       

        public bool SetMultipleDMArea(int Addr, int count, List<byte[]> value, string Area)
        {
            if (isDeviceReady)
            {
              
                List<int> addr = new List<int>();
                List<int> addressid = new List<int>();
                List<int> count0 = new List<int>();
                int addrid = DTTcpCmdPackAndDataUnpack.GetIntAreaFromStr(Area);
                if (DeviceId == Constant.xzjDeivceId)
                {
                    addrid = XJPLCPackCmdAndDataUnpack.AreaGetFromStr(Area);
                    for (int i = 0; i < count; i++)
                    {
                        if(value.Count>0)
                        addr.Add(Addr + i*(value[0].Count()/2));
                        addressid.Add(addrid);
                        count0.Add(1);
                    }
                }
                else                          
                for (int i = 0; i < count; i++)
                {                    
                    addr.Add(Addr+i);
                    addressid.Add(addrid);
                    count0.Add(1);
                }

                SetDMCmdOut.Clear();
                SetDMCmdIn.Clear();
                if (DeviceId == Constant.xzjDeivceId)
                {
                    if (addrid < Constant.HSD_ID)
                        SetDMCmdOut.AddRange(DTTcpCmdPackAndDataUnpack.AsPlcPackWriteByteCmd(addr.ToArray(), addressid.ToArray(), count0.ToArray(), value, SetDMCmdIn));
                    else
                        SetDMCmdOut.AddRange(DTTcpCmdPackAndDataUnpack.AsPlcPackWriteBitCmd(addr.ToArray(), addressid.ToArray(), count0.ToArray(), value, SetDMCmdIn));

                }
                else
                {
                    if (addrid > Constant.MXAddrId)
                        SetDMCmdOut.AddRange(DTTcpCmdPackAndDataUnpack.PackWriteByteCmd(addr.ToArray(), addressid.ToArray(), count0.ToArray(), value, SetDMCmdIn));
                    else
                        SetDMCmdOut.AddRange(DTTcpCmdPackAndDataUnpack.PackWriteBitCmd(addr.ToArray(), addressid.ToArray(), count0.ToArray(), value, SetDMCmdIn));
                }
                ConstantMethod.Delay(200); //延时一下 防止数据发太快 监控上看不到
                //防止前面在写数据 
                while (isWriteCmd)
                {
                    Application.DoEvents();
                }

                isWriteCmd = true;
               
                ConstantMethod.DelayWriteCmd(Constant.WriteCommTimeOut, ref isWriteCmd);

                return (!isWriteCmd);
            }
            return false;

        }
コード例 #29
0
        void AsPlcDataprocess(object sender, SocEventArgs e)
        {
            if (isShiftDataForm)
            {
                isShiftDataForm = false;
                return;
            }
            if (e.Byte_buffer.Count() < 12)
            {
                return;
            }

            List <byte>   data  = new List <byte>();
            List <byte[]> value = new List <byte[]>();

            data.AddRange(e.Byte_buffer);

            byte[] s = data.Skip(7).Take(2).ToArray();
            if ((!ConstantMethod.compareByteStrictly(s, Constant.DTAsPlcTcpFunctionReadBitCmd)) &&
                (!(ConstantMethod.compareByteStrictly(s, Constant.DTAsPlcTcpFunctionReadByteCmd))))
            {
                return;
            }

            byte[] s1 = data.Skip(9).Take(2).ToArray();
            Array.Reverse(s1);
            int ss = BitConverter.ToInt16(s1, 0);

            if (ss < 1)
            {
                return;
            }
            if (data.Count > 11)
            {
                data.RemoveRange(0, 11);
            }
            //这里执行一种数据获取当时直到数据数量取完

            if (ConstantMethod.compareByteStrictly(s, Constant.DTAsPlcTcpFunctionReadBitCmd))
            {
                value = getMValue(data);
                //m 看下是否存在分组的数据
                if (splitMLst.Count == 0)
                {
                    if (MPlcInfo.Count() == value.Count())
                    {
                        for (int i = 0; i < MPlcInfo.Count(); i++)
                        {
                            MPlcInfo[i].ByteValue = value[i];
                        }
                    }
                }
                else
                {
                    valueGet(splitMLst, value, MPlcInfo);
                }
            }
            else
            {
                if (ConstantMethod.compareByteStrictly(s, Constant.DTAsPlcTcpFunctionReadByteCmd))
                {
                    value = getDValue(data);
                    //D
                    if (splitDLst.Count == 0)
                    {
                        if (DPlcInfo.Count() == value.Count())
                        {
                            for (int i = 0; i < DPlcInfo.Count(); i++)
                            {
                                DPlcInfo[i].ByteValue = value[i];
                            }
                        }
                    }
                    else
                    {
                        valueGet(splitDLst, value, DPlcInfo);
                    }
                }
            }
            //update form
            updateData();
            //数据处理 以及更新 datagridview
            // DTPLCcmd.UnPackCmdReadDMDataIn(dataForm,e.Byte_buffer, DPlcInfo, MPlcInfoAll);
            Application.DoEvents();
            e.Byte_buffer = null;
        }
コード例 #30
0
        //写D寄存器支持多个使用


        public byte[] getByteFromMode(string value, string Mode)
        {
            List <byte> valueByte = new List <byte>();
            Dictionary <string, int> modeByteCount = new Dictionary <string, int>();

            if (DeviceId == Constant.xzjDeivceId)
            {
                ConstantMethod.ArrayToDictionary(modeByteCount, Constant.asPlcTcpType, Constant.asPlcTcpTypeByteCount);

                switch (modeByteCount[Mode])
                {
                case 1:
                {
                    int data1Byte = 0;

                    //D区单字节 和位 区分开

                    if (int.TryParse(value, out data1Byte))
                    {
                        if (Mode.Equals(Constant.BitMode))
                        {
                            valueByte.Add((byte)data1Byte);
                        }
                        else
                        {
                            valueByte.AddRange(ConstantMethod.getDataHighLowByte(data1Byte));
                        }
                    }

                    break;
                }

                case 2:
                {
                    int data1Byte = 0;
                    if (int.TryParse(value, out data1Byte))
                    {
                        valueByte.AddRange(BitConverter.GetBytes(data1Byte));
                    }
                    byte temp = 0;

                    temp         = valueByte[0];
                    valueByte[0] = valueByte[1];
                    valueByte[1] = temp;
                    temp         = valueByte[2];
                    valueByte[2] = valueByte[3];
                    valueByte[3] = temp;

                    break;
                }
                }

                return(valueByte.ToArray());
            }
            else
            {
                ConstantMethod.ArrayToDictionary(modeByteCount, Constant.tcpType, Constant.tcpTypeByteCount);
            }
            //1字节 2 字节 4字节 8字节

            switch (modeByteCount[Mode])
            {
            case 1:
            {
                int data1Byte = 0;

                if (int.TryParse(value, out data1Byte))
                {
                    valueByte.Add((byte)(data1Byte));
                }

                break;
            }

            case 2:
            {
                //uint
                int data1Byte = 0;

                if (int.TryParse(value, out data1Byte))
                {
                    valueByte.AddRange(ConstantMethod.getDataLowHighByte(data1Byte));
                }

                break;
            }

            case 4:
            {
                //int 占用4个 和单精度浮点
                int data1Byte = 0;
                if (Mode.Contains(Constant.REAL))
                {
                    float dataFloat = 0;
                    if (float.TryParse(value, out dataFloat))
                    {
                        valueByte.AddRange(BitConverter.GetBytes(dataFloat));
                    }
                }
                else
                if (int.TryParse(value, out data1Byte))
                {
                    valueByte.AddRange(BitConverter.GetBytes(data1Byte));
                }

                break;
            }

            case 8:
            {
                //8字节 就双精度浮点 和LONG INT
                Int64 data1Byte = 0;
                if (Mode.Contains(Constant.REAL))
                {
                    double dataFloat = 0;
                    if (double.TryParse(value, out dataFloat))
                    {
                        valueByte.AddRange(BitConverter.GetBytes(dataFloat));
                    }
                }
                else
                if (Int64.TryParse(value, out data1Byte))
                {
                    valueByte.AddRange(BitConverter.GetBytes(data1Byte));
                }


                break;
            }
            }

            return(valueByte.ToArray());
        }