CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Fri Nov 24, 2017 5:51 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
 Post subject: CAA NBS - NTP request
PostPosted: Thu Oct 12, 2017 11:00 am 
Offline

Joined: Thu Mar 17, 2016 1:24 pm
Posts: 42
Hi. I try to use CAA Net Base Servises (3.5.5.0) to get current time from NTP-server. My Device - CODESYS Control Win V3 (3.5.5.0).

NTP-server: 129.6.15.28 (time-a.nist.gov)
http://tf.nist.gov/tf-cgi/servers.cgi

I take example of NTP-request (0x1B and 47 NULL bytes) from this:
https://stackoverflow.com/questions/119 ... er-using-c

I test it with Hercules utility, and it works:
Image

Now I want to make this with CODESYS Control Win V3 - and I can't get response from server.
And no errors in all NBS fb's.

Maybe somebody will be able to found my mistakes and describe it.
I will be really grateful.

My code:

Code:
   iStep:            INT;

   fbUdpPeer:          NBS.UDP_Peer;
   hPeer:             NBS.CAA.HANDLE;
   fbUdpSend:          NBS.UDP_Send;
   fbUdpReceive:          NBS.UDP_Receive;
   stNtpAddress:         NBS.IP_ADDR;
   
   abyNtpRequest:       ARRAY [0..47] OF BYTE:=[16#1B, 47(0)];
   abyNtpResponse:      ARRAY [0..47] OF BYTE;
   
   fbSynchroPeriod:      TON;
   fbTimeout:          TON;



Code:
fbSynchroPeriod
(
   IN:=NOT(fbSynchroPeriod.Q),
   PT:=T#15S
);

stNtpAddress.sAddr:='129.6.15.28';

CASE iStep OF
   
0:
   fbUdpPeer
   (
      xEnable      :=   TRUE,
      ipAddr      :=      ,
      uiPort      :=   4023,
      ipMultiCast   :=       ,
      hPeer      =>   hPeer
   );

   IF fbUdpPeer.xActive THEN
      iStep:=10;
   END_IF
   
   
10:

   fbTimeout(IN:=FALSE);

   fbUdpSend
   (
      xExecute   :=    fbSynchroPeriod.Q,
      udiTimeOut   :=    , 
      hPeer      :=    hPeer,
      ipAddr      :=    stNtpAddress,
      uiPort      :=    123, 
      pData      :=    ADR(abyNtpRequest),
      szSize      :=    SIZEOF(abyNtpRequest)
   );   
   
   IF fbUdpSend.xDone THEN
      fbUdpSend(xExecute:=FALSE);
      iStep:=20;
   END_IF
   
   
   20:
   
   fbTimeout(IN:=TRUE, PT:=T#6S);
   
   fbUdpReceive(
      xEnable   :=   TRUE , 
      hPeer   :=   hPeer ,
      pData   :=   ADR(abyNtpResponse) ,         // fixed
      szSize   :=   SIZEOF(abyNtpResponse) ,       // fixed
    );

   IF fbUdpReceive.xReady THEN
      iStep:=10;
   END_IF
   
   IF fbTimeout.Q THEN
      iStep:=10;
   END_IF
   
END_CASE


Top
   
PostPosted: Fri Oct 13, 2017 5:05 am 
Offline

Joined: Thu Mar 17, 2016 1:24 pm
Posts: 42
I found my mistake and edit first post. Now it works.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited