<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to TCP Server in Halcon example errors after client disconnects</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b80e2cd610/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b80e2cd610/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/b80e2cd610/</id><updated>2020-02-27T13:48:47.045000Z</updated><subtitle>Recent posts to TCP Server in Halcon example errors after client disconnects</subtitle><entry><title>TCP Server in Halcon example errors after client disconnects</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/b80e2cd610/?limit=25#43f7" rel="alternate"/><published>2020-02-27T13:48:47.045000Z</published><updated>2020-02-27T13:48:47.045000Z</updated><author><name>Onno</name><uri>https://forge.codesys.com/u/onno/</uri></author><id>https://forge.codesys.com0ba82f435feed372e786d8e87b371c32bc4e7704</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Setup: Schneider Electric TM251MESE running the TCP-Server code&lt;br/&gt;
With putty I connect to this plc with raw tcp communication on port 4711.&lt;/p&gt;
&lt;p&gt;The plc response is Hello World: 100&lt;br/&gt;
When I response with Hello World: 100 the response is Hello World: 99 etc.&lt;br/&gt;
As expected the value decrements every time the correct response is send back to the plc &lt;br/&gt;
The eState variable is switching from Init to Send to Read, Send, Read... &lt;/p&gt;
&lt;p&gt;After I close the putty window the state switches to Error then to Init, assuming this is expected behaviour.&lt;/p&gt;
&lt;p&gt;When I try to connect again the connection is made, the Hello World: __ string is returned and eState switches to Read.&lt;br/&gt;
The next cycle handling this state fails:&lt;br/&gt;
The putty window closes.&lt;/p&gt;
&lt;p&gt;Setting breakpoints: after executing&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;TCPRead&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;xEnable&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;TRUE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;hConnection&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;Connection&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;szSize&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;SIZEOF&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;sReceived&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; &lt;span class="nt"&gt;pData&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;ADR&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;sReceived&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;TCPRead.xError is true, eState switches from Error into Init.&lt;/p&gt;
&lt;p&gt;Every time I connect again the Hello World: __ string is send again but every attempt to receive (TCPRead) results in an Error then Init.&lt;/p&gt;
&lt;p&gt;Only by a cold reset I can connect again and send data back to the plc. &lt;/p&gt;
&lt;p&gt;What is happening?&lt;br/&gt;
Is there a method to reset the functionblocks in this example?&lt;/p&gt;
&lt;p&gt;I tried this example as I need to implement a connection from a robot to this plc.&lt;/p&gt;
&lt;p&gt;Are there any other examples of a simple tcp-server arround with some error handling?&lt;/p&gt;
&lt;p&gt;Thanks in advance!&lt;br/&gt;
Best regards,&lt;br/&gt;
Onno&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>