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
4 posts
• Page 1 of 1
Simple little ruby code for getting epoch time
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
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
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.
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.
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
Re: Simple little ruby code for getting epoch time
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
- Quentin
- Posts: 37
- Joined: Sat Jul 14, 2012 5:35 am
Re: Simple little ruby code for getting epoch time
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.
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!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 75 guests