modbus_write_bits


機能

 

ファンクションコード Write Multiple Coils (コード15) を用いてCoil領域へ複数ビット分書き込みます。

 

書式

 

ret =  modbus_write_bits( 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 ]

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

 

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

書き込みbit数を指定下さい。

 

dest [ VB.NET:Byte() ] [ C, C++: uint8_t * ] [ C#: byte[]  ] [ Python: ctypes.POINTER(ctypes.c_uint8) ]

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

 

戻り値

 

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

 

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

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

 

定義

意味

EMBMDATA

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

 

説明

 

Write Multiple Coils (コード15) を用いてCoil領域へ複数ビット分書き込みます。

 

使用例

 

アドレス0から8ビットに1を書き込みます。

 

VB.NET

Dim ret As Integer

Dim ctx As IntPtr

Dim data(8) As Byte

Dim i As Short

For i = 0 To 7

     data(i) = 1

Next i

ret = modbus_write_bits(ctx, 0, 8, data)

 

C, C++

int ret;

modbus_t *ctx;

uint8_t data[8];

short i;

for( i = 0 ; i < 8 ; i++ ){

     data[i] = 1;

}

ret = modbus_write_bits( ctx, 0, 8 , data );

 

C#

int ret;

IntPtr ctx;

byte[] data = new byte[8];

short i;

for( i = 0 ; i < 8 ; i++ ){

     data[i] = 1;

}

ret = modbus.WriteBits(ctx, 0, 8, data);

 

Python

ret = ctypes.c_int

ctx = ctypes.POINTER(modbus_t)

uint8_buff_type = ctypes.c_uint8 * 8

data = uint8_buff_type()

for i in range(8):

       data[i] = 1

ret = modbus.modbus_write_bits(ctx, 0, 8, data)