cloud-automation / node-soem Goto Github PK
View Code? Open in Web Editor NEWSimple Open EtherCAT Master (SOEM) Port for Node.js
Simple Open EtherCAT Master (SOEM) Port for Node.js
Hi Stefan, is there any reason why you limit Ibytes, same applies to Obytes, to 8 bytes ? shouldn't we just make sure that num bytes reported by slave matches the bits ?
numbytes = ec_slave[i].Ibytes;
if ((numbytes == 0) && (ec_slave[i].Ibits > 0)) numbytes = 1;
if (numbytes > 8) numbytes = 8;
Rgds
I am just prototyping with node-soem using a Beckhoff EL2622 (2-channel relay).
This device has two output bits:
{ name: 'EL2622',
state: 18,
ALStatusocde: 0,
configadr: 4098,
aliasadr: 0,
Obits: 2,
Obytes: 0,
outputs: ArrayBuffer { byteLength: 0 },
Ibits: 0,
Ibytes: 0,
inputs: ArrayBuffer { byteLength: 0 },
pdelay: 145 }
Note that the outputs
array is zero length, so the following code fails:
var counter = 0,
slaves = master.getSlaves(),
dv = new DataView(slaves[1].outputs);
var intv = setInterval(function () {
master.sendProcessdata();
master.receiveProcessdata();
dv.setUint16(0, 1);
(the DataView is zero length)
According to the SOEM ethercatmain.h
, if Obits is less than 8, Obytes will be zero, as in this case.
I hacked around this using the following code:
uint16 bits=ec_slave[i].Obits;
if ( bits > 0 && bits < 8 ) {
slave->Set(String::NewFromUtf8(isolate, "outputs"),
ArrayBuffer::New(isolate, (void*) ec_slave[i].outputs, 1));
} else {
slave->Set(String::NewFromUtf8(isolate, "outputs"),
ArrayBuffer::New(isolate, (void*) ec_slave[i].outputs, ec_slave[i].Obytes));
}
Then I could use dv.setUint8
in the Javascript and it worked ok.
I think there is more to do for a proper solution, because I didn't take care of the bit offset / mask. There is some further info on this here: https://openethercatsociety.github.io/doc/soem/tutorial_8txt.html.
It would be great if ultimately this library (or another) could abstract this type of detail away from the developer -- many Javascript developers are not used to doing bitwise manipulation, or even using advanced features such as DataView!
Anyway I got my little PoC working so thanks for the lib!
Fails with:
SOLINK_MODULE(target) Release/obj.target/node-soem.node
/usr/bin/ld: ../lib/build/libsoem.a(ethercatmain.c.o): Die Umlagerung von
../lib/build/libsoem.a: error adding symbols: Ungültiger Wert
collect2: error: ld returned 1 exit status
node-soem.target.mk:132: die Regel für Ziel „Release/obj.target/node-soem.node“ scheiterte
make: *** [Release/obj.target/node-soem.node] Fehler 1
make: Verzeichnis „/home/helyman83/node-soem/build“ wird verlassen
In the last SOEM changes, they have cleaned up the CMakeLists.txt file.
In preinstall.sh this fails:
sed -i "/target_link_libraries(soem\ pthread\ rt)/a \ \ set_property(TARGET soem PROPERTY POSITION_INDEPENDENT_CODE ON)" CMakeLists.txt
because "target_link_libraries(soem pthread rt)" was replaced by "target_link_libraries(soem ${OS_LIBS})"
preinstall.sh works again if we replace it with:
sed -i '/target_link_libraries(soem\ ${OS_LIBS})/a \ \ set_property(TARGET soem PROPERTY POSITION_INDEPENDENT_CODE ON)' CMakeLists.txt
Attempt to "sudo npm install node-soem" fails at "node-gyp rebuild".
Node.js is "v4.2.6". Also installed "nodejs-legacy" but no change.
SOEM was installed before this and seems to work fine.
Additional info - the first error is on building "../src/node-sooem-master.cc:8:22: fatal error: ethercat.h: No such file or directory". I will try to find why.
In example_01.js and readme.md to switch to OP state we should pass to writeState/statecheck '8' and not '4'.
See typdef enum from https://github.com/OpenEtherCATsociety/SOEM/blob/master/soem/ethercattype.h :
/** Possible EtherCAT slave states */ typedef enum { /** No valid state. */ EC_STATE_NONE = 0x00, /** Init state*/ EC_STATE_INIT = 0x01, /** Pre-operational. */ EC_STATE_PRE_OP = 0x02, /** Boot state*/ EC_STATE_BOOT = 0x03, /** Safe-operational. */ EC_STATE_SAFE_OP = 0x04, /** Operational */ EC_STATE_OPERATIONAL = 0x08, /** Error or ACK error */ EC_STATE_ACK = 0x10, EC_STATE_ERROR = 0x10 } ec_state;
and https://infosys.beckhoff.com/index.php?content=../content/1031/tcsystemmanager/reference/ethercat/html/EtherCAT_Diagnostics.htm&id= (section Info Data).
Or I'm missing something ?
npm install node-soem
fails at node-gyp build.
SOLINK_MODULE(target) Release/obj.target/node-soem.node
**/usr/bin/ld: cannot find -lsoem**
collect2: error: ld returned 1 exit status
node-soem.target.mk:133: die Regel für Ziel „Release/obj.target/node-soem.node“ scheiterte
make: *** [Release/obj.target/node-soem.node] Fehler 1
make: Verzeichnis „/home/xxx/proj/node_modules/node-soem/build“ wird verlassen
gyp ERR! build error
gyp ERR! stack Error: 'make' failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/node-gyp/lib/build.js:285:23)
gyp ERR! stack at emitTwo (events.js:106:13)
gyp ERR! stack at ChildProcess.emit (events.js:191:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Linux 4.4.0-78-generic
gyp ERR! command "/usr/bin/nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/xxx/proj//node_modules/node-soem
gyp ERR! node -v v6.10.3
gyp ERR! node-gyp -v v3.6.1
gyp ERR! not ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
Ubuntu 16.04.2 LTS
There is a mistake in the binding.gyp. The libsoem.so is not at lib/build but at ../lib/build. But this doesn't help. At execution of a Node.js app based on node-soem I get:
module.js:597
return process.dlopen(module, path._makeLong(filename));
^
Error: libsoem.so: cannot open shared object file: No such file or directory
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/ballings/proj/spielwiese/nodeEtherCAT/example_01.js:1:74)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
If I copy the libsoem manually to /usr/lib everything working fine (node-gyp build & execution of node.js app).
By the way... why you use an shared object of libsoem and not an static linked object?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.