public static int WriteValueEx(this IReaderWriter writer, DeviceAddress address, object value) { switch (address.VarType) { case DataType.BOOL: return(writer.WriteBit(address, Convert.ToBoolean(value))); case DataType.BYTE: return(writer.WriteBits(address, Convert.ToByte(value))); case DataType.WORD: return(writer.WriteUInt16(address, Convert.ToUInt16(value))); case DataType.SHORT: return(writer.WriteInt16(address, Convert.ToInt16(value))); case DataType.DWORD: return(writer.WriteUInt32(address, Convert.ToUInt32(value))); case DataType.INT: return(writer.WriteInt32(address, Convert.ToInt32(value))); case DataType.FLOAT: return(writer.WriteFloat(address, Convert.ToSingle(value))); case DataType.STR: return(writer.WriteString(address, value.ToString())); } return(-1); }