Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > setting the hardware clock from ruby

Reply
Thread Tools

setting the hardware clock from ruby

 
 
Joel VanderWerf
Guest
Posts: n/a
 
      05-09-2004

Anybody happen to know if there is a platform independent way of setting
the hardware clock from ruby? I'm primarily interested in Windows at the
moment (for a port of some QNX code), so it can probably be done with
Win32API (or Ruby/DL, now). I didn't find much under "clock" on ruby
talk or "ruby set clock" on google. Any suggestions appreciated...


 
Reply With Quote
 
 
 
 
Joel VanderWerf
Guest
Posts: n/a
 
      05-10-2004
Joel VanderWerf wrote:
>
> Anybody happen to know if there is a platform independent way of setting
> the hardware clock from ruby? I'm primarily interested in Windows at the
> moment (for a port of some QNX code), so it can probably be done with
> Win32API (or Ruby/DL, now). I didn't find much under "clock" on ruby
> talk or "ruby set clock" on google. Any suggestions appreciated...


Setting local time on windows turned out to be an easy exercise in
Ruby/DL. For posterity, here's the code:

require "dl/import"
require "dl/struct"

module Kernel32
extend DL::Importable
dlload 'kernel32'

SYSTEMTIME = struct [
"WORD wYear",
"WORD wMonth",
"WORD wDayOfWeek",
"WORD wDay",
"WORD wHour",
"WORD wMinute",
"WORD wSecond",
"WORD wMilliseconds",
]

# These use GMT.
extern "void GetSystemTime(SYSTEMTIME*)"
extern "BOOL SetSystemTime(const SYSTEMTIME*)"

# These use local time, like ruby's Time.now.
extern "void GetLocalTime(SYSTEMTIME*)"
extern "BOOL SetLocalTime(const SYSTEMTIME*)"
end

# +time+ is a Time
def set_clock(time)
local_time = Kernel32::SYSTEMTIME.malloc

local_time.wYear = time.year
local_time.wMonth = time.month
local_time.wDay = time.day
local_time.wHour = time.hour
local_time.wMinute = time.min
local_time.wSecond = time.sec
local_time.wMilliseconds = time.usec/1000

unless Kernel32.setLocalTime(local_time)
raise "Could not set local time to #{time}."
end
end


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Single clock pulse transfer to different clock domains. himassk VHDL 1 05-16-2007 10:41 AM
Arbitrary Clock Frequencies From Base Clock abhisheknag@gmail.com VHDL 5 06-23-2006 12:45 PM
What is the best way to clock data in on one clock edge and out on another? simon.stockton@baesystems.com VHDL 4 04-26-2006 11:36 PM
Sync for PC clock and server clock PS Computer Support 3 05-13-2005 05:27 AM
Are clock and divided clock synchronous? Valentin Tihomirov VHDL 11 10-28-2003 01:18 PM



Advertisments