Twido master with 2 slaves

M

Thread Starter

Marius

I'm trying to establish communication between a Twido working as a master and two PM710 devices working as slaves, but I have problems using the EXCHx and MSGx functions.

I can only send the first message to the first Modbus device using the EXCHx function. After this, the value of MSGx.D never goes back to one and so the next message using another EXCHx function can't be sent. It keeps sending the first message and receiving an answer from the same slave over and over again. I configured it in the same way it's described in the TwidoSuite V2.0 Programming Software Online Help in the in the description of the Exchange Control Function Block (%MSGx) - Transmission of Several Successive Messages.

Can anyone please send an example in wich a Twido acts as a master and sends multiple messages to slaves?

My email is [email protected]

Thanks in advance.
 
V

Vittorio Giannini

Hi

I've solved the problem introducing sync variables acting like semaphores (plus the %MSG2.D internal communication state variable): If you read the snippet code below you see that I have 3 different PM9Cs multimeters from which I've to read 56 registers. In general if you want read N modbus slaves (N>1) you must use N-1 variables plus MSG2.D.

In this case I've used 2 variables MW89 and MW90 that are set/reset in the corresponding rug.

I didn't use Boolean variables (for example %M89 %M90) because the configuration below produces warnings on twido suite: "warning: variable is written several times".

It is also possible use the same criteria if you use EXCHx command with the corresponding transmission table.
hope this help.<pre>
(* PM9 MAIN*)
LD %MSG2.D
AND [ %MW89 = 0 ] (* compare block *)
AND [ %MW90 = 0 ] (* compare block *)
[ %MW3 := 1000 ]
[ C_RDNW 0 56 ] (* macro 0: reading 56 registers from first PM9C*)
[ %MW89 := 1 ] (* set MW89 *)
[ %MW90 := 0 ] (* reset MW90 *)
(* PM9 FM first floor *)
LD %MSG2.D
AND [ %MW89 = 1 ]
AND [ %MW90 = 0 ]
[ %MW303 := 1000 ]
[ C_RDNW 1 56 ] (* macro 1 reading 56 registers from second PM9C *)
[ %MW89 := 0 ]
[ %MW90 := 1 ]
(* PM9 pump 1*)
LD %MSG2.D
AND [ %MW89 = 0 ]
AND [ %MW90 = 1 ]
[ %MW403 := 1000 ]
[ C_RDNW 2 56 ] (* macro 2 reading 56 registers from third PM9C *)
[ %MW89 := 0 ]
[ %MW90 := 0 ]

(* variables MW89 and MW90 are used for sync the modbus requests to PM9Cs.*)</pre>
 
> I've solved the problem introducing sync variables acting like semaphores
> (plus the %MSG2.D internal communication state variable): If you read the snippet
> code below you see that I have 3 different PM9Cs multimeters from which
> I've to read 56 registers. In general if you want read N modbus slaves (N>1) you
> must use N-1 variables plus MSG2.D.

perfect! i've succeed
Grazie mille :)
 
now i have another problem: Check communications error.

If a slave does not respond or is disconnected, in the Twido memory remains the last value read from this.

How to solve this?

Thank you
 
V

Vittorio Giannini

Communication errors are managed on twido by system words %SW63 and %SW64. Catching the error code you can do different actions.
Regards, Vittorio

from twido help:
If an error occurs when using the EXCHx instruction, bits %MSGx.D and %MSGx.E are set to 1 and system word %SW63 contains the error code for Port 1, and %SW64 contains the error code for Port 2.


%SW63 EXCH1 error code:
0 - operation was successful
1 - number of bytes to be transmitted is too great (> 250)
2 - transmission table too small
3 - word table too small
4 - receive table overflowed
5 - time-out elapsed
6 - transmission
7 - bad command within table
8 - selected port not configured/available
9 - reception error
10 - can not use %KW if receiving
11 - transmission offset larger than transmission table
12 - reception offset larger than reception table
13 - controller stopped EXCH processing

%SW64 EXCH2 error code: See %SW63.
 
> Communication errors are managed on twido by system words %SW63 and %SW64.
> Catching the error code you can do different actions.

I try with this but when I look at the animation table in Twido, the system word %s64 is still 0, even if i remove the slave. The same thing happened with MSGx.E, and MSGx.D.

Thank you
 
Top