Skip to main content
1-Visitor
December 5, 2016
Solved

Issue in connecting Thingworx and Modbus PLC Simulator

  • December 5, 2016
  • 12 replies
  • 6796 views

Hi All,

  • I am running Modbus PLC simulator (downloaded from Modbus PLC Simulator​) and Thingworx server on windows machine.
  • Running EMS on Raspberry pi (all are connected in same network)
  • I am using MicroServer-5.3.2-Linux-ARM-HWFPU and Modbus package for LinuxARM

I am following modbus example from Modbus PLC Simulator, ThingWorx and You

This is my ws_servers & auto_bind section of config.json

  "ws_servers": [ {

       "host": "192.168.0.94",

       "port": 8443

  } ],

  "appKey": "9311c13b-69a1-49fa-9e22-00bd9fe8c333",

  "auto_bind": [ {

       "name": "ModbusGateway",

       "gateway": true

  } ],

and config.lua

scripts.MyPLC = { 

    file = "thing.lua", 

    template = "modbusExample",

    identifier = "plc", 

    updateRate = 2000 

} 

 

scripts.Thingworx = { 

    file = "thingworx.lua" 

} 

 

scripts.modbus_handler = { 

    file = "modbus_handler.lua", 

    name = "modbus_handler", 

    host = "192.168.0.94",

    port = "502" 

}

The problem is that I can bind remote properties to a created thing but could not able to read modbus registries.

I am getting following error.

pi@raspberrypi:~/microserver/install_services $ sudo journalctl --unit=tw_luaScriptResourced | tail -20

Oct 21 15:36:01 raspberrypi thingworx[5648]: ScriptResource::executeScriptRequest:Path /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 15:36:01 raspberrypi thingworx[5648]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                             Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 15:36:01 raspberrypi thingworx[5648]: MyPLC:Could not read current value of Int16HoldRegExample. Setting quality to UNKNOWN. Resp:

Oct 21 15:36:01 raspberrypi thingworx[5648]: MyPLC:Error while getting property Int16HoldRegExample. msg: /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 15:36:04 raspberrypi thingworx[5648]: ScriptResource::executeScriptRequest:Path /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 15:36:04 raspberrypi thingworx[5648]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                             Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Could not read current value of ScaledInt16RegExample. Setting quality to UNKNOWN. Resp:

Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Error while getting property ScaledInt16RegExample. msg: /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 15:36:04 raspberrypi thingworx[5648]: ScriptResource::executeScriptRequest:Path /scripts/modbus_handler/holding_register/1/40002/ not found

Oct 21 15:36:04 raspberrypi thingworx[5648]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40002'

                                             Returned: 404 /scripts/modbus_handler/holding_register/1/40002/ not found

Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Could not read current value of Uint16RegExample. Setting quality to UNKNOWN. Resp:

Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Error while getting property Uint16RegExample. msg: /scripts/modbus_handler/holding_register/1/40002/ not found

Oct 21 15:36:04 raspberrypi thingworx[5648]: ScriptResource::executeScriptRequest:Path /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 15:36:04 raspberrypi thingworx[5648]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                             Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Could not read current value of Int16HoldRegExample. Setting quality to UNKNOWN. Resp:

Oct 21 15:36:04 raspberrypi thingworx[5648]: MyPLC:Error while getting property Int16HoldRegExample. msg: /scripts/modbus_handler/holding_register/1/40001/ not found

am I missing something?

2nd query is how to log the messages from luaScriptResource when its running as service? config.lua does not have logger section.

Best answer by Do1

Hello Mithun,

I recently found some industrial units based on the Raspberry Pi and were quite excited about the possibilities.

Unfortunately I encountered the same issues with both my standard Raspberry Pi and these new ones.

I identified two problems on my side:

1. The modbusExample.lua tries to load file transfer functionality.

2. There is something wrong with the supplied core.so file (maybe it was not compiled for ARM architecture) - you get No such file or directory

[ERROR] when running the luaResource.

To fix the 1st issue is easy... just remove the require "thingworx.shapes.filetransfer" line from modbusExample.lua.

To fix the second issue you need to find a core.so file which is compatible with the ARM Architecture of your Raspberry Pi.  In theory, the core.os file supplied as part of the TWEMS MODBUS Package_Linux_ARM.zip file located at microserver/etc/community/clibs/socket/core.so should work, but it does not.

Download the lua-socket resource:

$ sudo apt-get install lua-socket

Copy the newly downloaded core.so to your microserver installation:

$ cp /usr/lib/arm-linux-gnueabihf/lua/5.1/socket/core.so /home/pi/microserver/etc/community/clibs/socket/

Now if your config files are configured correctly, then everything should work.

Good luck!

12 replies

5-Regular Member
December 5, 2016

Mithun, can you output the luaScriptResource onto a log file by running the following?

luaScriptResource > logfile.log

When you run both the EMS and lua, does the Modbus sim show a successful connection?

msarage1-VisitorAuthor
1-Visitor
December 5, 2016

Ravi,

When i type the command

luaScriptResource > logfile.log

  i get following error.

luaScriptResource: command not found

Sorry I am new to Linux.


Yes When I run EMS & Lua services, in Thingworx I can see Identifier for remote thing also I can browse remote properties, only thing is values are not getting updated.


When I type the command

sudo journalctl --unit=Thingworx_Lua | tail -50          (here Thingworx_Lua is my service name from lua script)

get following result

pi@raspberrypi:~/microserver/install_services $ sudo journalctl --unit=Thingworx_Lua | tail -50

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 19:34:44 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 19:34:44 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40002'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40002/ not found

Oct 21 19:34:44 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 19:34:47 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 19:34:47 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40002'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40002/ not found

Oct 21 19:34:47 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 19:34:50 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 19:34:50 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40002'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40002/ not found

Oct 21 19:34:50 raspberrypi thingworx[3844]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 19:35:05 raspberrypi systemd[1]: Stopping LSB: ThingWorx Lua Script Resource...

Oct 21 19:35:05 raspberrypi logger[3904]: Stopping ThingWorx Lua Script Resource luaScriptResource

Oct 21 19:35:05 raspberrypi Thingworx_Lua[3899]: start-stop-daemon: warning: this system is not able to track process names

Oct 21 19:35:05 raspberrypi Thingworx_Lua[3899]: longer than 15 characters, please use --exec instead of --name.

Oct 21 19:35:21 raspberrypi thingworx[3844]: HttpClient::processReq:Timeout while waiting for response from localhost.

Oct 21 19:35:21 raspberrypi thingworx[3844]: luaBindings::httpPost:Error POSTing to HTTP Server at localhost/Thingworx/Things/LocalEms/Services/HasEdgeThing

Oct 21 19:35:35 raspberrypi systemd[1]: Stopped LSB: ThingWorx Lua Script Resource.

Oct 21 19:35:48 raspberrypi systemd[1]: Starting LSB: ThingWorx Lua Script Resource...

Oct 21 19:35:48 raspberrypi logger[3944]: Starting ThingWorx Lua Script Resource luaScriptResource

Oct 21 19:35:48 raspberrypi thingworx[3948]: daemonize:Child process running

Oct 21 19:35:48 raspberrypi thingworx[3948]: psrap::daemonize:Child creating session id...

Oct 21 19:35:48 raspberrypi thingworx[3948]: psrap::daemonize:Child continuing...

Oct 21 19:35:48 raspberrypi thingworx[3948]: psrap::daemonize:Child closing out stdin,stdout,stderr...

Oct 21 19:35:48 raspberrypi thingworx[3948]: /home/pi/microserver/install_services/..//luaScriptResource:Using config file: /home/pi/microserver/install_services/..//etc/config.lua

Oct 21 19:35:48 raspberrypi thingworx[3948]: /home/pi/microserver/install_services/..//luaScriptResource:Starting up ....

Oct 21 19:35:48 raspberrypi logger[3949]: 0

Oct 21 19:35:48 raspberrypi systemd[1]: Started LSB: ThingWorx Lua Script Resource.

Oct 21 19:35:48 raspberrypi thingworx[3948]: luaScriptProxy::execute:[1972368464] Error executing script modbus_handler, Error = Error: error loading module 'socket.core' from file '/home/pi/microserver/install_services/..//etc/community/clibs/socket/core.so':

                                                    /home/pi/microserver/install_services/..//etc/community/clibs/socket/core.so: cannot open shared object file: No such file or directory

Oct 21 19:35:48 raspberrypi thingworx[3948]: luaScriptProxy::app_unlock:[1972368464] Attempt to unlock app_mutex while not holding it.L= 0x759144e8

Oct 21 19:35:48 raspberrypi thingworx[3948]: httpServer:starting http server port=502

Oct 21 19:35:48 raspberrypi thingworx[3948]: httpserver:Server socket error: Address not available [192.168.0.94:502]

Oct 21 19:35:48 raspberrypi thingworx[3948]: httpServer:unable to bind http server to any port from 502 to 502.

Oct 21 19:35:51 raspberrypi thingworx[3948]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

Oct 21 19:35:51 raspberrypi thingworx[3948]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40002'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40002/ not found

Oct 21 19:35:51 raspberrypi thingworx[3948]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40003'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40003/ not found

Oct 21 19:35:51 raspberrypi thingworx[3948]: luaInterscriptBinding::l_executeCallback:Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

                                            Returned: 404 /scripts/modbus_handler/holding_register/1/40001/ not found

In this this result I feel these are the lines which are hinting something

Oct 21 19:35:48 raspberrypi systemd[1]: Started LSB: ThingWorx Lua Script Resource.

Oct 21 19:35:48 raspberrypi thingworx[3948]: luaScriptProxy::execute:[1972368464] Error executing script modbus_handler, Error = Error: error loading module 'socket.core' from file '/home/pi/microserver/install_services/..//etc/community/clibs/socket/core.so':

                                                    /home/pi/microserver/install_services/..//etc/community/clibs/socket/core.so: cannot open shared object file: No such file or directory

Oct 21 19:35:48 raspberrypi thingworx[3948]: luaScriptProxy::app_unlock:[1972368464] Attempt to unlock app_mutex while not holding it.L= 0x759144e8

Oct 21 19:35:48 raspberrypi thingworx[3948]: httpServer:starting http server port=502

Oct 21 19:35:48 raspberrypi thingworx[3948]: httpserver:Server socket error: Address not available [192.168.0.94:502]

Oct 21 19:35:48 raspberrypi thingworx[3948]: httpServer:unable to bind http server to any port from 502 to 502.

I am using following EMS and modbus package

MED-61060-CD-053_SP2_Microserver-5-3-2-Linux-ARM-HWFPU.zip

TWEMS MODBUS Package_Linux_ARM.zip

5-Regular Member
December 5, 2016

You would need to stop the lua service, navigate to /home/pi/microserver (assuming that's where the luaScriptResource file is) and then run ./luaScriptResource > log.log

That should pipe the output onto the log file. Going by this message -

Oct 21 19:35:48 raspberrypi thingworx[3948]: httpserver:Server socket error: Address not available [192.168.0.94:502]

Is the sim actually running/ connected? If you have the EMS and lua running, and along with the sim, the sim should say something on the lines of Connected (1/10) to show successful connection via port 502 (default port).