//设置单片机控制板控制的按键灯 public void SetKeyLedByKey(Board board, ARM_InputPoint Key, LED_State LedState) { IOValue Value = LedState == (LED_State.LED_ON) ? IOValue.IOValueHigh : IOValue.IOValueLow; ARM_OutputPoint KeyLed = ARM_OutputPoint.IO_OUT_LedKeyRun; switch (Key) { case ARM_InputPoint.IO_IN_KeyRun: KeyLed = ARM_OutputPoint.IO_OUT_LedKeyRun; break; case ARM_InputPoint.IO_IN_KeyPause: KeyLed = ARM_OutputPoint.IO_OUT_LedKeyPause; break; case ARM_InputPoint.IO_IN_KeyStop: KeyLed = ARM_OutputPoint.IO_OUT_LedKeyStop; break; case ARM_InputPoint.IO_IN_KeyReset: KeyLed = ARM_OutputPoint.IO_OUT_LedKeyReset; break; default: break; } SetArmControlBoardIo(board, KeyLed, Value); }
//设置单片机控制板的IO public bool SetArmControlBoardIo(Board board, ARM_OutputPoint Io, IOValue Value) { if (!IsBoardConnected(board)) { return(false); } int data1 = 8; //1~8输出口使能控制字节, 最大是0x80 int data2 = 16; int data3 = 24; int data4 = 32; const int CommandIndex = Message.MessageCommandIndex; Message.MakeSendArrayByCode((byte)ArmCommandCode.SetOutput, ref m_SendMeas); //根据Type, Value 设置使能位和数据 int TempIo = (int)Io; int ControlIndex = CommandIndex + 1; byte ControlValue = 0; byte IoData = 0; if (TempIo <= data1) { ControlIndex = CommandIndex + 1; ControlValue = (byte)(0x01 << (TempIo - 1)); IoData = (byte)(((byte)Value) << (TempIo - 1)); } else if (TempIo > data1 && TempIo <= data2) { ControlIndex = CommandIndex + 2; ControlValue = (byte)(0x01 << (TempIo - data1 - 1)); IoData = (byte)(((byte)Value) << (TempIo - data1 - 1)); } else if (TempIo > data2 && TempIo <= data3) { ControlIndex = CommandIndex + 3; ControlValue = (byte)(0x01 << (TempIo - data2 - 1)); IoData = (byte)(((byte)Value) << (TempIo - data2 - 1)); } else if (TempIo > data3 && TempIo <= data4) { ControlIndex = CommandIndex + 4; ControlValue = (byte)(0x01 << (TempIo - data3 - 1)); IoData = (byte)(((byte)Value) << (TempIo - data3 - 1)); } m_SendMeas[ControlIndex] = ControlValue; m_SendMeas[ControlIndex + 4] = IoData; m_SendMeas[Message.MessageSumCheck] = MyMath.CalculateSum(m_SendMeas, Message.MessageLength); m_MyTcpClientArm[(int)board].ClientWrite(m_SendMeas); return(true); }