<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Question about TCP Modbus Master Trigger</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/5acd387ad0/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/5acd387ad0/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/5acd387ad0/</id><updated>2020-02-27T14:06:55.336000Z</updated><subtitle>Recent posts to Question about TCP Modbus Master Trigger</subtitle><entry><title>Question about TCP Modbus Master Trigger</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/5acd387ad0/?limit=25#aa98" rel="alternate"/><published>2020-02-27T14:06:55.336000Z</published><updated>2020-02-27T14:06:55.336000Z</updated><author><name>Roy444</name><uri>https://forge.codesys.com/u/roy444/</uri></author><id>https://forge.codesys.com4083f0b8575ce491471e1adac16864443c8b0ccf</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;after linking code program and the modbus module to the same task&lt;br/&gt;
and also found a bug i had with the program, the trigger worked well!&lt;/p&gt;
&lt;p&gt;no need for different tasks.&lt;/p&gt;
&lt;p&gt;adding the code i ran with:&lt;/p&gt;
&lt;p&gt;TYPE Modbus_Data :&lt;br/&gt;
STRUCT&lt;br/&gt;
    Old:ARRAY&lt;span&gt;[0..15]&lt;/span&gt; OF BOOL := &lt;span&gt;[16(FALSE)]&lt;/span&gt;; &lt;br/&gt;
    New:ARRAY&lt;span&gt;[0..15]&lt;/span&gt; OF BOOL := &lt;span&gt;[16(FALSE)]&lt;/span&gt;;&lt;br/&gt;
    Trigger:BOOL := FALSE;&lt;br/&gt;
END_STRUCT&lt;br/&gt;
END_TYPE&lt;/p&gt;
&lt;p&gt;arrModbusData: ARRAY&lt;span&gt;[0..1]&lt;/span&gt; OF Modbus_Data;&lt;/p&gt;
&lt;p&gt;PROGRAM Modbus_programm&lt;br/&gt;
VAR&lt;br/&gt;
    wordIndex : UINT;&lt;br/&gt;
    bitIndex : UINT;&lt;br/&gt;
    isTriggerNeeded : BOOL; &lt;br/&gt;
    modbusDataArrayLength : int := SIZEOF(arrModbusData)/SIZEOF(Modbus_Data);&lt;br/&gt;
END_VAR&lt;br/&gt;
VAR CONSTANT&lt;br/&gt;
    NUMBER_OF_BITS_IN_WORD : INT := 16;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;isTriggerNeeded := FALSE;&lt;br/&gt;
FOR wordIndex:=0 TO modbusDataArrayLength -1  DO&lt;br/&gt;
    arrModbusData&lt;span&gt;[wordIndex]&lt;/span&gt;.Trigger := FALSE;&lt;br/&gt;
    FOR bitIndex:=0 TO NUMBER_OF_BITS_IN_WORD - 1 DO&lt;br/&gt;
    IF(arrModbusData&lt;span&gt;[wordIndex]&lt;/span&gt;.New&lt;span&gt;[bitIndex]&lt;/span&gt; &amp;lt;&amp;gt; arrModbusData&lt;span&gt;[wordIndex]&lt;/span&gt;.Old&lt;span&gt;[bitIndex]&lt;/span&gt;) THEN&lt;br/&gt;
        arrModbusData&lt;span&gt;[wordIndex]&lt;/span&gt;.Old&lt;span&gt;[bitIndex]&lt;/span&gt; := arrModbusData&lt;span&gt;[wordIndex]&lt;/span&gt;.New&lt;span&gt;[bitIndex]&lt;/span&gt;;&lt;br/&gt;
        isTriggerNeeded := TRUE;&lt;br/&gt;
    END_IF;&lt;br/&gt;
    END_FOR;  &lt;br/&gt;
    IF(isTriggerNeeded = TRUE) THEN&lt;br/&gt;
        arrModbusData&lt;span&gt;[wordIndex]&lt;/span&gt;.Trigger := TRUE;&lt;br/&gt;
    END_IF; &lt;br/&gt;
END_FOR;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Question about TCP Modbus Master Trigger</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/5acd387ad0/?limit=25#4127" rel="alternate"/><published>2020-02-27T14:06:55.034000Z</published><updated>2020-02-27T14:06:55.034000Z</updated><author><name>josepmariarams</name><uri>https://forge.codesys.com/u/josepmariarams/</uri></author><id>https://forge.codesys.com00a8bc9f707eb6ea9055abd8c49d3eaa826fd228</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Reset the trigger in the other task.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Question about TCP Modbus Master Trigger</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/5acd387ad0/?limit=25#d90b" rel="alternate"/><published>2020-02-27T14:06:54.727000Z</published><updated>2020-02-27T14:06:54.727000Z</updated><author><name>Roy444</name><uri>https://forge.codesys.com/u/roy444/</uri></author><id>https://forge.codesys.comc2f606883bf2454c549e6cf997fe3063fdb98032</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;I'll first describe the goal:&lt;br/&gt;
1. Have an outside device write into a variable of codesys.&lt;br/&gt;
2. Detect the variable in (1) has been changed.&lt;br/&gt;
3. After detection, make the modbus master write to another device via trigger.&lt;/p&gt;
&lt;p&gt;what I've tried to do:&lt;br/&gt;
make a stuct with:&lt;br/&gt;
LastValue : BOOL; //linked to the another device in (3)&lt;br/&gt;
CurrentValue : BOOL; //linked to the outside device in (1)&lt;br/&gt;
Trigger : BOOL; //linked to the modbus master trigger&lt;/p&gt;
&lt;p&gt;now i got a task where I do the following:&lt;br/&gt;
Trigger := FALSE;&lt;br/&gt;
IF (CurrentValue &amp;lt;&amp;gt; LastValue) THEN&lt;br/&gt;
    LastValue := CurrentValue;&lt;br/&gt;
    Trigger := TRUE;&lt;br/&gt;
END_IF&lt;/p&gt;
&lt;p&gt;When i ran this code, the trigger didn't work as planned, meaning the modbus master didn't update me about the change.&lt;br/&gt;
i mainly suspect about the syncing of the tasks, one task runs the code above controlling the trigger and another task runs the modbus master module who checks the trigger rising edge and performs the writing action.&lt;/p&gt;
&lt;p&gt;Questions:&lt;br/&gt;
1. how would you sync between the two tasks? how to control the trigger properly?&lt;br/&gt;
2. What type of scheduler protocol is being used, might help me understand the problem.&lt;/p&gt;
&lt;p&gt;Thanks in advance for any help&lt;br/&gt;
Roy.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>