RobotStudio event

PCSDK: How to set controller time (sample)




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. Ouch
 
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. Dead
 
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]
Clap
 
 
 
 

John Wiberg2012-10-22 09:36:37