Exemplo n.º 1
0
 private void button1_Click(object sender, EventArgs e)                          //连接ABB机器人socket
 {
     if (ConnectABBflag == true)
     {
         ShowABBflagOK = true;
         ShowABBflagNO = true;
         if (ABBClientConnectInforStr != NetConnected)
         {
             CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] Connect to robot ABB ..." + "\r\n"));
             IPEndPoint remoteEP = new IPEndPoint(System.Net.IPAddress.Parse(ABBRemoteIPAddress), int.Parse(ABBRemotePort));
             ABBClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
             ABBClientSocket.ReceiveBufferSize = 2000;
             ABBClientSocket.SendBufferSize    = 2000;
             ABBClientSocket.SendTimeout       = 4;
             ABBClientSocket.BeginConnect(remoteEP, new AsyncCallback(ABBClientConnectCallback), ABBClientSocket);
             CommunicationMsg.AppendText("aaaaa1\n");                                                            //字符戳,是有执行到这一步的
             if (ABBClientConnectInforStr != NetConnected)
             {
                 IPEndPoint clientipe = (IPEndPoint)ABBClientSocket.LocalEndPoint;
                 CommunicationMsg.AppendText("aaaaa");
             }
         }
     }
     else
     {
         if (ABBClientSocket != null)
         {
             ABBClientSocket.Close();
             ABBClientSocket.Dispose();
             ConnectABB.ForeColor = Color.Red;
             CommunicationMsg.AppendText(System.Convert.ToString("Disconnect to robot ABB" + "\r\n"));
         }
         ABBClientConnectInforStr = NetDisConnected;
     }
 }
Exemplo n.º 2
0
 private void TimerNetMonitor_Tick(object sender, EventArgs e)
 {
     TextBox1.Text = System.Convert.ToString(PlateCheck) + System.Convert.ToString(finishMoveFlag);
     if (CommunicationMsg.Lines.Length > 50)
     {
         textLast1             = CommunicationMsg.Text[49];
         textLast2             = CommunicationMsg.Text[50];
         textLast3             = CommunicationMsg.Text[51];
         CommunicationMsg.Text = "";
         CommunicationMsg.AppendText(textLast1 + "\r\n");
         CommunicationMsg.AppendText(textLast2 + "\r\n");
         CommunicationMsg.AppendText(textLast3 + "\r\n");
     }
     if (ConnectABBflag == true)
     {
         lock (ABBClientSyncObject)
         {
             if (ABBClientConnectInforStr != NetConnected)
             {
                 if (ABBClientSocket != null)
                 {
                     ABBClientSocket.Close();
                     ABBClientSocket.Dispose();
                 }
                 IPEndPoint remoteEP = new IPEndPoint(System.Net.IPAddress.Parse(ABBRemoteIPAddress), int.Parse(ABBRemotePort));
                 ABBClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                 ABBClientSocket.ReceiveBufferSize = 2000;
                 ABBClientSocket.SendBufferSize    = 2000;
                 ABBClientSocket.SendTimeout       = 4;
                 ABBClientSocket.BeginConnect(remoteEP, new AsyncCallback(ABBClientConnectCallback), ABBClientSocket);
             }
             else
             {
                 byte[] byteData = Encoding.ASCII.GetBytes("OK" + "\r\n");
                 try
                 {
                     //Begin sending the data to the remote device.StockIsOK
                     ABBClientSocket.BeginSend(byteData, 0, byteData.Length, (System.Net.Sockets.SocketFlags) 0, new AsyncCallback(ABBClientSendCallback), ABBClientSocket);
                 }
                 catch (Exception)
                 {
                     ABBClientConnectInforStr = NetError;
                 }
             }
         }
         if (PlateCheck == true && finishMoveFlag == true)
         {
             byte[] byteData = Encoding.ASCII.GetBytes("PlateIsOK" + "\r\n");
             try
             {
                 //Begin sending the data to the remote device.StockIsOK
                 TextBoxInfo.Text = TextBoxInfo.Text + "SendToABBOnce" + "\r\n";
                 ABBClientSocket.BeginSend(byteData, 0, byteData.Length, (System.Net.Sockets.SocketFlags) 0, new AsyncCallback(ABBClientSendCallback), ABBClientSocket);
             }
             catch (Exception)
             {
                 ABBClientConnectInforStr = NetError;
             }
             PlateCheck = false;
             // finishMoveFlag = False
         }
         if (ABBClientConnectInforStr == NetConnected)
         {
             ConnectABB.ForeColor = Color.Green;
             if (ShowABBflagOK == true)
             {
                 CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] Connect to robot ABB successly" + "\r\n"));
                 ShowABBflagOK = false;
                 ShowABBflagNO = true;
             }
         }
         else
         {
             ConnectABB.ForeColor = Color.Red;
             if (ShowABBflagNO == true)
             {
                 CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] Wait for robot ABB connection" + "\r\n"));
                 ShowABBflagNO = false;
                 ShowABBflagOK = true;
             }
         }
     }
 }
Exemplo n.º 3
0
        private void ABBShowInfoSub(string Info)
        {
            CogToolBlock myToolBlock;
            CogToolBlock myRunToolblock3;             //= myToolBlock.Tools("MyToolBlock3")

            // static string SaveInfo = ""; //VBConversions Note: Static variable moved to class level and renamed ABBShowInfoSub_SaveInfo. Local static variables are not supported in C#.
            if (ABBShowInfoSub_SaveInfo != Info)
            {
                TextBoxInfo.Text = Info + "\r\n" + TextBoxInfo.Text;
            }
            ABBShowInfoSub_SaveInfo = Info;
            if (Info == "WorkpieceArrived")
            {
                CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] From robot ABB : " + "\r\n"));
                CommunicationMsg.AppendText(System.Convert.ToString("Workpiece arrived target position" + "\r\n"));
            }
            else if (Info == "StartPlateMove")
            {
                finishMoveFlag = false;
                startMoveFlag  = true;
                CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] From robot ABB : " + "\r\n"));
                CommunicationMsg.AppendText(System.Convert.ToString("Start move platform ..." + "\r\n"));
            }            //下面开始的代码就会闪退
            else if (Info == "TriggerCam")
            {
                TriggerCamNum++;                 //本身定义为0,+1代表可以执行拍照了
                CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] From robot ABB : " + "\r\n"));
                CommunicationMsg.AppendText(System.Convert.ToString("Robot ABB camera trigger " + Conversion.Str(TriggerCamNum) + "\r\n"));
                CogToolGroup myTG = (CogToolGroup)myJob.VisionTool;
                myToolBlock     = (CogToolBlock)myTG.Tools["AcquireImageAndProcessLeft"];
                myRunToolblock3 = (CogToolBlock)myToolBlock.Tools["MyToolBlock3"];
                if (TriggerCamNum == 1)
                {
                    myRunToolblock3.Inputs["TriggerCamNum"].Value = 0;
                }
                else
                {
                    myRunToolblock3.Inputs["TriggerCamNum"].Value = 1;
                    TriggerCamNum = 0;
                }
            }

            //	try
            //	{
            //		ModuleCard.d1000_out_bit((short)10, (short)0);
            //		System.Threading.Thread.Sleep(50);
            //		int num = 0;
            //		myRunToolblock3.Inputs["Input2dImage"].Value = AcqFifoTool4.Operator.Acquire(out num); //应该是获取图像
            //		myRunToolblock3.Run(); //这个myruntoolblock3是一个模块,和外部的拍照组件链接(确信)
            //	}
            //	catch (Exception)
            //	{
            //		MessageBox.Show("error");
            //	}
            //}
            //判断定位是否正确
            //ABB_Result = System.Convert.ToString(myRunToolblock3.Outputs["ABB_Result"].Value); //这里是怎么判断的呢?????
            //if (ABB_Result == "OK")
            //{
            //	if (ABBClientConnectInforStr == NetConnected)
            //	{
            //		byte[] byteData = Encoding.ASCII.GetBytes("WorkpieceLocationOK" + "\r\n");
            //		try
            //		{
            //			//Begin sending the data to the remote device.StockIsOK
            //			ABBClientSocket.BeginSend(byteData, 0, byteData.Length, (System.Net.Sockets.SocketFlags)0, new AsyncCallback(ABBClientSendCallback), ABBClientSocket);
            //		}
            //		catch (Exception)
            //		{
            //			ABBClientConnectInforStr = NetError;
            //		}
            //	}
            //}
            //else
            //{
            //	if (ABBClientConnectInforStr == NetConnected)
            //	{
            //		byte[] byteData = Encoding.ASCII.GetBytes("WorkpieceLocationNO" + "\r\n");
            //		try
            //		{
            //			//Begin sending the data to the remote device.StockIsOK
            //			ABBClientSocket.BeginSend(byteData, 0, byteData.Length, (System.Net.Sockets.SocketFlags)0, new AsyncCallback(ABBClientSendCallback), ABBClientSocket);
            //		}
            //		catch (Exception)
            //		{
            //			ABBClientConnectInforStr = NetError;
            //		}
            //	}
            //}
            //}
            //else if (Info == "IsPlateOK")
            //{
            //	PlateCheck = true;
            //}
            //else
            //{
            //	//CommunicationMsg.AppendText(Info + vbCrLf)
            //}
        }