Ejemplo n.º 1
0
        private string setPlcCmd(Socket socket, string plcAddress, string setResult)
        {
            string rtn = InspectUtilsTB.sendCmdToTarget(socket, "01WWR" + plcAddress + setResult + "\r\n");

            //MessageBox.Show("01WWR" + plcAddress + setResult + "\r\n");
            return(rtn);
        }
Ejemplo n.º 2
0
        private string readInspect(int camId)
        {
            string str = "c1;";

            InspectUtilsTB.sendCmdToTarget(localSocket, str);
            var receiveData = InspectUtilsTB.receiveDataFromTarget(localSocket, resBytes);

            return(receiveData);
        }
Ejemplo n.º 3
0
        private int getPlcCmd(Socket socket, string plcAddress)
        {
            int enCamId = 0;

            InspectUtilsTB.sendCmdToTarget(socket, readCmd + plcAddress + "\r\n");
            var cmd = InspectUtilsTB.receiveDataFromTarget(socket, new byte[1024]);

            testStr = cmd;
            var indexOf = cmd.IndexOf('\r');

            if (indexOf != -1)
            {
                cmd = cmd.Substring(0, indexOf);
            }
            if (cmd == "11OK0001" && cmd != lastCmd)
            {
                Console.WriteLine(Thread.CurrentThread.Name + "触发");
                enCamId = 1;
            }

            lastCmd = (string)cmd.Clone();
            return(enCamId);
        }
Ejemplo n.º 4
0
        private string setPlcCmd(Socket socket, string plcAddress, string setResult)
        {
            string rtn = InspectUtilsTB.sendCmdToTarget(socket, writeCmd + plcAddress + setResult);

            return(rtn);
        }
Ejemplo n.º 5
0
        private void cmdCam1_Click(object sender, EventArgs e)
        {
            string str = "c1;";

            testMsg.Text      = "无";
            testMsg.BackColor = Color.Silver;
            InspectUtilsTB.sendCmdToTarget(inspectSocket, str);
            var receiveData = InspectUtilsTB.receiveDataFromTarget(inspectSocket, resByteArr);

            if (work1.camMode == 1)     //仅开启上面的相机
            {
                if (receiveData == "2") //上ok下ng
                {
                    setPlcCmd(plcSocket1, cam1ResAds, " 0001\r\n");
                    setPlcCmd(plcSocket1, cam1CmdAds, " 0000\r\n");
                    testMsg.Text      = "上面胶条 OK";
                    testMsg.BackColor = Color.LimeGreen;
                }
                else
                {
                    setPlcCmd(plcSocket1, cam1ResAds, " 0003\r\n"); //给PLC发送3代表上面NG
                    setPlcCmd(plcSocket1, cam1CmdAds, " 0000\r\n");
                    testMsg.Text      = "上面胶条 NG";
                    testMsg.BackColor = Color.Red;
                }
            }
            else if (work1.camMode == 2)
            {
                if (receiveData == "3") //上ng下ok
                {
                    setPlcCmd(plcSocket1, cam1ResAds, " 0001\r\n");
                    setPlcCmd(plcSocket1, cam1CmdAds, " 0000\r\n");
                    testMsg.Text      = "下面胶条 OK";
                    testMsg.BackColor = Color.LimeGreen;
                }
                else
                {
                    setPlcCmd(plcSocket1, cam1ResAds, " 0002\r\n"); //2代表下面NG
                    setPlcCmd(plcSocket1, cam1CmdAds, " 0000\r\n");
                    testMsg.Text      = "下面胶条 NG";
                    testMsg.BackColor = Color.Red;
                }
            }
            else if (work1.camMode == 3) //上下面相机都正常工作
            {
                if (receiveData == "1")  //上下都ok
                {
                    setPlcCmd(plcSocket1, cam1ResAds, " 0001\r\n");
                    setPlcCmd(plcSocket1, cam1CmdAds, " 0000\r\n");
                    testMsg.Text      = "全部OK";
                    testMsg.BackColor = Color.LimeGreen;
                }
                else if (receiveData == "2") //上OK下NG
                {
                    setPlcCmd(plcSocket1, cam1ResAds, " 0002\r\n");
                    setPlcCmd(plcSocket1, cam1CmdAds, " 0000\r\n");
                    testMsg.Text      = "下面胶条NG";
                    testMsg.BackColor = Color.Red;
                }
                else if (receiveData == "3") //上NG下OK
                {
                    setPlcCmd(plcSocket1, cam1ResAds, " 0003\r\n");
                    setPlcCmd(plcSocket1, cam1CmdAds, " 0000\r\n");
                    testMsg.Text      = "上面胶条NG";
                    testMsg.BackColor = Color.Red;
                }
                else if (receiveData == "4") //上下都NG
                {
                    setPlcCmd(plcSocket1, cam1ResAds, " 0004\r\n");
                    setPlcCmd(plcSocket1, cam1CmdAds, " 0000\r\n");
                    testMsg.Text      = "全部NG";
                    testMsg.BackColor = Color.Red;
                }
            }
        }