eip.handle()
eip.handle(handler)
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. |
Example
eip.handle(function(req){ // handle incoming EtherNet/IP requests
if(req.data){ // write request
req.data.seek(0);
let status = req.data.read("U16AB");
io.PALL = {
feedEnable: status & 1,
masterAlarm: (status & (1<<5)) > 0,
flowAvailable: req.data.read("U16AB") / 0.2777778
};
} else { // read request — build and return a reply
let buff = bin.alloc(100);
buff.write("BIT", [0, io.p304.running, io.p303.running, 0,0,0,0,0, 0,0,0,0,0,0,0,0]);
buff.write("U16AB", [151.2 * 0.2777778, io.clearwellLevel701.inst * 10]);
return buff;
}
});