INGEAR.NET.MBLINK

 

Tag.Value Property

Gets / Sets the MODBUS device register value

[Visual Basic]
NotOverridable Public Property Value As Object _
    Implements ITag.Value
[C#]
public object Value {get; set;}

Property Value

Object value

Implements

ITag.Value

Remarks

Reading Values:

When reading from the MODBUS device, you need to specify the DataType for the value being read.

Default data types for registers as follows:

The Length property determines the number of continguous number of registers read. The .Value propery will be returned as a Array of the specified .DataType

Writing Values: When setting the .Value for writing, the Type of the Object will be assigned to the MODBUS device. See Tag.ATOMIC for supported data types.

Error Condition: When an error occurs the .Value property will be returned as a null reference (Nothing in Visual Basic)

Exceptions

Exception Type Condition
ArgumentNullException Thrown if Value property is a null reference (Nothing in Visual Basic) when setting.
ArgumentException Thrown if Value property is an unsupported NetType

Example

VB
Imports MBLink
' * reading
Dim MBDevice As New Controller("192.168.1.45")
Dim MyTag As New Tag("40001")
' * read 40001 as System.Int16 (default)
MBDevice.ReadTag(MyTag)
Console.WriteLine(MyTag.Value.ToString())
' * read 40001 as System.Int32
MyTag.DataType = ATOMIC.INT
MBDevice.ReadTag(MyTag)
Console.WriteLine(MyTag.Value.ToString())
' * read 40001 as System.Single
MyTag.DataType = ATOMIC.REAL
MBDevice.ReadTag(MyTag)
Console.WriteLine(MyTag.Value.ToString())
' * reading 40001 as an array
MyTag.DataType = ATOMIC.INT
MyTag.Length = 100
MBDevice.ReadTag(MyTag)
' * writing System.Int16
Dim _plcValue As System.Int
_plcValue = 123
MyTag.Value = _plcValue
MBDevice.WriteTag(MyTag)
C#
unsing MBLink
// reading
Controller MBDevice = new Controller("192.168.1.45");
Tag MyTag = new Tag("40001");
// read 40001 as System.Int16 (default)
MBDevice.ReadTag(MyTag);
Console.WriteLine(MyTag.Value.ToString());
// read 40001 as System.Int32
MyTag.DataType = ATOMIC.INT;
MBDevice.ReadTag(MyTag);
Console.WriteLine(MyTag.Value.ToString());
// read 40001 as System.Single
MyTag.DataType = ATOMIC.REAL;
MBDevice.ReadTag(MyTag);
Console.WriteLine(MyTag.Value.ToString());
// reading 40001 as an array
MyTag.DataType = ATOMIC.INT;
MyTag.Length = 100;
MBDevice.ReadTag(MyTag);
// writing System.Int16
System.Int16 _plcValue
_plcValue = 123;
MyTag.Value = _plcValue;
MBDevice.WriteTag(MyTag);

See Also

Tag Class | MBLink Namespace | ErrorCode | ErrorString | QualityCode | QualityString