public void SendCommand(PLCCommand command)
        {
            NetworkStream stream = client.GetStream();

            byte[] data = Encoding.ASCII.GetBytes(command.ToString().ToLower());

            stream.Write(data, 0, data.Length);
        }
Example #2
0
        public void Command([FromQuery] string command)
        {
            PLCCommand c = (PLCCommand)Enum.Parse(typeof(PLCCommand), command);

            commandSender.SendCommand(c);
        }
Example #3
0
        public void DeletetionEnd(object obj)
        {
            progressBar1.Value = 0;
            try
            {
                //发送开始考试
                plcCommond = PLCCommand.GetInstance();
                plcCommond.SyncWrite((PLCCommand.GroupName)obj, PLCCommand.ItemName.Set, 1);  //set写入1  指定科目1

                //开始检测
                plcCommond.SyncWrite((PLCCommand.GroupName)obj, PLCCommand.ItemName.DetectionStart, 1);  //DetectionStart写入1  开始检测
                bool declectResult2 = false;
                bool result2        = false;
                bool detectionEnd   = false;

                int sumTimeOut = 0;

                while (!detectionEnd)
                {
                    try
                    {
                        sumTimeOut++;

                        progressBar1.Value = sumTimeOut;
                        if (sumTimeOut > 149)
                        {
                            progressBar1.Value = 150;
                            break;
                        }
                        bool result        = false;
                        bool declectResult = plcCommond.SyncRead((PLCCommand.GroupName)obj, PLCCommand.ItemName.DetectionEnd, out result);
                        if (result)
                        {
                            progressBar1.Value = 150;
                            //读取结果值
                            declectResult2 = plcCommond.SyncRead((PLCCommand.GroupName)obj, PLCCommand.ItemName.Result, out result2);

                            detectionEnd = result;
                            break;
                        }

                        Thread.Sleep(100);
                    }
                    catch (Exception)
                    {
                        break;
                    }
                }
                if (result2)
                {
                    label2.Invoke(new Action(() =>
                    {
                        label2.Text = "当前科目检测结果正确";
                    }));
                }
                else
                {
                    label2.Invoke(new Action(() =>
                    {
                        label2.Text = "当前科目检测结果错误";
                    }));
                }
            }
            catch (Exception)
            {
                label2.Invoke(new Action(() =>
                {
                    label2.Text = "当前科目检测结果错误";
                }));
            }
        }