<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Sending Sequential Modbus TCP Packets</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b7d2d5b8ab/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b7d2d5b8ab/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/b7d2d5b8ab/</id><updated>2024-03-08T11:27:29.278000Z</updated><subtitle>Recent posts to Sending Sequential Modbus TCP Packets</subtitle><entry><title>Sending Sequential Modbus TCP Packets</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b7d2d5b8ab/?limit=25#4272" rel="alternate"/><published>2024-03-08T11:27:29.278000Z</published><updated>2024-03-08T11:27:29.278000Z</updated><author><name>ph0010421</name><uri>https://forge.codesys.com/u/ph0010421/</uri></author><id>https://forge.codesys.com88c7a7c542b8a14639ba0dbb87341f6b00709a77</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello&lt;br/&gt;
You'll need to write a proper sequence to send, then wait for confirmation, and then move on to the next step.&lt;br/&gt;
Use the CASE statement in ST. It's perfect for creating a sequence.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Sending Sequential Modbus TCP Packets</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b7d2d5b8ab/?limit=25#3b9f" rel="alternate"/><published>2024-03-06T20:32:58.654000Z</published><updated>2024-03-06T20:32:58.654000Z</updated><author><name>testlogic</name><uri>https://forge.codesys.com/u/testlogic/</uri></author><id>https://forge.codesys.com540584e1f2b346b1dba08365e7c84487f6a24807</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have a Modbus TCP slave device where I need to do sequential writes to the same register.&lt;br/&gt;
The register I'm writing to is kind of like a command line, each packet is a command word encoded in Hexadecimal.&lt;/p&gt;
&lt;p&gt;I am having difficulty implementing this system in CoDeSys 3.5 SP19. I feel like the structure of the program should be something along the lines of (Pseudocode):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;ModbusTCPSend(Command Register, Command1)
ModbusTCPSend(Command Register, Command2)
ModbusTCPSend(Command Register, Command3)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I have tried to implement this with a rising edge trigger&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nv"&gt;wMot1OPCode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="nv"&gt;E1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;Stop&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;Motor&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&amp;amp;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;Kill&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;Program&lt;/span&gt;
&lt;span class="nv"&gt;xMot1SendOP&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;Send&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;OP&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;on&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;rising&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;edge&lt;/span&gt;
&lt;span class="nv"&gt;xMot1SendOP&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;FALSE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;Reset&lt;/span&gt;
&lt;span class="nv"&gt;wMot1OPCode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="nv"&gt;E&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;Disable&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;Motor&lt;/span&gt;
&lt;span class="nv"&gt;xMot1SendOP&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nv"&gt;TRUE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;Send&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;OP&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;on&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;rising&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;edge&lt;/span&gt;
&lt;span class="nv"&gt;xMot1SendOP&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;FALSE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nv"&gt;Reset&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Where "wMot1OPCode" is the IO map for writing to the command register, and "xMot1SendOP" is the rising edge trigger for that modbus channel.&lt;br/&gt;
However, this doesn't work. The device never responds to the modbus commands. It seems like the trigger variable is switched too quickly for modbus to send the packet. &lt;/p&gt;
&lt;p&gt;I know the modbus register is working, because I can set the channel to cyclic and the device will respond. However, I can't use this reliably because I need each command to be sent once, in order. Cyclic keeps re-sending the commands and seems like it could miss a command as well if one was sent in-between cycle time. &lt;/p&gt;
&lt;p&gt;I have also trying using the Application trigger as described by &lt;a href="https://faq.codesys.com/pages/viewpage.action?pageId=24510480" rel="nofollow"&gt;https://faq.codesys.com/pages/viewpage.action?pageId=24510480&lt;/a&gt;, but this is also not working for me. See attached picture for my FBD code. &lt;/p&gt;
&lt;p&gt;This seems like a simple function, I can't tell what I'm doing wrong here. Thanks for the help.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>