Connect Beckhoff PLC via TAME library (ADS)

929 views
Skip to first unread message

mm

unread,
Oct 17, 2017, 3:39:42 AM10/17/17
to Node-RED
Hello!

I'm trying to control a Beckhoff PLC via Nodered.
There is a project called TAME (https://github.com/tomcx/tame4) providing a JS library to access a PLC.

Could anyone please point me to a start on how to implement this into nodered?
e.g. a trigger sets a digital out in my PLC.
or a value is read and written into a mongodb.

Thank you!
Martin

Colin Law

unread,
Oct 17, 2017, 4:39:03 AM10/17/17
to node...@googlegroups.com
On 17 October 2017 at 08:39, mm <martin.k...@gmail.com> wrote:
> Hello!
>
> I'm trying to control a Beckhoff PLC via Nodered.
> There is a project called TAME (https://github.com/tomcx/tame4) providing a
> JS library to access a PLC.

I suspect that is not the right place to start. Google suggests that
the device supports OPC UA in which case
node-red-contrib-opcua might be a possible route.
https://flows.nodered.org/node/node-red-contrib-opcua

Colin

mm

unread,
Oct 30, 2017, 9:25:36 AM10/30/17
to Node-RED
Unfortunately that's not an option since my controller is not able to run OPC UA server

Is there a way to execute javascript based on an external library?

steve rickus

unread,
Oct 30, 2017, 10:37:19 AM10/30/17
to Node-RED
Hi Martin,

Yes, this is the purpose of many of the node-red core and contrib nodes -- they wrap nodejs libs and expose them to flows. You will need to follow the docs for Creating Custom Nodes, and if you follow the tagging/naming rules, your new node will be visible on flows.nodered.org for others to use as well.

I would start by looking at how other PLC nodes use their external libs to communicate with specific PLCs. You can search on the flows library and look at the code on github, such as this node for the Siemens S7 device. The idea is to require the TAME library, and wrap the node-red events (onInput, onClose, etc) around your PLC specific calls. Most likely, you will end up with "tame-in", "tame-out", and "tame-config" nodes -- then you can wire your tame-out node to a flow that processes your PLC readings, and inserts them into mongodb or whatever database you want.
--
Steve

mm

unread,
Nov 3, 2017, 3:03:16 PM11/3/17
to Node-RED

Before I will try my luck of implementing this into a node, I’d like to get the library itself running inside node red as a function.


It is possible to install the „tame“ library via npm (npm install tame4), which I did.


Then I added this to the settings.js:

    functionGlobalContext: {
        tamecon
:require('ta...@4.3.0')
   
},



In the help file of the tame library there is an example constructor for instancing the web service client:


var PLC = TAME.WebServiceClient.createClient({
 serviceURL
: "http://192.168.1.2/TcAdsWebService/TcAdsWebService.dll", configFileUrl: '' http://192.168.1.2/myproject.tpy'',
 onReady
: function() {
//Put your stuff here }
});



trying something like this in a function in red node didn’t yield any results:


var PLC = context.global.tamecon();

PLC
.WebServiceClient.createClient({
serviceURL
: "http://192.168.1.2/TcAdsWebService/TcAdsWebService.dll", amsNetId: "192.168.1.2.1.1",
onReady
: function() {}
});
return msg;



I receive:


TypeError: context.global.tamecon is not a function


Could someone please point me in the right direction? I really would like to get this running and pick up all I need in the process…

It’s my missing link to use this great software and all it’s possibilities for my house…


Thanks!

Martin

Julian Knight

unread,
Nov 4, 2017, 7:18:06 PM11/4/17
to Node-RED
Start by looking at the node-red log to see if tame actually got loaded. You may see an error that would point you in the right direction.

Also, it would be easier to `npm install tame4`, you shouldn't need the version since 4.3.0 is the latest. Then you use `tamecon:require('tame4')`

Finally, do you have an ADS Web Service running? That is required for Tame, their example is on IP address 192.168.1.2 but that is unlikely to be the same in your local environment.

mm

unread,
Nov 5, 2017, 8:10:14 AM11/5/17
to Node-RED
Thank you Julian,

Yes, I do have a working ADS service running. (And a working web example)

I think I'm a step further now...

var PLC = new context.global.tamecon.WebServiceClient.createClient({
amsNetId: "x.xx.xxx.xx.1.1",
alignment: "4",
language: "en",
onReady: function() {}});
return msg;

I now get:

 5.11.2017, 14:07:17node: tame
function : (error)
"ReferenceError: alert is not defined"

Is this a node red error or an error from the library?
Is there a way to tell? Or any other places I can look for a more detailed error description?

Thanks!

Julian Knight

unread,
Nov 5, 2017, 2:15:47 PM11/5/17
to Node-RED
The function node actually uses Node.JS's VM library for creating protected environments. As such not everything is allowed. You happened to have discovered one of those things!

Use node.warn() instead and the output will appear in the debug sidebar.

mm

unread,
Nov 6, 2017, 4:07:25 PM11/6/17
to Node-RED
ok, i guess the error lies in the log function here within the tame.js lib and when it's called the first time to log the lib version...
but exchanging "alert" to "node.warn" doesnt help...

/**
         * Wrapper for console messages.
         *
         * @param {Mixed} message  The message to be logged.
         */

       
function log(message) {
           
try {
                window
.console.log(message);
           
} catch (e) {
               
//fallback
                alert
(message);
           
}
       
}


       
//Log version
        log
('TAME library version: ' + TAME.version);

mm

unread,
Nov 7, 2017, 8:45:48 AM11/7/17
to Node-RED
on a second note I don't think I should change the original npm source, right?

Julian Knight

unread,
Nov 9, 2017, 3:29:34 PM11/9/17
to Node-RED
Well .... no, not really ;-)

Best to clone the repo. You can link your clone into your test instance of Node-RED. Once you have fixed the problem, you can then issue a pull request against the original repo. Hopefully they will accept it and update.

mm

unread,
Nov 16, 2017, 4:13:36 AM11/16/17
to Node-RED
Thank you guys for all your help.
Due to the complexity of this and my lack of programming skills I abandoned this route.

I'm now using a native implementation of a MQTT pub/sub client on my PLC.

Shivraj Managond

unread,
Mar 29, 2018, 7:42:32 AM3/29/18
to Node-RED
Hi , can you give information how you used TwinCAT PLC with Nodered communication via pub-sub
Reply all
Reply to author
Forward
0 new messages