Closed greg9504 closed 4 months ago
Looked at it some more and got the PO/IO VFD data being read using implicit messaging via the IO class. There was one change to make in the src/io/ tcp/index.ts Controller class. The order of the input and output had to be swamped, otherwise the VFD reported back invalid path. I'm trying to find if he order is actually specified anywhere.
Line 375 (and probably line 373) From
cipPath = Buffer.concat([assemblyObjectClass, configInstance, pointOT, pointTO]);
To
cipPath = Buffer.concat([assemblyObjectClass, configInstance, pointTO, pointOT]); //swap order of pointTO and pointOT
Full working code
import { ControllerManager, TagList, IO, Tag, Controller } from "st-ethernet-ip";
// connect to the SEW VFD IO data (PO1/PO2/PO2 and PI1/PI2/PI3) using the IO scanner
async function main() {
// If you have any running instances of Ethernet tools (say EnIPExplorer) shut it down or
// opening the port 2222 will fail
const scanner = new IO.Scanner(2222, '0.0.0.0'); // Iinitalize new scanner on default port 2222
// device configuration from manufacturer.
const config = {
// this defines the connection path, see SEW eds file example: "20 04 24 01 2C 78 2C 82"
// see Fieldbus Interface DFE33B manual page 57, 6.2 Data Exchange Assembly Object 0x04
configInstance: {
assembly: 1,
size: 0
},
outputInstance: {
assembly: 130,//0x82
size: 20
},
inputInstance: {
assembly: 120, //0x78
size: 20
}
}
// Add a connection with (device config, rpi, ip_address)
const conn = scanner.addConnection(config, 500, '192.168.1.159');//VFD at '192.168.1.159'
// Above does forwardOpen async, returns before connection is open
// connection is not marked open until first UDP packet (acutal data) is received
// Called when UDP packets are not receiving. (Timeout is based on rpi setting)
conn.on('disconnected', () => {
console.log('Disconnected');
});
// After first UDP packet is received
conn.on('connected', () => {
console.log('Connected')
console.log('input data => ', conn.inputData); // Display Input Data Buffer.
console.log('output data => ', conn.outputData); // Display Output Data Buffer.
// Create alias for bits and integers (can be named what ever you want)
conn.addOutputBit(0, 8, 'outMotorDir'); // Using outputData. bit 8 is motor direction in control word
conn.addOutputInt(2, 'outMotorSpeed'); // second outputData word is configured as motor speed
conn.addInputBit(0, 5, 'inFaultorWarn'); // first inputData word is Status Word, bit 8 is fault or warn indicator
conn.addInputInt(2, 'inActualSpeed'); //
// Set values to be written to devices
conn.setValue('outMotorDir', true);
conn.setValue('outMotorSpeed', 23500);
// Read values from device connection
console.log(conn.getValue('inFaultorWarn'));
console.log(conn.getValue('inActualSpeed'));
setInterval(() => {
if (conn.connected) {
console.log('input data => ', conn.inputData.toString('hex')); // Display Input Data Buffer.
console.log('Fault: ' + conn.getValue('inFaultorWarn'));
console.log('Acutal Speed: ' + conn.getValue('inActualSpeed'));
}
}, 4000);
});
console.log('Hello world!');
}
main();
Does seem like the scanner.addConnection method needs a way to indicate an error opening the connection. If I understand it, the code will just try over and over to establish the connection without being able to signal to caller that an error happened.
Going to close this. You can ignore the problem I had with the Input/Output of the IO. I'll open a pull request for the getAttributeSingle change.
I'm trying to get ethernet-ip working with SEW VFD's. These do NOT support the 0x6b class object used for tags. The drives support the Assembly (0x04) and Register (0x07) object classes. I have been able to connect and configure the drives using the library and the getAttributeSingle/setAttributeSingle methods. I did have to make one small change to the library to get it to work. Code is below for how I'm using the library.
What I'm wondering is:
I'm pretty green on Ethernet-IP. So any suggestions welcome.
Anyway here is how I'm using it to talk to the SEW drive. The small modification I had to make to the library was to add a Buffer parameter to the getAttributeSingle call. This is for getting drive parameter values, you need to send some data identifying which parameter you want to get.
getAttributeSingle: