ac-engineer-one - 2020-10-13

I'm using a BL20-PN-EN-DN-JA for a project in CoDeSys v2.3 that requires accurate timestamps for quality traceability.

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).

The old system relies on the operator + SysLibRtc.lib to produce timestamps:

  1. Operator pushes a button tied to SysRTCGetTime() to display the PLCs current time on the visualization
  2. Operator MANUALLY adjusts the displayed time to synchronize with the PC clock
  3. Operator pushes a button tied to SysRTCSetTime() to send the adjusted time back to the PLC.

This reliance on manual data entry has failed us many times in the past...

Among the project requirements, automating this time synch is a task that i'm struggling with.

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)->imported(myproject) any peripheral dependencies from the OSCAT libraries that were throwing errors...

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.

I read somewhere that the OSCAT Sntp function might only compatible with a host running <= Win7? (we're on win 10)
I adjusted the registries of the host PC to allow it to enable NTP server functionality
* My inputs to the SNTP_CLIENT() function are

fSNTP_CIENT(    IP_C   := ipc1,                      (data type i copied directly from OSCAT library)
                S_BUF  := sBuff,                     (Data type NETWORK_BUFFER copied from OSCAT)
                R_BUFF := rBuff,                     (Data type NETWORK_BUFFER copied from OSCAT)
                ACTIVE := bActive,                   (bool i throw high to activate the function)
                IP4    := IP4_DECODE('10.10.XX.XX'));(ip of my connected PC passed through the IP4_DECODE
                                                     function i exported from OSCAT. i've also tried
                                                     feeding the IP from DNS_CLIENT.IP4)
       (outputs omitted since i'm not receiving any)
  • I receive 16711680 (=0hFF0000) from the ERROR output -> Connection timeout
  • I'm not a network guru - wondering if firewalls are to blame? I tried to disable windows firewall and saw no difference
  • 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.
  • I can display the PCs clock using %t%a %b %d.%m.%y%H:%M:%S 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?
  • Any other methods to snychronize the PLC clock?
  • 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...

Any thoughts? I can share a gutted version of my source with the OSCAT functions included if it would help.

Thanks in advance!


Last edit: ac-engineer-one 2020-10-13