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 SendCommandToRunAxisByTransportType(Axis axis, TransportType type, int steps) { int BoardIndex = 0; int AxisIndex = 0; GetMotorBoardAndAxisIndexByAxisType(axis, ref BoardIndex, ref AxisIndex); if (!IsControlerConnected((Board)BoardIndex)) { return; } byte TransportTypeCode = (byte)ControlerCommandCode.SetAxisStepsRef; if (type == TransportType.Absolute) { TransportTypeCode = (byte)ControlerCommandCode.SetAxisStepsAbs; } byte[] temp = new byte[CommunicationProtocol.MessageLength]; CommunicationProtocol.MakeSendArrayByCode(TransportTypeCode, ref temp); int DataIndex = CommunicationProtocol.MessageCommandIndex + 1; temp[DataIndex] = (byte)AxisIndex; temp[DataIndex + 1] = (byte)(steps & 0xffU); temp[DataIndex + 2] = (byte)((steps >> 8) & 0xffU); temp[DataIndex + 3] = (byte)((steps >> 16) & 0xffU); temp[DataIndex + 4] = (byte)((steps >> 24) & 0xffU); temp[CommunicationProtocol.MessageSumCheck] = 0x00; temp[CommunicationProtocol.MessageSumCheck] = MyMath.CalculateSum(temp, CommunicationProtocol.MessageLength); AddCommandMessageToQueue((Board)BoardIndex, (ControlerCommandCode)TransportTypeCode, 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 SendCommandToSetControlBoardOutput(IO_OUT_Type Io, IOValue Value) { int BoardIndex = 0; int IoOutIndex = 0; GetIoOutBoardAndAxisIndexByIO_OUT_Type(Io, ref BoardIndex, ref IoOutIndex); if (!IsControlerConnected((Board)BoardIndex)) { return; } uint outputBuffer = 0; //输出口数据 uint outputEnable = 0; //输出口使能 if (Value == IOValue.High) { outputBuffer |= ((uint)1 << IoOutIndex); } outputEnable |= ((uint)1 << IoOutIndex); byte[] temp = new byte[CommunicationProtocol.MessageLength]; CommunicationProtocol.MakeSendArrayByCode((byte)ControlerCommandCode.SetOutput, ref temp); const int DataIndex = CommunicationProtocol.MessageCommandIndex + 1; temp[DataIndex + 0] = (byte)(outputEnable & 0xffU); temp[DataIndex + 1] = (byte)((outputEnable >> 8) & 0xffU); temp[DataIndex + 2] = (byte)((outputEnable >> 16) & 0xffU); temp[DataIndex + 3] = (byte)((outputEnable >> 24) & 0xffU); temp[DataIndex + 4] = (byte)(outputBuffer & 0xffU); temp[DataIndex + 5] = (byte)((outputBuffer >> 8) & 0xffU); temp[DataIndex + 6] = (byte)((outputBuffer >> 16) & 0xffU); temp[DataIndex + 7] = (byte)((outputBuffer >> 24) & 0xffU); temp[CommunicationProtocol.MessageSumCheck] = 0x00; temp[CommunicationProtocol.MessageSumCheck] = MyMath.CalculateSum(temp, CommunicationProtocol.MessageLength); AddCommandMessageToQueue((Board)BoardIndex, ControlerCommandCode.SetOutput, ref temp); }
public void SendCommandToSetControlBoardOutputByInput(IO_IN_Type Io_In, int Value, IO_OUT_Type Io_Out1, int Out1_Value, IO_OUT_Type Io_Out2, int Out2_Value) { int BoardIndex = 0; int IoInIndex = 0; GetIoInBoardAndAxisIndexByIO_IN_Type(Io_In, ref BoardIndex, ref IoInIndex); int indexBoardOut1 = 0; int IoOut1Index = 0; GetIoOutBoardAndAxisIndexByIO_OUT_Type(Io_Out1, ref indexBoardOut1, ref IoOut1Index); int indexBoardOut2 = 0; int IoOut2Index = 0; GetIoOutBoardAndAxisIndexByIO_OUT_Type(Io_Out2, ref indexBoardOut2, ref IoOut2Index); if (!IsControlerConnected((Board)BoardIndex)) { return; } byte[] temp = new byte[CommunicationProtocol.MessageLength]; CommunicationProtocol.MakeSendArrayByCode((byte)ControlerCommandCode.SetOutputByInput, ref temp); const int DataIndex = CommunicationProtocol.MessageCommandIndex + 1; temp[DataIndex + 0] = (byte)IoInIndex; temp[DataIndex + 1] = (byte)Value; temp[DataIndex + 2] = (byte)IoOut1Index; temp[DataIndex + 3] = (byte)Out1_Value; temp[DataIndex + 4] = (byte)IoOut2Index; temp[DataIndex + 5] = (byte)Out2_Value; temp[CommunicationProtocol.MessageSumCheck] = 0x00; temp[CommunicationProtocol.MessageSumCheck] = MyMath.CalculateSum(temp, CommunicationProtocol.MessageLength); AddCommandMessageToQueue((Board)BoardIndex, ControlerCommandCode.SetOutputByInput, ref temp); }
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); } }