Home AMX User Forum NetLinx Studio

Homemade Clocks

I have a TP that displays clocks from 5 different time zones. The problem is, due to the classification of the system, I am not allowed to connect it to the internet so I can't use an application like i!-TimeManager. No worries, I just pounded out the code myself to allow the user to set the local time and from there, it adds or subtracts hours depending. Probably not the most cost effective way to handle it, but this is what I did:
nIraq = ATOI(LEFT_STRING(TIME,2))
nZulu = ATOI(LEFT_STRING(TIME,2))
nQatar = ATOI(LEFT_STRING(TIME,2))
nAfghanH = ATOI(LEFT_STRING(TIME,2))
nAfghanM = ATOI(MID_STRING(TIME,4,2))

I can then take those integers and manipulate them however I need to. Afghanistan is weird because they are 9 and a half hours ahead. I created a timeline to query TIME every second. Is there a better way to do this?

Comments

  • ericmedleyericmedley Posts: 4,177
    I'm one of those that had to create my own clock system because a good majority of our clients are international business people and whatnot. I had several clients who actually wanted to be able to set the clocks in their houses to another time zone so they'd be synced up with their main offices.

    Having said that, I don't use the built-in clocks on the Touch panels. I also wrote my own time manager that looked at the NIST atomic clock for time sync. It was great since they had their own system of communicating when daylight savings time was on or off. I still don't like the network time protocol way of doing things.

    However, NIST has discontinued their time service such as it is. It is now following the NTP and is hence forth not worth using.

    I now use a Netlinx master here at my office that serves time to all my masters. The local clocks are set from the Mothership. I have a routine that sends the time to the touch panels in vari-text windows. It ticks off seconds. There is also a time set window that allows the client to set the clocks any way they want and it creates an offset from the master clock.

    I realize with the current NI firmware the clocks are syncing to an NTS 'under the hood' I still have my routine running too. So, my internal clocks stay real synced up. :)

    However, what gets displayed on the screen is not a TP time button but a text string created from the NI master.

    Some here have expressed a concern that this would create too much network traffic. However, I have systems with 20-some moderos and 20-some G3's that work just fine. I don't usually send second ticks to G3s.

    That's how I roll.
  • AMXJeffAMXJeff Posts: 450
    I have a TP that displays clocks from 5 different time zones. The problem is, due to the classification of the system, I am not allowed to connect it to the internet so I can't use an application like i!-TimeManager.

    The problem is a little deeper then you think, when you start to think about daylight savings time, plus DST is different in other countries. See attachment, I think this covers almost all situations.

    This code uses a slightly modified TimeDataLib.axi then we normally have. But the idea is simple. It allows you to set up each city, with different Daylight Savings Times with offset from Zulu Time.
    //////////////////////////////////////////////////////////////
    // TIMEZONES
    //////////////////////////////////////////////////////////////
    LoadTimezone(1, 'San Francisco', 	-8, TDL_USA, 0, 0, 0);
    LoadTimezone(2, 'Denver', 				-7, TDL_USA, 0, 0, 0);
    LoadTimezone(3, 'Chicago', 				-6, TDL_USA, 0, 0, 0);
    LoadTimezone(4, 'New York', 			-5, TDL_USA, 0, 0, 0);
    LoadTimezone(5, 'London', 				 0, TDL_MARCH, TDL_LAST_SUNDAY, TDL_OCTOBER, TDL_LAST_SUNDAY);
    LoadTimezone(6, 'Paris / Rome', 	 1, TDL_MARCH, TDL_LAST_SUNDAY, TDL_OCTOBER, TDL_LAST_SUNDAY);
    LoadTimezone(7, 'Dubai', 					 4, 0, 0, 0, 0);
    LoadTimezone(8, 'HK / Shanghai', 	 8, 0, 0, 0, 0);
    LoadTimezone(9, 'Tokyo', 				 	 9, 0, 0, 0, 0);
    
    

    Display on the TP with the Local Zulu Time offset.
    DEFINE_PROGRAM
    
    UI_DisplayTimes(-5);
    
  • Wow. That is over my head, but I think with time, I should be able to understand it. Thanks. My "clocks" only use 42 lines of code, but all of my data is hard coded. The only fancy trick I did was:
    IF (nZulu > 23)
    {
         nZulu = (nZulu - 24)
    }
    
    

    All that does is prevent the hours from going to 24 and above. The idea of daylight savings time had crossed my mind, but I was thinking of having a DST radio button to check when setting the clock. The only problem, now that you have mentioned it, some countries celebrate DST while others do not. In order for everything to work, I would have to hard code all of that info with a bunch of IF statements. My 42 lines was only for one time zone. Times that by 4 for each of the timezones where the TP could reside, then figure in the DST options, and I would be writing lots of code with hard coded variables. In my short experience, hard coded variables mostly work on a prayer. I have learned so much, but I still have much more to go. Thanks for the example and reply.
  • ericmedley wrote: »
    However, what gets displayed on the screen is not a TP time button but a text string created from the NI master.

    Some here have expressed a concern that this would create too much network traffic. However, I have systems with 20-some moderos and 20-some G3's that work just fine. I don't usually send second ticks to G3s.

    That's how I roll.

    Yeah, that is what mine is doing too. When I was first toying with it, I displayed the time via the SetUp Port option in TPD4. After I really got into it, that quickly changed.

    BTW, what stratum level is the internal clock on a NetLinx? How often can a user expect clock drift on a system that has no external source for checking the time?
  • AMXJeffAMXJeff Posts: 450
    How often can a user expect clock drift on a system that has no external source for checking the time?

    Of course you will need to change the time on every DST change, other then that, the clock will drift a few seconds a year i would guess... Accurate enough for TPs....
  • a_riot42a_riot42 Posts: 1,624
    AMXJeff wrote: »
    Of course you will need to change the time on every DST change, other then that, the clock will drift a few seconds a year i would guess... Accurate enough for TPs....

    Interesting, I have not found this to be the case. I have found that Master time can drift quite a bit. Maybe rebooting them more often makes for more drift I haven't tested for that.
    Paul
  • ericmedleyericmedley Posts: 4,177
    a_riot42 wrote: »
    Interesting, I have not found this to be the case. I have found that Master time can drift quite a bit. Maybe rebooting them more often makes for more drift I haven't tested for that.
    Paul

    As I understand the NTP driver on the Netlinx master, it does the typical checking of multiple NTS's and compares itself to them and averages them all out. If it's typical, it probably checks itself several times a day.

    Some sophisticated time checking routines will even try to figure out what its own internal clock drift tends to be and will schedule accordingly.

    My routine checks a couple times a day and that seems to keep it honest enough for most people. After all, we're not trying to align satellite communications or 200" reflector telescopes. We just want the landscape lighting to come on around the right time. :)
  • ericmedley wrote: »
    After all, we're not trying to align satellite communications or 200" reflector telescopes.
    I'm trying to align satellite communications. ;) The way people act around here, you would think I was aligning satellites.

    Back to the clock drift topic, if you guys remember that Binary Clock topic I started a couple of months ago, I have been running a binary clock as a screen saver on my TP every since then and I have not noticed any clock drift. I was wondering, is the hardiness of the clock at all related to the hardiness of the frequency of the power? If the power freq fluctuates, won't that affect the clock? Also, pinging the clock every second for a binary clock makes for a cool, geeky screen saver, but that is not going to wear anything out is it? I mean, I am not shortening the life of my little NI-700 by doing that am I?
  • Joe HebertJoe Hebert Posts: 2,159
    pinging the clock every second for a binary clock makes for a cool, geeky screen saver, but that is not going to wear anything out is it? I mean, I am not shortening the life of my little NI-700 by doing that am I?
    The NI-700 will be fine, however, you are most likely shortening the life of the touch panel backlight if the "screen saver" keeps it on 24/7.
  • Joe Hebert wrote: »
    The NI-700 will be fine, however, you are most likely shortening the life of the touch panel backlight if the "screen saver" keeps it on 24/7.
    Ooops. :rolleyes:
  • DarksideDarkside Posts: 345
    A vast majority of our work is corporate and it's fairly rare that the IT guys will stick us on their network or punch a hole in the firewall for us to go out and grab a hold of an NTP server, so, we too were stuck with the problem of the accuracy of the NI clock - which I might add is pretty good for the bulk of our stuff!!

    Not long ago we had a system that needed extremely accurate time and date stamping for a security DVR file extraction process to a PC, so we looked at several methods of tightening this process up and ended up installing a AUD$200.00 GPS to the system and sucking the time and date out of that via serial.

    I created a couple of calendar events based on our local DST rules, and adjusted the time on the inbound strings from the GPS.

    Neat, sweet and very accurate.
  • a_riot42a_riot42 Posts: 1,624
    If you work in corporate environments then they will likely have a ntp/sntp server running on the network like a Windows domain server on port 123. They are usually set up to provide time to all nodes on the network. If you use the i!-TimeManagerMod and use the IP address of the Windows server then I don't really see why this wouldn't work to get correct time for your master.
    Paul
  • DarksideDarkside Posts: 345
    a_riot42 wrote: »
    If you work in corporate environments then they will likely have a ntp/sntp server running on the network like a Windows domain server on port 123. They are usually set up to provide time to all nodes on the network. If you use the i!-TimeManagerMod and use the IP address of the Windows server then I don't really see why this wouldn't work to get correct time for your master.
    Paul
    It's almost a certainty that they have an NTP server in their network, however, as I mentioned before, in some of our 'more serious' corporates, we aren't even allowed to look at their network sockets, let alone plug in to them!! No amount of whitepaper reading will convince these guys that an NI and TP will be ok on the network!

    We are nearly always creating closed AMX networks for purely this reason in these high profile environments, which doesn't cause an issue until you need accuracies as described above - thus the GPS solution!

    When we do get to hop on their network, the NTP implementation is generally straightforward. Same with our VC solutions.
  • GSLogicGSLogic Posts: 562
    Almost a CLOCK!

    Attached is a binary clock/date module that can be fun, when trying to explain to non-code people how you read the time and date.
  • AMXJeffAMXJeff Posts: 450
    Here is a link from the old Binary Clock Thread....


    http://www.amxforums.com/showthread.php?t=3306&highlight=Binary+Clock
Sign In or Register to comment.