예제 #1
0
        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="e"></param>
        void dataCommunication_DataRecieved(DataRecievedArgs e)
        {
            var buffer = e.Buffer.GetBytes(0xFA, 9);

            while (buffer != null)
            {
                ResponsePackage responsePackage = null;
                //判断数据类型
                int dataType = buffer[1];
                switch (dataType)
                {
                    case ResponseCodes.BendStretchData:
                        responsePackage = GetBendStretchData(buffer, 2);
                        break;
                    case ResponseCodes.RotationData:
                        responsePackage = GetRotationData(buffer, 2);
                        break;
                    case ResponseCodes.OtherData:
                        responsePackage = GetOtherData(buffer, 2);
                        break;
                    case ResponseCodes.Alarm:
                        responsePackage = GetAlarm(buffer, 2);
                        break;
                    case ResponseCodes.Version:
                        responsePackage = GetVersion(buffer, 2);
                        break;
                }

                if (responsePackage != null)
                {
                    if (DataPackRecieved != null)
                    {
                        DataPackReceivedEventArgs args = new DataPackReceivedEventArgs();
                        args.ResponsePackageData = responsePackage;

                        myThreadPool.QueueUserWorkItem((x) => { DataPackRecieved(args); }, null);

                    }
                }

                buffer = e.Buffer.GetBytes(0xFA, 9);
            }
        }
예제 #2
0
        /// <summary>
        /// 传输数据
        /// </summary>
        /// <param name="args"></param>
        void DataCommunication_Move(DataPackReceivedEventArgs args)
        {
            GameRunInfo tinfo = new GameRunInfo();
            if (args.ResponsePackageData.Code == ReciveModel)//屈伸
            {

                ThreadPool.QueueUserWorkItem((x) =>
                {

                if (ReciveModel == ResponseCodes.BendStretchData)
                    {
                        tinfo.RunVlue = args.ResponsePackageData.BendStretchAngle;

                    }
                    else
                    {
                        tinfo.RunVlue = args.ResponsePackageData.RotationAngle;
                    }
                    
                    string runMetaData = JsonConvert.SerializeObject(tinfo);
                    LumbarRobot.ModulesCommon.GlobalVar.SendCommand(runMetaData, LumbarRobot.ModulesCommon.CommandType.GameRunCommand);
                });


            }
            //else if (args.ResponsePackageData.Code == ReciveModel)//旋转
            //{
            //    ThreadPool.QueueUserWorkItem((x) =>
            //    {
            //        List<string> list = new List<string>();
            //        list.Add(args.ResponsePackageData.RotationAngle.ToString());
            //        list.Add(GetJson());
            //        osc.SendMessageToClient<string>("ULTClient", "address/folder", list);

            //    });
            //}
        }
        void controlCommand_DataPackRecieved(DataPackReceivedEventArgs args)
        {
            if (args.ResponsePackageData != null)
            {
                lastReceiveTime = DateTime.Now.Ticks;
                IsConnected = true;

                if (args.ResponsePackageData.Code == ResponseCodes.BendStretchData)
                {
                    CurrentBendStretchAngle = args.ResponsePackageData.BendStretchAngle;
                    if (Move != null && currentControl != null)
                    {
                        //if (currentControl.IsReady)
                        //{
                            
                            if (!LumbarRobotController.RobotController.IsStop
                                && !LumbarRobotController.RobotController.IsPause
                                && RealLine != null)
                            {
                                Move(new PositionArgs(args.ResponsePackageData));

                                if (LumbarRobotController.RobotController.currentControl != null
                                    && (LumbarRobotController.RobotController.currentControl.Action == ActionEnum.Bend
                                    || LumbarRobotController.RobotController.currentControl.Action == ActionEnum.Protrusive
                                    || LumbarRobotController.RobotController.currentControl.Action == ActionEnum.ProtrusiveOrBend))
                                {
                                    realLine.Add(args.ResponsePackageData.BendStretchAngle);

                                    if (args.ResponsePackageData.BendStretchAngle < actionMinAngle)
                                    {
                                        actionMinAngle = args.ResponsePackageData.BendStretchAngle;
                                    }
                                    else if (args.ResponsePackageData.BendStretchAngle > actionMaxAngle)
                                    {
                                        actionMaxAngle = args.ResponsePackageData.BendStretchAngle;
                                    }

                                    if (args.ResponsePackageData.BendStretchAngle < groupActionMinAngle)
                                    {
                                        groupActionMinAngle = args.ResponsePackageData.BendStretchAngle;
                                    }
                                    else if (args.ResponsePackageData.BendStretchAngle > groupActionMaxAngle)
                                    {
                                        groupActionMaxAngle = args.ResponsePackageData.BendStretchAngle;
                                    }

                                    if (args.ResponsePackageData.BendStretchForce > maxForce)
                                    {
                                        maxForce = args.ResponsePackageData.BendStretchForce;
                                    }

                                    sumForce += args.ResponsePackageData.BendStretchForce;
                                    sumForceNum++;

                                    forceLine.Add(args.ResponsePackageData.BendStretchForce * -1);
                                }
                            }
                        //}
                    }
                }
                else if (args.ResponsePackageData.Code == ResponseCodes.RotationData)
                {
                    CurrentRotateAngle = args.ResponsePackageData.RotationAngle;
                    if (Move != null && currentControl != null) 
                    {
                        //if (currentControl.IsReady)
                        //{
                            
                            

                            if (LumbarRobotController.RobotController.currentControl != null
                                        && LumbarRobotController.RobotController.currentControl.Action == ActionEnum.Rotation)
                            {

                                if (!LumbarRobotController.RobotController.IsStop
                                    && !LumbarRobotController.RobotController.IsPause
                                    && RealLine != null)
                                {

                                    Move(new PositionArgs(args.ResponsePackageData));

                                    realLine.Add(args.ResponsePackageData.RotationAngle);

                                    if (args.ResponsePackageData.RotationAngle < actionMinAngle)
                                    {
                                        actionMinAngle = args.ResponsePackageData.RotationAngle;
                                    }
                                    else if (args.ResponsePackageData.RotationAngle > actionMaxAngle)
                                    {
                                        actionMaxAngle = args.ResponsePackageData.RotationAngle;
                                    }

                                    if (args.ResponsePackageData.RotationAngle < groupActionMinAngle)
                                    {
                                        groupActionMinAngle = args.ResponsePackageData.RotationAngle;
                                    }
                                    else if (args.ResponsePackageData.RotationAngle > groupActionMaxAngle)
                                    {
                                        groupActionMaxAngle = args.ResponsePackageData.RotationAngle;
                                    }

                                    if (args.ResponsePackageData.RotationForce > maxForce)
                                    {
                                        maxForce = args.ResponsePackageData.RotationForce;
                                    }

                                    sumForce += args.ResponsePackageData.RotationForce;
                                    sumForceNum++;

                                    forceLine.Add(args.ResponsePackageData.RotationForce);
                                }
                            }

                        //}
                    }
                }
                else if (args.ResponsePackageData.Code == ResponseCodes.OtherData)
                {
                    HomingAngle = args.ResponsePackageData.HomingAngle;
                    PushRodAngle = args.ResponsePackageData.PushRodAngle;
                    LimitSwitchValue = args.ResponsePackageData.LimitSwitch;

                }
                else if (args.ResponsePackageData.Code == ResponseCodes.Alarm)
                {
                    //报警
                    AlarmCode = args.ResponsePackageData.Alarm;

                }
                else if (args.ResponsePackageData.Code == ResponseCodes.Version)
                {
                }

                if (currentControl != null && !IsStop && !IsPause)
                {
                    currentControl.Control(args.ResponsePackageData);
                }
            }
        }