modbus_read_registers


機能

 

ファンクションコード Read Holding Registers (コード03)を用いてholding register領域のレジスタ情報を複数取得します。

 

書式

 

ret =  modbus_read_registers( ctx , addr ,  nb , dest )

 

引数

 

ctx [ VB.NET: IntPtr ] [ C, C++: modbus_t * ] [ C#: IntPtr ] [ Python: ctypes.POINTER(modbus_t) ]

libmodbus構造体へのポインタを指定下さい。

 

addr[ VB.NET: Integer ] [ C, C++: int ] [ C#: int ] [ Python: ctypes.c_int ]

readする先頭アドレスを指定下さい。

 

nb[ VB.NET: Integer ] [ C, C++: int ] [ C#: int ] [ Python: ctypes.c_int ]

読みだすレジスタ数を指定下さい。

 

dest [ VB.NET: UShort() ] [ C, C++: uint16_t * ] [ C#: ushort[] ] [ Python: ctypes.POINTER(ctypes.c_uint16_t) ]

readしたデータを格納する配列のポインタを指定下さい。

 

戻り値

 

ret [ VB.NET:Integer ] [ C, C++: int ] [ C#: int ] [ Python: ctypes.c_int ]

 

成功時には読み取りに成功したレジスタ点数が入ります。

失敗時には-1が入り、以下の errno が設定されます。

 

定義

意味

EMBMDATA

要求データ数が多すぎます。

 

説明

 

ファンクションコード Read Holding Registers (コード03)を用いてholding register領域のレジスタ情報を複数取得します。

 

使用例

 

スタートアドレス0から8点分のデータを取得します。

 

VB.NET

Dim ret As Integer

Dim ctx As IntPtr

Dim dest(8) As UShort

ret = modbus_read_registers(ctx, 0, 8, dest)

 

C, C++

int ret;

modbus_t *ctx;

uint16_t dest[8];

ret = modbus_read_registers( ctx, 0, 8 , dest );

 

C#

int ret;

IntPtr ctx;

ushort[] dest = new ushort[8];

ret = modbus.ReadRegisters(ctx, 0, 8, dest);

 

Python

ret = ctypes.c_int

ctx = ctypes.POINTER(modbus_t)

uint16_buff_type = ctypes.c_uint16 * 8

dest = uint16_buff_type()

ret = modbus.modbus_read_registers(ctx, 0, 8, dest)