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
Newbie

Connect Thingworx and PLC

Hi,

I'm trying to connect PLC and Thingworx via EMS.

In modbusExample.lua file, defining property for Thing is essential.

I put this property like this,

properties.Int16HoldRegExample = {value="300", dataChangeType="ALWAYS",pushType="ALWAYS", key ="holding_register/1/40001", handler="modbus_handler", basetype="NUMBER"}

But I can't connect.

Which URL does this "key" table mean?   PLC ,EMS or Thingworx Composer ?

please let me know information...

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Connect Thingworx and PLC

The Modbus example is specifically for connecting using Modbus protocol.

You have a modbus protocol setup to your PLC?

the Key refers to the Modbus register that is to be read.

21 REPLIES 21

Re: Connect Thingworx and PLC

The Modbus example is specifically for connecting using Modbus protocol.

You have a modbus protocol setup to your PLC?

the Key refers to the Modbus register that is to be read.

Re: Connect Thingworx and PLC

I use Modbus package and set up modbus protocol to my PLC.

Is it ok that only modbus register is included in key contents,for example key = "40001" ?

Re: Connect Thingworx and PLC

Unfortunately I'm not too familiar with how the modbus.lua is setup and how it processes the key that is put in.

Hopefully someone else can give some input on that.

Re: Connect Thingworx and PLC

First of all you need to make sure that your Modbus communication is working properly.

That deppends on type of connecten. Are you using Modbus over serial - i.e. RTU/ASCII over RS485? or Modbus over TCP??

You can try program like Modbus Poll to verify your settings and readings. That's what I am using. (it's only a 10minutes demo though).

Then you need to change your config.lua file accordingly. Regarding reading the registers, I think that you need to define a type as well.

This is what I am using (just an example):

properties.VoltageVan = {key="input_register/1/30002?format=Float", handler="modbus_handler1", basetype="NUMBER"}

Its always good idea to use some network protocol analyzer (Wireshark is the best no doubt) when dealing with low-layer communication.

--> Tomas

Re: Connect Thingworx and PLC

Thanks for your information.

I'm using Modbus over TCP protocol. And I could read holding register data from  PLC with holding_register function in modbus_handler.lua.

But,I can't write data from ThingWorx to PLC via EMS.The cause is timeout like this:

[ERROR] 2016-02-01 17:17:39,410 modbus:executeFunction: Error: Timed out waiting for result.

[ERROR] 2016-02-01 17:17:39,410 luaInterscriptBinding::l_executeCallback: Error executing callback 'modbus_handler//scripts/modbus_handler/holding_register/1/40001'

Returned: 500 Timeout

[WARN ] 2016-02-01 17:17:39,411 MyPLC: Could not write property: Int16HoldRegExample, code: 500, msg: Timeout

Does the holding_register function include not only reading holging_register value but writing the same holding_register value?

Or should I set something else for writing property ? If you know,please teach me...

Re: Connect Thingworx and PLC

Holding Registers should be able to be read and written to.

What function are you using for the write?

Re: Connect Thingworx and PLC

I would be interested in that function as well.

What kind of PLC system are you using? Systems which I am familiar with needs a proper configuration in a project in the first place to allow MODBUS registers (coils and holding registers) to be written into. It is a safety issue. Use Wireshark to capture Modbus packets sent and recieved from/by your lua script. That could give you some clue.   

Re: Connect Thingworx and PLC

Can you post the property string you're using in your modbus template.lua file?

Re: Connect Thingworx and PLC

This line is for setting property.

properties.Int16HoldRegExample = {value="300", dataChangeType="ALWAYS",pushType="ALWAYS", key ="holding_register/1/40001?format=Int16", handler="modbus_handler", basetype="NUMBER"}

And,these line are for setting services to get property value.

services.getAllProperties = function(me, headers, query, data)

  log.debug(me.name, "Called getProperties")

  local postdata = {content='{"slave": 1 ,"address": 40001 , "count": 1, "data": "string"}'}

  return tw_script.executeCallback("modbus_handler", "POST", "holding_register", headers, query, postdata)