Playing with Ruby

I need to add support a new interface panel to the my Plutohome installation. To do it I use Generic Serial Device (GSD) which works perfect. GSD has embedded Ruby interpretator to provide a tool for implementing desire device logic. In my case, I receive a hexdecimal binary string which contains a device ID, device port, command and data. All of them should be converted in integer exept data. The data should be converted in float. I found this solution how to convert hex string to float on Ruby forum:
irb(main):001:0> s='0x44361000'
=> "0x44361000"

irb(main):002:0> f=[s.to_i(16)].pack('L').unpack('F')[0]
=> 728.25

I like Ruby. It’s the similar to Perl but, of course, with some specificity.

Published by

Michael Stepanov

Site owner and admin :)

Leave a Reply

Your email address will not be published. Required fields are marked *