public void SendCommandToRunAxis(Axis axis, ControlerCommandCode Code, AxisDir Dir) { int BoardIndex = 0; int AxisIndex = 0; GetMotorBoardAndAxisIndexByAxisType(axis, ref BoardIndex, ref AxisIndex); if (!IsControlerConnected((Board)BoardIndex)) { return; } byte[] temp = new byte[CommunicationProtocol.MessageLength]; CommunicationProtocol.MakeSendArrayByCode((byte)Code, ref temp); temp[CommunicationProtocol.MessageCommandIndex + 1] = (byte)AxisIndex; if (Dir == AxisDir.Forward) { temp[CommunicationProtocol.MessageCommandIndex + 2] = 0x00; } else { temp[CommunicationProtocol.MessageCommandIndex + 2] = 0x01; } temp[CommunicationProtocol.MessageSumCheck] = 0x00; temp[CommunicationProtocol.MessageSumCheck] = MyMath.CalculateSum(temp, CommunicationProtocol.MessageLength); AddCommandMessageToQueue((Board)BoardIndex, Code, ref temp); }
public void SendCommandToControler(Board BoardIndex, ControlerCommandCode Code) { if (IsControlerConnected(BoardIndex)) { byte[] temp = new byte[CommunicationProtocol.MessageLength]; CommunicationProtocol.MakeSendArrayByCode((byte)Code, ref temp); AddCommandMessageToQueue(BoardIndex, Code, ref temp); } }
public bool SendCommandToSetSpeedParam(Axis axis, int velLow, int velHigh, int acc, int dec, bool Default) { int BoardIndex = 0; int AxisIndex = 0; GetMotorBoardAndAxisIndexByAxisType(axis, ref BoardIndex, ref AxisIndex); if (!IsControlerConnected((Board)BoardIndex)) { return(false); } ControlerCommandCode Code = Default ? ControlerCommandCode.SetAxisParametersDefault : ControlerCommandCode.SetAxisParameters; byte[] temp = new byte[CommunicationProtocol.MessageLength]; CommunicationProtocol.MakeSendArrayByCode((byte)Code, ref temp); int DataIndex = CommunicationProtocol.MessageCommandIndex + 1; temp[DataIndex] = (byte)AxisIndex; temp[DataIndex + 1] = (byte)(velLow & 0xffU); temp[DataIndex + 2] = (byte)((velLow >> 8) & 0xffU); temp[DataIndex + 3] = (byte)((velLow >> 16) & 0xffU); temp[DataIndex + 4] = (byte)((velLow >> 24) & 0xffU); temp[DataIndex + 5] = (byte)(velHigh & 0xffU); temp[DataIndex + 6] = (byte)((velHigh >> 8) & 0xffU); temp[DataIndex + 7] = (byte)((velHigh >> 16) & 0xffU); temp[DataIndex + 8] = (byte)((velHigh >> 24) & 0xffU); temp[DataIndex + 9] = (byte)(acc & 0xffU); temp[DataIndex + 10] = (byte)((acc >> 8) & 0xffU); temp[DataIndex + 11] = (byte)((acc >> 16) & 0xffU); temp[DataIndex + 12] = (byte)((acc >> 24) & 0xffU); temp[DataIndex + 13] = (byte)(dec & 0xffU); temp[DataIndex + 14] = (byte)((dec >> 8) & 0xffU); temp[DataIndex + 15] = (byte)((dec >> 16) & 0xffU); temp[DataIndex + 16] = (byte)((dec >> 24) & 0xffU); temp[CommunicationProtocol.MessageSumCheck] = 0x00; temp[CommunicationProtocol.MessageSumCheck] = MyMath.CalculateSum(temp, CommunicationProtocol.MessageLength); AddCommandMessageToQueue((Board)BoardIndex, ControlerCommandCode.SetAxisParametersDefault, ref temp); return(true); }
public void SendCommandToControlerWithAxis(Axis axis, ControlerCommandCode Code) { if (axis >= Axis.Total) { return; } int BoardIndex = 0; int AxisIndex = 0; GetMotorBoardAndAxisIndexByAxisType(axis, ref BoardIndex, ref AxisIndex); if (IsControlerConnected((Board)BoardIndex)) { byte[] temp = new byte[CommunicationProtocol.MessageLength]; CommunicationProtocol.MakeSendArrayByCode((byte)Code, ref temp); temp[CommunicationProtocol.MessageCommandIndex + 1] = (byte)AxisIndex; temp[CommunicationProtocol.MessageSumCheck] = 0x00; temp[CommunicationProtocol.MessageSumCheck] = MyMath.CalculateSum(temp, CommunicationProtocol.MessageLength); AddCommandMessageToQueue((Board)BoardIndex, Code, ref temp); } }
public void AddCommandMessageToQueue(Board boardIndex, ControlerCommandCode Code, ref byte[] Command) { switch (Code) { //设置相关的指令 case ControlerCommandCode.SetOutput: case ControlerCommandCode.SetOutputByInput: case ControlerCommandCode.SetOutputDefault: case ControlerCommandCode.SetAxisParametersDefault: case ControlerCommandCode.SetAxisParameters: case ControlerCommandCode.SetAxisStepsAbs: case ControlerCommandCode.SetAxisStepsRef: case ControlerCommandCode.SetAxisMoveContinuous: case ControlerCommandCode.SetAxisStepsMax: case ControlerCommandCode.StopAxis: case ControlerCommandCode.ResetAxisError: case ControlerCommandCode.AxisGoHome: case ControlerCommandCode.SetIp: case ControlerCommandCode.SetVersionHardware: case ControlerCommandCode.ResetFactory: { if (m_MyTcpClient[(int)boardIndex].IsConnected) { m_MyTcpClient[(int)boardIndex].m_SetCommandQueue.Enqueue(Command); } } break; //“获取”相关的指令 case ControlerCommandCode.GetOutput: case ControlerCommandCode.GetInput: case ControlerCommandCode.GetAxisParameters: case ControlerCommandCode.GetAxisStepsAbs: case ControlerCommandCode.GetAxisState: case ControlerCommandCode.GetBoardInformation: { if (m_MyTcpClient[(int)boardIndex].IsConnected) { if (m_MyTcpClient[(int)boardIndex].m_GetCommandQueue.Count == 0) { m_MyTcpClient[(int)boardIndex].m_GetCommandQueue.Enqueue(Command); } else { bool AddToDequeue = true; foreach (var temp in m_MyTcpClient[(int)boardIndex].m_GetCommandQueue) { if (MyMath.IsEquals(temp, Command)) //避免加入的相同的指令过多 { AddToDequeue = false; break; } } if (AddToDequeue) { m_MyTcpClient[(int)boardIndex].m_GetCommandQueue.Enqueue(Command); } } } } break; default: break; } }