Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Simple little ruby code for getting epoch time

For general discussion related FlowStone

Simple little ruby code for getting epoch time

Postby Quentin » Mon Mar 18, 2013 7:41 pm

I need to send out unix time to a micro and it seems easy to get windows epoch time using the ruby command and then do basic maths to convert to unix time-- I am still getting used to the ruby module in flowstone- I wrote this little piece of code which outputs the time in seconds but it is not updating the time each time I trigger the module- What am I doing wrong? The module is connected by a single trigger in and a single int out.

def event(in_id,value) # Input Events
case in_id
when 0 # update value
time = (Time.now.to_f * 1000.0).to_i
output 0, time
end
end

Thanks
Quentin
Quentin
 
Posts: 37
Joined: Sat Jul 14, 2012 5:35 am

Re: Simple little ruby code for getting epoch time

Postby MyCo » Mon Mar 18, 2013 8:15 pm

The unix time is just:
Time.now.to_i

There is no need to multiply that by 1000.

If you do need microseconds, you have to multiply by 1000, but then you have to take care, because FlowStones Integers are only 32bit, so you exceed the integer range.
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Simple little ruby code for getting epoch time

Postby Quentin » Mon Mar 18, 2013 8:20 pm

aha, I see... the value was too big for the int so I wasn't seeing it change- thanks so much for helping me on this one..
Quentin
Quentin
 
Posts: 37
Joined: Sat Jul 14, 2012 5:35 am

Re: Simple little ruby code for getting epoch time

Postby trogluddite » Mon Mar 18, 2013 8:35 pm

Hi Quentin,

It would be a good idea to change your variable name too - the name 'time' is already used by the FlowStone API as a method for getting at the primitive's own internal clock - so it would depend how the interpreter resolves the name conflict which value you would get.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK


Return to General

Who is online

Users browsing this forum: No registered users and 83 guests