public static byte[] configurationToByteArray(INNCOM_CONF_LIST com) { int intValue = (int)com; byte[] intBytes = BitConverter.GetBytes(intValue); byte[] result = new byte[2]; Array.Copy(intBytes, result, 2); if (BitConverter.IsLittleEndian) { Array.Reverse(result); } return(result); }
private void readConfiguartion() { /* * Read Configuration */ INNCOM_CONF_LIST param = (INNCOM_CONF_LIST)tCmb_Param.SelectedItem; byte[] result = QuattroProtocol.sendCommand(INNCOM_COMMAND_LIST.COMM_CMD_READ_CONFIG, DeviceConfiguration.configurationToByteArray(param), ref err, 300); if (err != ERROR_LIST.ERROR_NONE) { tTxt_Logs.AppendText("ERROR - Read Configurations"); tTxt_Logs.AppendText(Environment.NewLine); return; } int offset = (int)PACKET_CONF.COMM_POS_PAYLOAD + 3; byte[] value = QuattroProtocol.getResponseValueData(result); int type = result[offset]; byte[] IDA = new byte[2]; Array.Copy(value, 0, IDA, 0, 2); string ID = BitConverter.ToString(IDA).Replace("-", string.Empty); byte[] ParamValue = new byte[value.Length - IDA.Length]; Array.Copy(value, IDA.Length, ParamValue, 0, value.Length - IDA.Length); string str = ""; switch (type) { case (int)PARAMETER_TYPE.PARAM_TYPE_STR: { str = Encoding.Default.GetString(ParamValue).Trim('\0'); break; }; case (int)PARAMETER_TYPE.PARAM_TYPE_U8: { str = (ParamValue, 0).ToString(); break; } case (int)PARAMETER_TYPE.PARAM_TYPE_U8A: { str = Encoding.Default.GetString(ParamValue).Trim('\0'); break; } case (int)PARAMETER_TYPE.PARAM_TYPE_S8: { str = Convert.ToSByte(ParamValue[0]).ToString(); break; } case (int)PARAMETER_TYPE.PARAM_TYPE_U32: { if (ParamValue.Length < 4) { byte[] temp = new byte[4 - ParamValue.Length]; ParamValue = Utility.mergeByteArray(temp, ParamValue); } str = Utility.getU32FromByteA(ParamValue, 0).ToString(); break; } case (int)PARAMETER_TYPE.PARAM_TYPE_U16: { if (ParamValue.Length == 1) { byte[] temp = new byte[1]; ParamValue = Utility.mergeByteArray(temp, ParamValue); } str = Utility.getU16FromByteA(ParamValue, 0).ToString(); break; } case (int)PARAMETER_TYPE.PARAM_TYPE_F32: { if (ParamValue.Length < 4) { byte[] temp = new byte[4 - ParamValue.Length]; ParamValue = Utility.mergeByteArray(temp, ParamValue); } str = Utility.getF32FromByteA(ParamValue, 0).ToString(); break; } default: { str = BitConverter.ToString(ParamValue).Replace("-", string.Empty); break; } } tTxt_Logs.AppendText("Parameter ID : 0x" + ID + " , Value : " + str); tTxt_Logs.AppendText(Environment.NewLine); }