The eip object speaks EtherNet/IP in both directions:
Client β eip.connect() / eip.read() read PLC data files. Files are
addressed by a type prefix and number β F, O, I, S, B, T, R,
N depending on type (e.g. "F103" for float file 103). Returned data is
a packed binary buffer parsed with the bin reader functions.
Server β eip.handle() answers incoming EtherNet/IP read and write
requests from a PLC, letting the device appear as a data file the PLC polls
and commands directly.
Functions
eip.connect() β Connects to a PLC over EtherNet/IP.
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");
}
Answers incoming EtherNet/IP read and write requests from a PLC.
Registers a handler for EtherNet/IP requests arriving at the device. The
request object provides:
Field
Meaning
req.file
The requested file address (e.g. "F103").
req.bytes
Read requests: the byte length of the requested data.
req.data
Write requests: a bin buffer with the written data. Absent on reads.
Write requests (req.data present): parse the buffer with
req.data.seek() / req.data.read() and apply the values β e.g. unpack a
PLC status word into individual io flags with bit masks.
Read requests: build a response with bin.alloc() and the buffer write
methods (including the "BIT" format for packing status bits), then
return the buffer.
Arguments
Name
Type
Required
Default
Description
handler
function
yes
β
Callback function(req){ β¦ } β return a bin buffer to answer read requests.