<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Synchronize PLC clock (OSCAT not working!)</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/620c99987f/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/620c99987f/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/620c99987f/</id><updated>2020-10-13T19:24:05.607000Z</updated><subtitle>Recent posts to Synchronize PLC clock (OSCAT not working!)</subtitle><entry><title>Synchronize PLC clock (OSCAT not working!)</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/620c99987f/?limit=25#0aa4" rel="alternate"/><published>2020-10-13T19:24:05.607000Z</published><updated>2020-10-13T19:24:05.607000Z</updated><author><name>ac-engineer-one</name><uri>https://forge.codesys.com/u/ac-engineer-one/</uri></author><id>https://forge.codesys.com1b610ca2a09a87ec920dcd405698b755d4dd05b1</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I'm using a BL20-PN-EN-DN-JA for a project in CoDeSys v2.3 that requires accurate timestamps for quality traceability.&lt;/p&gt;
&lt;p&gt;The PLC is connected to a PC, and the PC uses the Visualization tab displayed on its monitor as an HMI for the operator to control the procss (not ideal, but i did not design this syste... i'm simply trying to improve it per updated project requirements).&lt;/p&gt;
&lt;p&gt;The old system relies on the operator + SysLibRtc.lib to produce timestamps:&lt;br/&gt;
1) Operator pushes a button tied to SysRTCGetTime() to display the PLCs current time on the visualization&lt;br/&gt;
2) Operator MANUALLY adjusts the displayed time to synchronize with the PC clock&lt;br/&gt;
3) Operator pushes a button tied to SysRTCSetTime() to send the adjusted time back to the PLC.&lt;br/&gt;
This reliance on manual data entry has failed us many times in the past...&lt;/p&gt;
&lt;p&gt;Among the project requirements, automating this time synch is a task that i'm struggling with.&lt;/p&gt;
&lt;p&gt;I've dabbled with the OSCAT_NETLIB library and can't establish a network connection between the PLC and the PC.  To do so, i exported the SNTP_CLIENT() function to my project.  Compiled, then export(OSCAT)-&amp;gt;imported(myproject) any peripheral dependencies from the OSCAT libraries that were throwing errors...&lt;/p&gt;
&lt;p&gt;I work in structured text, but i believe that i'm understanding the FBD of the DNS_SNTP_SYSLOG_DEMO included in OSCAT_NETLIB... The example seems straightforward; hex IP address fed in, IP control datatype IP_C fed, Send (S_BUF) and Receive (R_BUF) buffers fed in.&lt;/p&gt;
&lt;p&gt;Thoughts:&lt;br/&gt;
&lt;em&gt; I read somewhere that the OSCAT Sntp function might only compatible with a host running &amp;lt;= Win7?  (we're on win 10)&lt;br/&gt;
&lt;/em&gt; My inputs to the SNTP_CLIENT() function are&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;fSNTP_CIENT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;    &lt;span class="n"&gt;IP_C&lt;/span&gt;   &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ipc1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;data&lt;/span&gt; &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="n"&gt;copied&lt;/span&gt; &lt;span class="n"&gt;directly&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;OSCAT&lt;/span&gt; &lt;span class="n"&gt;library&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;S_BUF&lt;/span&gt;  &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sBuff&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;Data&lt;/span&gt; &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;NETWORK_BUFFER&lt;/span&gt; &lt;span class="n"&gt;copied&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;OSCAT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;R_BUFF&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rBuff&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;Data&lt;/span&gt; &lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;NETWORK_BUFFER&lt;/span&gt; &lt;span class="n"&gt;copied&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;OSCAT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;ACTIVE&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bActive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                   &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="n"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;high&lt;/span&gt; &lt;span class="k"&gt;to&lt;/span&gt; &lt;span class="n"&gt;activate&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;IP4&lt;/span&gt;    &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;IP4_DECODE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'10.10.XX.XX'&lt;/span&gt;&lt;span class="p"&gt;));(&lt;/span&gt;&lt;span class="n"&gt;ip&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;my&lt;/span&gt; &lt;span class="n"&gt;connected&lt;/span&gt; &lt;span class="n"&gt;PC&lt;/span&gt; &lt;span class="n"&gt;passed&lt;/span&gt; &lt;span class="n"&gt;through&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;IP4_DECODE&lt;/span&gt;
                                                     &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="n"&gt;exported&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;OSCAT&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="s1"&gt;'ve also tried&lt;/span&gt;
&lt;span class="s1"&gt;                                                     feeding the IP from DNS_CLIENT.IP4)&lt;/span&gt;
&lt;span class="s1"&gt;       (outputs omitted since i'&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="n"&gt;receiving&lt;/span&gt; &lt;span class="k"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;I receive 16711680 (=0hFF0000) from the ERROR output -&amp;gt; Connection timeout  &lt;/li&gt;
&lt;li&gt;I'm not a network guru - wondering if firewalls are to blame?  I tried to disable windows firewall and saw no difference&lt;/li&gt;
&lt;li&gt;Do i need to use the DNS_Client OSCAT function in addition to the SNTP_Client function?  I see in the DNS_SNTP_SYSLOG_DEMO example in the oscat library, that the IP4 and ACTIVATE inputs are fed into the SNTP_Client function via outputs from the DNS_Client function.  I don't think this is necessary? But i've tried anyways with no luck.&lt;/li&gt;
&lt;li&gt;I can display the PCs clock using &lt;code&gt;%t%a %b %d.%m.%y%H:%M:%S&lt;/code&gt; as text displays in the Visualization.  Is there any way to read that text data back into a variable which i could then send into the SysRTCSetTime() function?&lt;/li&gt;
&lt;li&gt;Any other methods to snychronize the PLC clock?&lt;/li&gt;
&lt;li&gt;The BL20 manual states that the PLC battery is replaceable.  I know in most PLCs, the battery supports the retainment of system variables such as the RTC.  I ripped apart a spare PLC i had and didn't see any serviceable batteries...&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Any thoughts?  I can share a gutted version of my source with the OSCAT functions included if it would help.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>