eip.read()
eip.read(file, offset, bytes) → { status, data }
Reads bytes from a PLC data file.
Reads bytes starting at element offset of the addressed file. Parse the
returned buffer with string.seek() and string.read().
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| file | string | yes | — | File address with type prefix (F,O,I,S,B,T,R,N) + number, e.g. "F103". |
| offset | number | yes | — | Starting element offset within the file. |
| bytes | number | yes | — | Number of bytes to read, e.g. 4*4 for four 32-bit floats. |
Returns
object
{ status, data } — status 0 = success; data is a bin buffer.
Example
let res = eip.read("F103", 1, 4*4); // four 4-byte floats
if(res.status === 0){
res.data.seek(0); // Position our cursor at the start of the data
let plc = {
flow: res.data.read("F32ABCD"),
pressure: res.data.read(), // No format specified, use the last specified format
pumpSpeed: res.data.read(),
temp: res.data.read(),
lastUpdated: now()
};
print(string(plc));
} else {
print("PLC Read Failed");
}