Modbus_Tcp More Than One Device


polilies

Recommended Posts

my question is pretty clear i think;

i have 25 RTU device and i wanna read them via modbus TCP.

should i create more then one "Ehernet(TCP/IP) device" like RTU_1 and RTU_2..... RTU_25 with diffirent ip.

or should i create one "Ehernet(TCP/IP) device" and add it 25 port thing with different ip'es then poll them like this


while(1)
device.RTU.Port(RTU_1) // is this the true way of changing port of created ethernet device
IL1_RMS = device.RTU.ReadHoldingU16(0,20606,1)
IL2_RMS = device.RTU.ReadHoldingU16(0,20607,1)
IL3_RMS = device.RTU.ReadHoldingU16(0,20608,1)
device.RTU.Port(RTU_1)
delay(10)
IL1_RMS_2 = device.RTU.ReadHoldingU16(0,20606,1)
IL2_RMS_2 = device.RTU.ReadHoldingU16(0,20607,1)
IL3_RMS_2 = device.RTU.ReadHoldingU16(0,20608,1)
endwhile
[/CODE]

can you tell me which one will work? Thank you.

Link to comment
Share on other sites

Well, device.rtu.port(RTU_1) isn't going to work at all. For one, port is a variable not a function, and second, DF will think RTU_1 is a variable as well, not the port #. I'm not quite sure what you were trying to do with that statement.

If you have 25 fixed devices its probably easiest to simply create 25 devices within DAQFactory. If they are all duplicates, you should consider using objects and dynamic comm object creation. There is at least one other post here somewhere that really dives into that technique.

Link to comment
Share on other sites

i was thinking if i may create one modbus_tcp devicepost-6691-0-15208000-1350118611_thumb.jp and then in it create 25 "serial/ethernet port"post-6691-0-92690000-1350118587_thumb.jp. So when i change the "IP" adress

via "serial/ethernet port" option i can reach the RTU with out changing device. But i don't know if there is a way about this. my RTU's IP

adresses all different.

i look for the post that you suggest but can't find it still.

Link to comment
Share on other sites

You can create one serial/ethernet device and then change the IP address on it. You only need one device, one port and one protocol. The script to change the ip is simply (for your device named "RTU")

device.RTU.address = "10.0.0.1"

device.RTU.initComm()

// do some comms with device at 10.0.0.1

device.RTU.address = "10.0.0.2"

device.RTU.initComm()

// do some comms with device at 10.0.0.2

// etc.

It works fine. Its just slow. You probably will need a small delay, say delay(0.1) after the initComm().

Link to comment
Share on other sites

  • 3 months later...

i'll try your last post. That's nice. but i'm trying to evaluate a string script if u help me. i hope that'll be faster and flexible.

here is my script


data = evaluate("Device.rtu["+DoubleToStr(x)+'].device.ReadHoldingFloat(rtu['+DoubleToStr(x)+'"].id,22016,1)"')
[/CODE]

and the class definition

[CODE]
class rtu
local id
local string device
local string adres
local failure //1 ise iletisim var 0 ise yok!
local second
local exsec
local role1_il1
local role1_il2
local role1_il3
local role1_ac
local role1_kapa

local role2_il1
local role2_il2
local role2_il3
local role2_ac
local role2_kapa

local role3_il1
local role3_il2
local role3_il3
local role3_ac
local role3_kapa

endclass
global rtu[0] = new(rtu)
rtu[0].device = "RTU_5C1"
rtu[0].adres = "-n 1 188.59.84.254"
rtu[0].id = 1
rtu[0].failure = 0
[/CODE]

Link to comment
Share on other sites

First, you can't index items under device (i.e. device.rtu[1] is not valid).

But you can create a member function in your class:


function read22016()
device.RTU.address = adres
device.rtu.initcomm()
delay(0.1)
private data = device.rtu.readHoldingFloat(id, 22016,1)
return data
endfunction

[/CODE]

Then you can instantiate as many rtu classes as you want (don't store them in a variable with the same name though!), and call the read22016() function to get the value for that particular RTU.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.