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: case DataType.SHORT: return(writer.WriteInt16(address, Convert.ToInt16(value))); case DataType.TIME: 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); }