Hi, I would like to pull the Ignition Gateway time, preferably as an array of DINTs, that I can then send to my PLC. We have one AB PLC that is connected to our gateway, and every other plant PLC is connected to that original PLC. All important data passes through that PLC to get to Ignition and then to a SQL database. It is a terrible setup that I am in the process of changing. But for now, none of our PLCs have access to the IT world and I want to have a way to sync the time of all of our PLCs without being able to use an NTP server. I’m hoping there is a way that I can pull the Ignition gateway time, convert it to a dint structure similar to the time structure in studio, then do an SSV, as well as have all the other PLCs being able to pull the time from our main PLC.
I can get the epoch time, but I didn’t know if there was already a structure that separates it all into individual items (year, month, day, hour, min, sec, msec). Otherwise, I may have to do some sort of conversion either in the PLC or in Ignition.
I think the
system.date.get* functions should help you break the current date down into components.
From there it’s up to you to write those to tags in the main PLC, trigger an SSV somehow, then sync it to the other PLCs.
You didn’t specify what platform you were using, but you could use the Clock Update Tool for your one PLC under windows (okay-ish, and better than setting up multiple tags and SSV-ing it) or set up the Ignition server as an NTP or PTP server under Linux (better).
Thanks Kevin. I was actually looking at doing just that. But I couldn’t find if it was using client time or gateway time…I guess system implies gateway time?
Using Studio 5000, version 30 or later on almost everything. I do use the clock update tool, but I don’t have any computers that are always connected to the network. I use a laptop that I take home every night. So it works ok, but I want something more permanent.
I am intrigued by the idea of using Ignition as an NTP server…If I use a network switch, can I just point the time server address to my gateway address?
It depends on the scope you execute your script in.
Vision Client button press or Designer script console? Client.
Perspective button press or Gateway timer script? Gateway.
Sorry for my ignorance…don’t use Ignition much. Can you explain what you mean by Gateway timer script?
Buy the $500 Time Machines TM2000B. Turn on PTP multicast. Turn on Clock Synchronization in your PLCs (a checkbox in controller properties). For ControlLogix prior to L8x, enable clock sync in the network module connection in your I/O tree, too.
Sit back and watch all your Logix PLCs synchronize to within a few microseconds of each other.
The TM2000B is also an NTP server to which you can point your gateway (and other servers) to get millisecond-grade time synchronization.
Thanks everyone for the input…have been pulled away from this and am now back.
I would like to write a Gateway Event Script that pulls the system time in unix time (either in seconds or in milliseconds), then I will multiply by 1000 or 1000000 respectively to get it into microseconds
This is my script:
unixTime = time.time()*1000000
Works in the script console but not as a gateway event script. Any help would be appreciated.
Okay, if you insist. Doesn’t really give you microsecond time accuracy, just adds some zeros to what is really just seconds since Epoch.
But if you’re going to do it this way then:
unixTime = system.date.toMillis(system.date.now())
@pturmel’s recommendation, is IMO by far the best solution and will yield true microsecond time accuracy at the PLC level.
Thanks for the answer…I know what I am asking is weird, but I don’t need accuracy. I just need consistency. The way my company has our network set up is a little convoluted. We only have on PLC connected to the gateway. Every other PLC is connected through another network card on the PLC. Once I get the microsecond unix time, I can do a SSV to write that time to the plc, then I can either message or produce either the LINT or the individual time DINTs to all of the other PLCs, at the beginning of each shift.
And your script worked for me in the console, but it did not work for me as a Gateway Event
Thank you again,
I don’t think that what you’re asking is weird at all. You may not need accuracy, but why not get it when you can. If what you need is consistency, why would you depend on a software solution?
It makes much more since to use a hardware device (such as the TM2000B) connected to the controller in combination with the controller configurations to manage this, then you get both accuracy and consistency.
The controllers should be configured for Clock Synchronization. Then there is no need for any added logic or Ignition, the controllers just sync and all is well. I don’t think you’ll be able to write any script in Ignition which is as consistent as that.
What error are you getting? The script syntax is correct, so either there is something other than what I provided or the event is not executing when/how you expect it to.
I’m not getting any errors, but the tag in Ignition doesn’t update from the Gateway Event Script. Only when I run it in the script console
What type of event is it, and how do you have it configured?
I have tried on both a Timer and a Scheduled. In order to test, I have it more frequently. For the timer, I had it scheduled every 5 seconds. For the Scheduled, I could only go as often as every minute. But still neither are working.
What kind of tag is it? You didn’t make a Vision Client Tag by mistake did you?
Add print logging to the script and also print the result of the system.tag.write call.
It is just an OPC tag. It is not read only