PCSDK: How to set controller time (sample)
John Wiberg
✭✭✭
Since its a bit tricky I created this sample:
Its a Visual Studio 2010 C# project with PCSDK 5.14.03 components.
You need Visual Studio express 2010 or 2012 to open and use it.
The problem is the the DateTime format has different Kinds.
The IRC5 controller's datetime is ALWAYS in UTC. Yes, I know that you have probably set it to local time, but the DateTime Kind of the controller is UTC.
This means that if I "set" the controller DateTime to a non-UTC kind it will automatically convert it to UTC time.
So what you need to do is specify the kind of the time you want to set it to.
Yes that confused me to.
But lets look at code instead and you will see what I mean:
If I would do this:
[code]this.controller.DateTime = DateTime.Now;[/code]Then it will convert it and thus change it. This because the DateTime.Now always is in kind LOCAL.
But if I do this:
[code]this.controller.DateTime = DateTime.UtcNow;[/code]Then both are in UTC and the time will not be changed.
However both the snippets above will generate the EXACT SAME TIME.
So how do I do if I want to use the local time?
Well you specify the kind, like this:
[code]this.controller.DateTime = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);[/code]
John Wiberg2012-10-22 09:36:37
John
Developer Center
Developer Center
0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 799 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings