//конвертируем из значения массив байт в соответствии структуре public int[] ConvertToOutput(dynamic inputValue, RegStructure outputRegStruct) { #region output //dynamic outputValue = 0; if (RegTypeAttribute.GetRegType(outputRegStruct) == RegStructType._double) { double outputValue = (double)inputValue; return(BytesToRegs(BitConverter.GetBytes(outputValue), outputRegStruct)); } else if (RegTypeAttribute.GetRegType(outputRegStruct) == RegStructType._float) { float outputValue = (float)inputValue; if (float.IsPositiveInfinity(outputValue)) { outputValue = float.MaxValue; } else if (float.IsNegativeInfinity(outputValue)) { outputValue = float.MinValue; } return(BytesToRegs(BitConverter.GetBytes(outputValue), outputRegStruct)); } else //if (RegTypeAttribute.GetRegType(outputRegStruct) == RegStructType._long) { Int32 outputValue = (Int32)inputValue; return(BytesToRegs(BitConverter.GetBytes(outputValue), outputRegStruct)); } #endregion }
//конвертируем из байт в значение в соответсвии со структурой public dynamic ConvertFromInput(int[] regs, RegStructure inputRegStruct) { dynamic inputValue = 0; if (RegTypeAttribute.GetRegType(inputRegStruct) == RegStructType._double) { //перевести в double а потом в байты ///переименовать в regs to bytes var inputBytes = RegsToBytes(regs, inputRegStruct); inputValue = ToDouble(inputBytes); } else if (RegTypeAttribute.GetRegType(inputRegStruct) == RegStructType._float) { var inputBytes = RegsToBytes(regs, inputRegStruct); inputValue = ToFloat(inputBytes); } else if (RegTypeAttribute.GetRegType(inputRegStruct) == RegStructType._long) { var inputBytes = RegsToBytes(regs, inputRegStruct); inputValue = ToLong(inputBytes); } return(inputValue); }