You are on page 1of 9

ReadCoilStatus

Pgina 1 de 9

Method ReadCoilStatus

Description

Function 01 (0x01). 0X references.


This function is used to read from 1 to 1968 contiguous status of coils in a slave
device read. Coils are addressed starting at zero. Therefore coils 1-16 are addressed as
0-15.

Syntax

Visual Basic
Function ReadCoilStatus (Handle As Integer, SlaveID As Integer, Address As Long,
Quantity As Integer, UpdateRate As Long) As Boolean
Visual C++
BOOL ReadCoilStatus (short Handle, short SlaveID, long Address, short Quantity,
long UpdateRate);

Parameters

Handle: Transaction Handle. 0 to 199.


SlaveID: The slave ID. 1 to 255.
Address: The data address. 0 to 65535.
Quantity: The number of coils to read. 1 to 1968
UpdateRate: 1 to 600000ms

Return

If the function succeeds, the return value is nonzero.


If the function fails, the return value is zero.

Example

Read 10 coils starting from address 00005 from slave ID 3. Read every 700ms
Dim e As Integer
Private Sub Command1_Click()
e = Mbaxp1.ReadCoilStatus(1, 3, 4, 10, 700)
Mbaxp1.UpdateEnable (1) 'Start continuously update
End Sub
Private Sub Mbaxp1_ResultOk(ByVal Handle As Integer)
If Handle = 1 Then
Label1 = Mbaxp1.Coil(1, 0) 'Write the content of
End If
'00005 to Label1
End Sub

Method ReadInputStatus

file://C:\Users\Jorge\AppData\Local\Temp\~hh7DCC.htm

28/08/2016

ReadCoilStatus

Description

Pgina 2 de 9

Function 02 (0x02). 1X references.


This function is used to read from 1 to 1968 contiguous status of inputs in a slave
device read. Inputs are addressed starting at zero. Therefore inputs 1-16 are addressed
as 0-15.

Syntax

Visual Basic
Function ReadInputStatus (Handle As Integer, SlaveID As Integer, Address As Long,
Quantity As Integer, UpdateRate As Long) As Boolean
Visual C++
BOOL ReadInputStatus (short Handle, short SlaveID, long Address, short Quantity,
long UpdateRate);

Parameters

Handle: Transaction Handle. 0 to 199.


SlaveID: The slave ID. 1 to 255.
Address: The data address. 0 to 65535.
Quantity: The number of inputs to read. 1 to 1968
UpdateRate: 1 to 600000ms

Return

If the function succeeds, the return value is nonzero.


If the function fails, the return value is zero.

Example

Read 10 inputs starting from address 10005 from slave ID 3. Read every 700ms
Dim e As Integer
Private Sub Command1_Click()
e = Mbaxp1.ReadInputStatus(1, 3, 4, 10, 700)
Mbaxp1.UpdateEnable (1) 'Start continuously update
End Sub
Private Sub Mbaxp1_ResultOk(ByVal Handle As Integer)
If Handle = 1 Then
Label1 = Mbaxp1.Coil(1, 0) 'Write the content of
End If
'10005 to Label1
End Sub

Method ReadHoldingRegisters

Description

Function 03 (0x03). 4X references.


This function code is used to read from 1 to 125 contiguous holding registers in a slave
device. Registers are addressed starting at zero. Therefore registers 1-16 are addressed

file://C:\Users\Jorge\AppData\Local\Temp\~hh7DCC.htm

28/08/2016

ReadCoilStatus

Pgina 3 de 9

as 0-15.

Syntax

Visual Basic
Function ReadHoldingRegisters (Handle As Integer, SlaveID As Integer, Address As
Long, Quantity As Integer, UpdateRate As Long) As Boolean
Visual C++
BOOL ReadHoldingRegisters (short Handle, short SlaveID, long Address, short
Quantity, long UpdateRate);

Parameters

Handle: Transaction Handle. 0 to 199.


SlaveID: The slave ID. 1 to 255.
Address: The data address. 0 to 65535.
Quantity: The number of registers to read. 1 to 125
UpdateRate: 1 to 600000ms

Return

If the function succeeds, the return value is nonzero.


If the function fails, the return value is zero.

Example

Read 10 holding registers starting from address 40005 from slave ID 3. Read every
700ms
Dim e As Integer
Private Sub Command1_Click()
e = Mbaxp1.ReadHoldingRegisters(1, 3, 4, 10, 700)
Mbaxp1.UpdateEnable (1) 'Start continuously update
End Sub
Private Sub Mbaxp1_ResultOk(ByVal Handle As Integer)
If Handle = 1 Then
Label1 = Mbaxp1.Register(1, 0) 'Write the content of
End If
'40005 to Label1
End Sub

Method ReadInputRegisters

Description

Function 04 (0x04). 3X references.


This function code is used to read from 1 to 125 contiguous input registers in a slave
device. Registers are addressed starting at zero. Therefore registers 1-16 are addressed
as 0-15.

file://C:\Users\Jorge\AppData\Local\Temp\~hh7DCC.htm

28/08/2016

ReadCoilStatus

Syntax

Pgina 4 de 9

Visual Basic
Function ReadInputRegisters (Handle As Integer, SlaveID As Integer, Address As
Long, Quantity As Integer, UpdateRate As Long) As Boolean
Visual C++
BOOL ReadInputRegisters (short Handle, short SlaveID, long Address, short
Quantity, long UpdateRate);

Parameters

Handle: Transaction Handle. 0 to 199.


SlaveID: The slave ID. 1 to 255.
Address: The data address. 0 to 65535.
Quantity: The number of registers to read. 1 to 125
UpdateRate: 1 to 600000ms

Return

If the function succeeds, the return value is nonzero.


If the function fails, the return value is zero.

Example

Read 10 input registers starting from address 30005 from slave ID 7. Read every
500ms
Dim e As Integer
Private Sub Command1_Click()
e = Mbaxp1.ReadInputRegisters(1, 7, 4, 10, 500)
Mbaxp1.UpdateEnable (1) 'Start continuously update
End Sub
Private Sub Mbaxp1_ResultOk(ByVal Handle As Integer)
If Handle = 1 Then
Label1 = Mbaxp1.Register(1, 0) 'Write the content of
End If
'30005 to Label1
End Sub

Method ForceSingleCoil

Description

Function 05 (0x05). 0X references.


This function code is used to force a single coil to either ON or OFF in a slave device.

Syntax

Visual Basic
Function ForceSingleCoil (Handle As Integer, SlaveID As Integer, Address As Long,
UpdateRate As Long) As Boolean
Visual C++

file://C:\Users\Jorge\AppData\Local\Temp\~hh7DCC.htm

28/08/2016

ReadCoilStatus

Pgina 5 de 9

BOOL ForceSingleCoil (short Handle, short SlaveID, long Address, long


UpdateRate);

Parameters

Handle: Transaction Handle. 0 to 199.


SlaveID: The slave ID. 0 to 255.
Address: The data address. 0 to 65535.
UpdateRate: 1 to 600000ms

Return

If the function succeeds, the return value is nonzero.


If the function fails, the return value is zero.

Example

Turn on coil 10007 in slave 2


Dim e As Integer
Private Sub Command1_Click()
e = Mbaxp1.OpenConnection()
e = Mbaxp1.ForceSingleCoil(1, 2, 7, 700)
Mbaxp1.Coil(1, 0) = TRUE 'Internal array = the value write
Mbaxp1.UpdateOnce (1)
'Execute once
End Sub
Private Sub Mbaxp1_ResultOk(ByVal Handle As Integer)
If Handle = 1 Then
Label1 = "Success" 'Force single coil success
End If
End Sub

Method PresetSingleRegister

Description

Function 06 (0x06). 4X references.


This function code is used to write a single holding register in a slave device.

Syntax

Visual Basic
Function PresetSingleRegister (Handle As Integer, SlaveID As Integer, Address As
Long, UpdateRate As Long) As Booleean
Visual C++
BOOL PresetSingleRegister (short Handle, short SlaveID, long Address, long
UpdateRate);

Parameters

Handle: Transaction Handle. 0 to 199.

file://C:\Users\Jorge\AppData\Local\Temp\~hh7DCC.htm

28/08/2016

ReadCoilStatus

Pgina 6 de 9

SlaveID: The slave ID. 0 to 255.


Address: The data address. 0 to 65535.
UpdateRate: 1 to 600000ms

Return

If the function succeeds, the return value is nonzero.


If the function fails, the return value is zero.

Example

Write a incremented value to address 40007 in slave 2 and 3 every 1000ms


Dim e As Integer
Dim v1 As Integer
Dim v2 As Integer
Private Sub Command1_Click()
v1 = 0
v2 = 0
e = Mbaxp1.PresetSingleRegister(1, 2, 7, 1000)
e = Mbaxp1.PresetSingleRegister(2, 3, 7, 1000)
Mbaxp1.Register(1, 0) = v1 'Internal array 1,0
Mbaxp1.Register(2, 0) = v2 'Internal array 2,0
Mbaxp1.UpdateEnable (1)
'Continuously update
Mbaxp1.UpdateEnable (2)
'Continuously update
End Sub

'Use handle
'Use handle
= the value
= the value

1
2
to write
to write

Private Sub Mbaxp1_ResultOk(ByVal Handle As Integer)


If Handle = 1 Then
Label1 = "Success 2" 'Preset Single Register success
v1 = v1 + 1
'increment v1
Mbaxp1.Register(1, 0) = v1 'The incremented v1 is written next time
End If
If Handle = 2 Then
Label2 = "Success 3" 'Preset Single Register success
v2 = v2 + 3
'increment v2
Mbaxp1.Register(2, 0) = v2 'The incremented v2 is written next time
End If
End Sub

Method ForceMultipleCoils

Description

Function 15 (0x0F). 0X references.


This function code is used to force each coil in a sequence of 1 to 1968 coils to either
ON or OFF in a slave device. Coils are addressed starting at zero. Therefore coil 1 is
addressed as 0.

Syntax

Visual Basic
Function ForceMultipleCoils (Handle As Integer, SlaveID As Integer, Address As
Long, Quantity As Integer, UpdateRate As Long) As Integer.

file://C:\Users\Jorge\AppData\Local\Temp\~hh7DCC.htm

28/08/2016

ReadCoilStatus

Pgina 7 de 9

Visual C++
short ForceMultipleCoils (short Handle, short SlaveID, long Address, short Quantity,
long UpdateRate);

Parameters

Handle: Transaction Handle. 0 to 199.


SlaveID: The slave ID. 0 to 255.
Address: The data address. 0 to 65535.
Quantity: The number of coils to force. 1 to 1968
UpdateRate: 1 to 600000ms

Return

If the function succeeds, the return value is nonzero.


If the function fails, the return value is zero.

Example

Turn off/on coils 00003 through 00007 slave ID 7.


Dim e As Integer
Private Sub Command1_Click()
e = Mbaxp1.OpenConnection()
e = Mbaxp1.ForceMultipleCoils(1, 7, 2, 4, 1000)
Mbaxp1.Coil(1, 0) = 0 'Turn off coil 00003
Mbaxp1.Coil(1, 1) = 1 'Turn on coil 00004
Mbaxp1.Coil(1, 2) = 0
Mbaxp1.Coil(1, 3) = 1
Mbaxp1.UpdateOnce (1) 'Force the coils
End Sub
Private Sub Mbaxp1_ResultOk(ByVal Handle As Integer)
If Handle = 1 Then
Mbaxp1.Coil(1, 0) = 1 'Prepare 4 new values
Mbaxp1.Coil(1, 1) = 0
Mbaxp1.Coil(1, 2) = 1
Mbaxp1.Coil(1, 3) = 0
Mbaxp1.UpdateOnce (1) 'Force the coils
End If
End Sub

Method PresetMultipleRegisters

Description

Function 16 (0x0F). 4X references.


This function code is used to write from 1 to 123 contiguous holding registers in a
slave device. Registers are addressed starting at zero. Therefore registers 1-16 are
addressed as 0-15.

file://C:\Users\Jorge\AppData\Local\Temp\~hh7DCC.htm

28/08/2016

ReadCoilStatus

Syntax

Pgina 8 de 9

Visual Basic
Function PresetMultipleRegisters (Handle As Integer, SlaveID As Integer, Address
As Long, Quantity As Integer, UpdateRate As Long) As Boolean
Visual C++
BOOL PresetMultipleRegisters (short Handle, short SlaveID, long Address, short
Quantity, long UpdateRate);

Parameters

Handle: Transaction Handle. 0 to 199.


SlaveID: The slave ID. 0 to 255.
Address: The data address. 0 to 65535.
Quantity: The number of registers to write. 1 to 123
UpdateRate: 1 to 600000ms

Return

If the function succeeds, the return value is nonzero.


If the function fails, the return value is zero.

Example

Preset 4 holding registers starting from address 40003 in slave ID 9. Read every
1000ms
Dim e As Integer
Private Sub Command1_Click()
e = Mbaxp1.PresetMultipleRegisters(1, 9, 2, 4, 1000)
Mbaxp1.Register(1, 0) = 1
Mbaxp1.Register(1, 1) = 2
Mbaxp1.Register(1, 2) = 4
Mbaxp1.Register(1, 3) = 8
Mbaxp1.UpdateEnable (1) 'Start continuously update
End Sub
Private Sub Mbaxp1_ResultOk(ByVal Handle As Integer)
If Handle = 1 Then
Mbaxp1.Register(1, 0) = 8532 'Write 4 new values
Mbaxp1.Register(1, 1) = 535
Mbaxp1.Register(1, 2) = 8532
Mbaxp1.Register(1, 3) = 532
End If
End Sub

Method ReadWriteMultipleRegisters

Description

Function 23 (0x17). 4X references.


This function performs a combination of one read operation and one write operation in
a single MODBUS transaction. Holding registers are addressed starting at zero.

file://C:\Users\Jorge\AppData\Local\Temp\~hh7DCC.htm

28/08/2016

ReadCoilStatus

Pgina 9 de 9

Therefore holding registers 1-16 are addressed as 0-15. The request specifies the
starting address and number of holding registers to be read as well as the starting
address, number of holding registers, and the data to be written.

Syntax

Visual Basic
Function ReadWriteMultipleRegisters (Handle As Integer, SlaveID As Integer,
ReadAddress As Long, ReadQuantity As Integer, WriteAddress As Long,
WriteQuantity As Integer, UpdateRate As Long) As Boolean
Visual C++
BOOL ReadWriteMultipleRegisters (short Handle, short SlaveID, long
ReadAddress, short ReadQuantity, long WriteAddress, short WriteQuantity, long
UpdateRate);

Parameters

Handle: Transaction Handle. 0 to 199.


SlaveID: The slave ID. 1 to 255.
ReadAddress: The data address. 0 to 65535.
ReadQuantity: The number of registers to read. 1 to 125
WriteAddress: The data address. 0 to 65535.
WriteQuantity: The number of registers to write. 1 to 121
UpdateRate: 1 to 600000ms

Return

If the function succeeds, the return value is nonzero.


If the function fails, the return value is zero.

Example

Read 7 values from register 40007 through 40013 in slave ID 7.


Write 3 values to register 40002 through 40004 in slave ID 7.
Dim e As Integer
Private Sub Command1_Click()
e = Mbaxp1.OpenConnection()
e = Mbaxp1.ReadWriteMultipleRegisters(1, 7, 6, 7, 1, 3, 1000)
Mbaxp1.Register(1, 0) = 7
Mbaxp1.Register(1, 1) = 123
Mbaxp1.Register(1, 2) = 654
Mbaxp1.UpdateOnce (1) '
End Sub
Private Sub Mbaxp1_ResultOk(ByVal Handle As Integer)
If Handle = 1 Then
Label1 = Mbaxp1.Register(1, 0) 'Write the content of
End If
'40007 to Label1
End Sub

file://C:\Users\Jorge\AppData\Local\Temp\~hh7DCC.htm

28/08/2016

You might also like