modbus_read_bits


機能

 

ファンクションコード Read Coils (コード01)を用いてCoil領域のビット情報を複数取得します。

 

書式

 

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

 

引数

 

ctx [ C: modbus_t * ] [ Python: ctypes.POINTER(modbus_t) ]

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

 

addr [ C: int ] [ Python: ctypes.c_int ]

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

 

nb [ C: int ] [ Python: ctypes.c_int ]

読みだすbit数を指定下さい。

 

dest [ C: uint8_t * ] [ Python: ctypes.POINTER(ctypes.c_uint8) ]

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

 

戻り値

 

ret [ C: int ] [ Python: ctypes.c_int ]

 

成功時には読み取りに成功したビット点数が入ります。

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

 

定義

意味

EMBMDATA

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

 

説明

 

ファンクションコード Read Coils (コード01)を用いてCoil領域のビット情報を複数取得します。

 

使用例

 

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

 

C

int ret;

modbus_t *ctx;

uint8_t dest[8];

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

 

Python

ret = ctypes.c_int

ctx = ctypes.POINTER(modbus_t)

uint8_buff_type = ctypes.c_uint8 * 8

dest = uint8_buff_type()

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