<commit_before># node-drivers

Supports callbacks and async/await.

# Install

```sh
npm install node-drivers
```

# Examples

### 1. Communicate with a Logix5000 processor:

```javascript
const { Layers } = require('node-drivers');

const tcpLayer = new Layers.TCP({ host: '0.0.0.0', port: 44818 });
const eipLayer = new Layers.EIP(tcpLayer);
const cipConnection = new Layers.CIP.Connection(eipLayer);
const logix5000 = new Layers.CIP.Logix5000(cipConnection);

(async () => {
  try {
      const value = await logix5000.readTag('R03:9:I.Ch1Data');
      console.log(value);
    } catch(err) {
      console.log(err);
    }

    await tcpLayer.close();
  }
})();
```

### 2. Communicate with a PLC-5 processor using PCCC embedded in CIP:

```javascript
const { Layers } = require('node-drivers');

const tcpLayer = new Layers.TCP({ host: '0.0.0.0', port: 44818 });
const eipLayer = new Layers.EIP(tcpLayer);
const cipPCCCLayer = new Layers.CIP.PCCC(eipLayer);
const plc5 = new Layers.PCCC(cipPCCCLayer);

plc5.typedRead('N10:47', function(err, value) {
  if (err) {
    console.log(err);
  } else {
    console.log(value);
  }

  tcpLayer.close(function() {
    console.log('closed');
  });
});
```

### 3. Find all EtherNet/IP devices in a subnet using the UDP broadcast address:

```javascript
const { Layers } = require('../src');

const udpLayer = new Layers.UDP({ host: '0.0.0.255', port: 44818 });
const eipLayer = new Layers.EIP(udpLayer);

(async () => {
  try {
    const identities = await eipLayer.listIdentity({ timeout: 5000 });
    console.log(identities);
  } catch(err) {
    console.log(err);
  }

  await udpLayer.close();
})();
```

### 4. Find all EtherNet/IP devices in a subnet manually over UDP

```javascript
const { Layers } = require('../src');

/* host does not need to be specified if upper layer messages specify it */
const udpLayer = new Layers.UDP({ port: 44818 });
const eipLayer = new Layers.EIP(udpLayer);

const hosts = [];
for (let i = 2; i < 255; i++) {
  hosts.push(`0.0.0.${i}`);
}

(async () => {
  try {
    /* hosts override whatever host was specified in the Layers.UDP() constructor */
    const identities = await eipLayer.listIdentity({ timeout: 5000, hosts });
    console.log(identities);
  } catch(err) {
    console.log(err);
  }

  await udpLayer.close();
})();
```

### 5. List interfaces of EtherNet/IP device over TCP:

```javascript
const { Layers } = require('../src');

const tcpLayer = new Layers.TCP({ host: '0.0.0.255', port: 44818 });
const eipLayer = new Layers.EIP(tcpLayer);

(async () => {
  try {
    const identities = await eipLayer.listInterfaces();
    console.log(identities);
  } catch(err) {
    console.log(err);
  }<commit_msg>Changed EIP over TCP example host<commit_after># node-drivers

Supports callbacks and async/await.

# Install

```sh
npm install node-drivers
```

# Examples

### 1. Communicate with a Logix5000 processor:

```javascript
const { Layers } = require('node-drivers');

const tcpLayer = new Layers.TCP({ host: '0.0.0.0', port: 44818 });
const eipLayer = new Layers.EIP(tcpLayer);
const cipConnection = new Layers.CIP.Connection(eipLayer);
const logix5000 = new Layers.CIP.Logix5000(cipConnection);

(async () => {
  try {
      const value = await logix5000.readTag('R03:9:I.Ch1Data');
      console.log(value);
    } catch(err) {
      console.log(err);
    }

    await tcpLayer.close();
  }
})();
```

### 2. Communicate with a PLC-5 processor using PCCC embedded in CIP:

```javascript
const { Layers } = require('node-drivers');

const tcpLayer = new Layers.TCP({ host: '0.0.0.0', port: 44818 });
const eipLayer = new Layers.EIP(tcpLayer);
const cipPCCCLayer = new Layers.CIP.PCCC(eipLayer);
const plc5 = new Layers.PCCC(cipPCCCLayer);

plc5.typedRead('N10:47', function(err, value) {
  if (err) {
    console.log(err);
  } else {
    console.log(value);
  }

  tcpLayer.close(function() {
    console.log('closed');
  });
});
```

### 3. Find all EtherNet/IP devices in a subnet using the UDP broadcast address:

```javascript
const { Layers } = require('../src');

const udpLayer = new Layers.UDP({ host: '0.0.0.255', port: 44818 });
const eipLayer = new Layers.EIP(udpLayer);

(async () => {
  try {
    const identities = await eipLayer.listIdentity({ timeout: 5000 });
    console.log(identities);
  } catch(err) {
    console.log(err);
  }

  await udpLayer.close();
})();
```

### 4. Find all EtherNet/IP devices in a subnet manually over UDP

```javascript
const { Layers } = require('../src');

/* host does not need to be specified if upper layer messages specify it */
const udpLayer = new Layers.UDP({ port: 44818 });
const eipLayer = new Layers.EIP(udpLayer);

const hosts = [];
for (let i = 2; i < 255; i++) {
  hosts.push(`0.0.0.${i}`);
}

(async () => {
  try {
    /* hosts override whatever host was specified in the Layers.UDP() constructor */
    const identities = await eipLayer.listIdentity({ timeout: 5000, hosts });
    console.log(identities);
  } catch(err) {
    console.log(err);
  }

  await udpLayer.close();
})();
```

### 5. List interfaces of EtherNet/IP device over TCP:

```javascript
const { Layers } = require('../src');

const tcpLayer = new Layers.TCP({ host: '0.0.0.0', port: 44818 });
const eipLayer = new Layers.EIP(tcpLayer);

(async () => {
  try {
    const identities = await eipLayer.listInterfaces();
    console.log(identities);
  } catch(err) {
    console.log(err);
  }
{'fraction_non_alphanumeric': 0.1680796166605234, 'fraction_numerical': 0.033542204201990417, 'mean_word_length': 3.67039586919105, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4832474', 'n_tokens_mistral': 2067, 'n_tokens_neox': 1899, 'n_words': 495}