示例#1
0
        private void GetComClick(int idx, string PortName)
        {
            String flagMessage = ComConnector.GetCom(PortName);

            DataGridViewCell statusCell = ComDataGrid.Rows[idx].Cells[IDX_CONSTATUS_COUNT];

            if (statusCell != null)
            {
                if (flagMessage == null)
                {
                    statusCell.Style.ForeColor = Color.Green;
                    String retError = ComConnector.sendToMachine(idx, PortName, ComConnector.GetHexValue(NONE));
                    if (retError != null)
                    {
                        MessageBox.Show(retError, "Error");
                        statusCell.Style.ForeColor = Color.DarkRed;
                        statusCell.Value           = "断开";
                    }
                    else
                    {
                        statusCell.Value = "连通";
                    }
                    return;
                }

                statusCell.Style.ForeColor = Color.DarkRed;
                statusCell.Value           = "断开";
                MessageBox.Show(flagMessage, "Error");
            }
        }
示例#2
0
        private bool ResetAL1(int idx)
        {
            String           PortName     = ComDataGrid.Rows[idx].Cells[IDX_PORT_NAME].Value.ToString();
            DataGridViewCell addressCell  = ComDataGrid.Rows[idx].Cells[IDX_ADDRESS_CODE];
            String           FunctionCode = addressCell.Value + " " + RESET_AL1;
            String           CrcCode      = ComConnector.ToModbusCRC16(FunctionCode);
            String           retError     = ComConnector.sendToMachine(idx, PortName,
                                                                       ComConnector.GetHexValue(FunctionCode + " " + CrcCode.Substring(0, 2) + " " + CrcCode.Substring(2, 2)));

            if (retError != null)
            {
                DataGridViewCell statusCell = ComDataGrid.Rows[idx].Cells[IDX_CONSTATUS_COUNT];

                MessageBox.Show(retError, "Error");
                statusCell.Style.ForeColor = Color.DarkRed;
                statusCell.Value           = "断开";
                ComErrorCount++;
                if (ComErrorCount > 8)
                {
                    MessageBox.Show("COM 连接次数过多,将关闭程序", "Error");
                    Environment.Exit(0);
                }

                return(false);
            }

            ComErrorCount = 0;
            ComDataGrid.Rows[idx].Cells[IDX_CURRENT_COUNT].Value = 0;
            return(true);
        }
示例#3
0
        public void LEDShouldDisplay()
        {
            //准备Com设备和LED数码管
            ComBase comIO = new MyComDevice();

            ComLED.ComLED led = new ComLED.ComLED();
            //连线
            ComConnector connector = new ComConnector();

            connector.Bind(comIO, led.com);

            Assert.AreEqual(led.A, '0');
            Assert.AreEqual(led.B, '0');

            //串口发送
            ((MyComDevice)comIO).Display(0xFC);

            Assert.AreEqual(led.A, 'F');
            Assert.AreEqual(led.B, 'C');
            //断开连线
            connector.Close();

            ((MyComDevice)comIO).Display(0xDA);

            Assert.AreNotEqual(led.A, 'D');
            Assert.AreNotEqual(led.B, 'A');

            Assert.AreEqual(led.A, 'F');
            Assert.AreEqual(led.B, 'C');
        }
示例#4
0
        /**
         * 向仪表发送后查询计数指令后,更新列表的延期事件
         */
        private void readCounter(object sender, EventArgs e)
        {
            for (int i = 0; i < ComConnector.retCounts.Length; i++)
            {
                if (i >= ComDataGrid.Rows.Count)
                {
                    break;
                }
                DataGridViewCell CountCell   = ComDataGrid.Rows[i].Cells[IDX_CURRENT_COUNT];
                DataGridViewCell CountedCell = ComDataGrid.Rows[i].Cells[IDX_COUNTED_COUNT];
                int countedValue             = 0;
                if (ComConnector.retCounts[i] >= 0)
                {
                    countedValue    = ComConnector.retCounts[i] + Convert.ToInt16(CountedCell.Value);
                    CountCell.Value = countedValue;
                }
                DataGridViewCell StandardCell = ComDataGrid.Rows[i].Cells[IDX_STANDARD_COUNT];
                if (!StandardCell.Value.ToString().Equals("-"))
                {
                    int standard = Convert.ToInt16(StandardCell.Value);
                    if (countedValue < standard)
                    {
                        CountCell.Style.BackColor = Color.Yellow;
                    }
                    else
                    {
                        CountCell.Style.BackColor = Color.White;
                    }
                }
                else
                {
                    CountCell.Style.BackColor = Color.White;
                }
            }

            string retCheck = ComConnector.CheckSendTokens();

            if (retCheck != null)
            {
                ComErrorCount++;
                if (ComErrorCount > 8)
                {
                    MessageBox.Show("COM 连接次数过多,将关闭程序", "Error");
                    Environment.Exit(0);
                }

                MessageBox.Show(retCheck, "Error");

                return;
            }

            ComTimer.Enabled = false;
        }
示例#5
0
        public void ComIOBindToComBaseByConnector()
        {
            //初始化两个设备
            ComBase comIO   = new MyTestComDev();
            ComBase comBase = new MyVirtualCom();
            //初始化一个连接线Connector
            ComConnector connector = new ComConnector();

            //链接
            connector.Bind(comIO, comBase);
            Assert.IsNotNull(comBase.Connector);

            Console.WriteLine("ComBase send data to ComIO");
            (comBase as MyVirtualCom)?.SendTest();

            Console.WriteLine("ComIO receive data from real device to ComBase");
            (comIO as MyTestComDev)?.SendTest();

            //移除连接线
            connector.Close();
            Assert.IsNull(comBase.Connector);
        }
示例#6
0
        public MainForm()
        {
            this.InitializeComponent();
            this.ReadInitializeFile();
            this.lbl_processCode.Text = Common.process_code + " " + Common.line_part;

            ComTimer.Interval = 500;
            ComTimer.Start();

            string resContent = HttpRequester.Login();

            this.checkResContent(resContent);

            recSocket = new RecSocket(this);
            Thread socketThread =
                new Thread(new ThreadStart(recSocket.ListenMethod));

            socketThread.Name         = "SocketThread";
            socketThread.IsBackground = true;
            socketThread.Start();

            ComRefreshTimer.Start();
            ComConnector.InitTaskQueue();
        }
示例#7
0
 //
 private void MainFormClosing(object sender, EventArgs e)
 {
     ComConnector.CloseAllComs();
 }