cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Connect Thingworx and PLC

SOLVED

Re: Connect Thingworx and PLC

You can try adjusting the timeout value in config.lua

You can do so in the section

scripts.modbus_handler = {

    file = "modbus_handler.lua" ,

    response_timeout = 10000,

}

Not that the number is in milliseconds.  The default is 5000.

You can also debug your connection by talking directly to the modbus_handler script itself.  On the machine that your EMS is running, point a browser with your favorite REST debugging tool, like Postman, to http://127.0.0.1:<port>/scripts/modbus_handler/holding_register/<slave_id>/<register>

where port is the port your Lua Script resource is listening on - defaults to 8001, slave_id would be 1, and holding_holding register would be 4001 in your case.

For writing you should be should be doing a PUT to /holding_register/<slave_id>/<register>

Take a look at the documentation in /etc/thingworx/scripts/modbus_handler.lua for some more details on how to interact directly with that script.

Re: Connect Thingworx and PLC

Hi John, how exactly work this service.getAllProperties in modbusExample.lua? I can't see this service in remote thing for binding (how I can call it?). Also I having issue to read coils and discrete inputs - as bit values and using workaround with Uint16 word value - It's working, but it's not right. Could you please advice? Thanks.

Re: Connect Thingworx and PLC

Peter - In looking at the modbusExample.lua file that you posted (I assume this is the one you are referring to), I don't see a service definition in that template.  That is why you don't see it when you browse from Composer.  If I remember right read_multiple_registers returns a string with a comma separated list of formatted values.  You can double check this by directly POSTing to the modbus_handler script to see what comes back.

A coil property definition should look like the following:

properties.CoilTest1 = {key="coil/<slave_id>/<coil_number>", handler="modbus_handler", basetype="BOOLEAN"}

One thing to be careful of is offset in modbus addressing.  Depending on your modbus slave the first coil might be coil #1 at address 0 which is typical or they might call it by its address (i.e. coil 1 is at address 1 and coil 0 is at address 0).

Re: Connect Thingworx and PLC

Hi,

I also facing problem on connecting IDEC to ThingWorx.

below is the result after I run ./luascriptresources

[ERROR] 2016-04-09 11:34:20,113 luaScriptProxy::execute: [1094014096] Error executing script modbus_handler, Error = Error: ...t/thingworx/MicroServer/etc/thingworx/lua/modbus.lua:104: module 'socket' not found:

        no field package.preload['socket']

        no file '/opt/thingworx/MicroServer/etc/socket.lua'

        no file '/opt/thingworx/MicroServer/etc/thingworx/socket.lua'

        no file '/opt/thingworx/MicroServer/etc/thingworx/lua/socket.lua'

        no file '/opt/thingworx/MicroServer/etc/custom/socket.lua'

        no file '/opt/thingworx/MicroServer/etc/custom/lua/socket.lua'

        no file '/opt/thingworx/MicroServer/etc/community/lua/socket.lua'

        no file './socket.lua'

        no file '/usr/local/share/lua/5.1/socket.lua'

        no file '/usr/local/share/lua/5.1/socket/init.lua'

        no file '/usr/local/lib/lua/5.1/socket.lua'

        no file '/usr/local/lib/lua/5.1/socket/init.lua'

        no file '/opt/thingworx/MicroServer/etc/thingworx/clibs/socket.so'

        no file '/opt/thingworx/MicroServer/etc/custom/clibs/socket.so'

        no file '/opt/thingworx/MicroServer/etc/community/clibs/socket.so'

        no file './socket.so'

        no file '/usr/local/lib/lua/5.1/socket.so'

        no file '/usr/local/lib/lua/5.1/loadall.so'

[ERROR] 2016-04-09 11:34:20,118 luaScriptProxy::app_unlock: [1094014096] Attempt to unlock app_mutex while not holding it.L= 0x1141f0

hope someone can help.

thanks in advance

Re: Connect Thingworx and PLC

Eric, what version of the MicroServer are you using? Do you have the Modbus package with it as well?

Highlighted

Re: Connect Thingworx and PLC

Hi Eric, looks like you using latest 5.1 version - you need Modbus complete Modbus package - is missing - If you would like to download my package and search or socket.lua (and other files if needed) and add them to your microserver / or reuse my package with your config files (config.lua and config.json).

Re: Connect Thingworx and PLC

Have in mind - I'm using version 5.3.1.1113 with some changes to get it work

Re: Connect Thingworx and PLC

Hi,


Thanks for your fast reply. Sorry that i am very new to Thingworx.

How to check the version? The modbus package is that something like mobusscript.lua?

Fyi, i had actually downloaded the EMS to Syslink Systech SL-3000.

Re: Connect Thingworx and PLC

Here's a link to a quick start Modbus blog that has downloads to the package as well.

Re: Connect Thingworx and PLC

Thanks everyone.

Question to Peter, may I know where to get the complete Modbus package?

Can I use this package?

Content