Ejemplo n.º 1
0
        private void Client_OnPackageRecieved(object sender, string e)
        {
            var          type = RobotCmdBase.GetCmdTypeFromString(e);
            RobotCmdBase cmd  = null;

            switch (type)
            {
            case EnumRobotCmd.MOVEXYZ:
                cmd = MoveToPosCmd;
                break;

            case EnumRobotCmd.ROTATE:
                cmd = RotateCmd;
                break;

            case EnumRobotCmd.GETCURPOSXYZ:
                cmd = GetCurPosCmd;
                break;

            default:
                break;
            }
            if (cmd != null)
            {
                cmd.O_ReturnObj = e;
                cmd.SetMessageState();
                IsBusy = false;
            }
            ;
        }
Ejemplo n.º 2
0
        private void OnMessageReceived(object sender, string Msg)
        {
            var          type = RobotCmdBase.GetCmdTypeFromString(Msg);
            RobotCmdBase cmd  = null;

            switch (type)
            {
            case EnumRobotCmd.Calibration:
                cmd = CmdCalib;
                break;

            case EnumRobotCmd.MoveToPos:
                cmd = CmdMoveToPos;
                break;

            case EnumRobotCmd.Rotate:
                cmd = CmdRotate;
                break;

            case EnumRobotCmd.StopRobot:
                cmd = CmdStop;
                break;

            default:
                break;
            }
            if (cmd != null)
            {
                cmd.O_ReturnObj = Msg;
                cmd.SetMessageState();
                IsNotBusy = true;
            }
        }
Ejemplo n.º 3
0
 private RobotCmdBase ExcuteCmd(RobotCmdBase cmd, int TimeOut)
 {
     try
     {
         byte[] RecvBuffer = new byte[256];
         if (!Client.IsConnected)
         {
             Open(IP, Port);
         }
         if (Client.IsConnected)
         {
             cmd.ResetMessageState();
             lock (TcpLock)
             {
                 IsBusy = true;
                 Client.Send(cmd.ToByteArray());
             }
             RobotCmdBase cmdClone = cmd.GenEmptyCmd() as RobotCmdBase;
             if (cmd.WaitCmdRecved(TimeOut))
             {
                 if (cmd.O_ReturnObj != null)
                 {
                     cmdClone.FromString(cmd.O_ReturnObj.ToString());
                 }
                 else
                 {
                     throw new Exception($"Error Msg received:{cmd.I_Cmd.ToString()}");
                 }
             }
             else
             {
                 throw new Exception($"Timeout for waiting for Message: {cmd}");
             }
             return(cmdClone);
         }
         return(null);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }