CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Sat Oct 19, 2019 3:44 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri Nov 30, 2018 8:10 am 
Offline

Joined: Mon Jan 22, 2018 10:07 am
Posts: 47
I have defined a Slave Device in ModbusTCP, as in picture 1 attached.
I defined the registers as picture 2 attached.
When the partner writes to an holding register I receive correctly the value, but I need to overwrite is after a while.
Codesys does not permit to me to do this, picture 3.
How can I overwrite the register?
Thank you


You do not have the required permissions to view the files attached to this post.


Top
   
PostPosted: Sat Dec 01, 2018 8:17 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 280
Hi

You cannot write an input.

Sent from my Moto G (5S) Plus using Tapatalk


Top
   
PostPosted: Mon Dec 03, 2018 2:24 am 
Offline

Joined: Mon Jan 22, 2018 10:07 am
Posts: 47
yes but they are Holding Registers and according to Modbus specification holding register can be read and written at the same way. May I use a library to achieve it?


Top
   
PostPosted: Mon Dec 03, 2018 3:51 pm 
Offline
Frequent User
Frequent User

Joined: Fri Feb 23, 2018 3:41 pm
Posts: 159
Modbus is a one way communication, It only allows one master to read/write into a slave. That said, if, Inside your slave, you need to update writeable values then you have several workarounds :

1) Don't always write with master, if you can edit it. Just write when you have to transmit a value change. You must read back the value with the master to update it on the master. Otherwise your master with have a different value than your slave.

2) You have no way to not write cyclically, then you may read before write. Meaning, first master reads, then update internally the write value. Then master will perform writes on your slave. This has one drawback : in case of writing your value just after the read and before the write, it will be overwrited by master's value. Operator/program may have to write more than once the value to correctly update it. This works best with low cycle time (modbus wise).

For exemple :
We have a setpoint on the slave. The slave may limit it -> this would be continuous value update (slave side) and will work flawlessly (protecting the setpoint before using it)


Top
   
PostPosted: Thu Jan 10, 2019 5:28 pm 
Offline

Joined: Fri Feb 16, 2018 5:39 pm
Posts: 27
What you have to do is take that modbus input and translate it to another variable that you can change. The simplest way to do this is with the function block SEL. What you have to do is consider when you want the modbus value to overwrite the local value.

Below is a very quick example, and there are better ways to do it especially with structured text. You would need to think of the control logic for both the trigger options. I might use a comparison of the stored modbus value with the input value and if it's not the same it stores the new value and resets the local override.


Image


Top
   
PostPosted: Fri Jan 11, 2019 5:09 pm 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 96
You should be able to write the input using pointer as follows:


Code:
PROGRAM POU
VAR
   myWord: POINTER TO WORD;
END_VAR

myWord:=ADR(iwModbusTCP_Slave_Device_Inputs_0);
myWord^:=777;        //Write the Full input Word
myWord^.0:=FALSE;   //Write bit 0 in input Word


_________________
The Original SoMachine Ninja


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited