Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/controller/controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,15 @@ describe("Controller Class", () => {
const plc = new Controller({ queue_max_size: 200 });
expect(plc.workers.read.max).toEqual(200);
});

it("Default Unconnected Send timeout", () => {
const plc = new Controller();
expect(plc.params.unconnected_send_timeout).toEqual(2000);
});

it("Custom Unconnected Send timeout", () => {
const plc = new Controller({ unconnected_send_timeout: 5064 });
expect(plc.params.unconnected_send_timeout).toEqual(5064);
});
});
});
13 changes: 11 additions & 2 deletions src/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ const compare = (obj1, obj2) => {
};

class Controller extends ENIP {
constructor({ queue_max_size } = {}) {

/**
*
* @param {object} [options]
* @param {number} [options.queue_max_size=100] the maximum size for the command queue length
* @param {number} [options.unconnected_send_timeout=2000] the timeout value of messages of type "unconnected send"
*/
constructor({ queue_max_size, unconnected_send_timeout = 2000 } = {}) {
super();

this.state = {
Expand Down Expand Up @@ -41,6 +48,8 @@ class Controller extends ENIP {
write: new Queue(compare, queue_max_size),
group: new Queue(compare, queue_max_size)
};

this.params = { unconnected_send_timeout };
}

// region Property Definitions
Expand Down Expand Up @@ -143,7 +152,7 @@ class Controller extends ENIP {
write_cip(data, connected = false, timeout = 10, cb = null) {
const { UnconnectedSend } = CIP;

const msg = UnconnectedSend.build(data, this.state.controller.path);
const msg = UnconnectedSend.build(data, this.state.controller.path, this.params.unconnected_send_timeout);

//TODO: Implement Connected Version
super.write_cip(msg, connected, timeout, cb);
Expand Down