bin.fromArray()
bin.fromArray(array, format, [byteOrder]) → buffer
Packs an array of numbers or bits into a binary buffer.
Packs an array into binary data. For bit types ("BITS"/"RBITS") the array
holds 1/0 (or true/false) entries — 16 bits pack into two bytes.
The inverse is bin.toArray().
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| array | array | yes | — | Values to pack — numbers, or 1/0 / true/false for bit types. |
| format | string | yes | — | Element type: "F32", "F64", "BITS", "RBITS", "U8", "S8", "U16", "S16", "U32", "S32". |
| byteOrder | string | optional | "ABCD" | Byte order, e.g. "AB", "ABCD", "BADC", "DCBA", "CDAB". Not used by bit types. |
Returns
buffer
Packed binary data ready for modbus.write(), mqtt.publish() or hex conversion.
Example
let data = bin.fromArray([1,2,3,4,5,6,7,8], "U16", "AB");
modbus.write(0, 1, 16, 0, 8, data);
// pack floats, word-swapped
let bytes = bin.fromArray([12345.6789, 100, 200], "F32", "BADC");
// pack a bit array (two bytes)
let flags = bin.fromArray([1,0,0,0,0,0,0,0, 0,1,1,1,1,1,1,1], "RBITS");