Tag Archives | monitoring

FFI Ruby Bindings for Phidget Library

While working with completely virtualized systems and architectures is fun, for me it’s never been quite as much fun as doing things in the Real World™. A few years ago I found Phidgets Inc. Phidgets are a set of “plug and play” building blocks for low cost USB sensing and control from your PC. From their website:

All the USB complexity is taken care of by our robust API. Applications can be developed quickly by programmers using their favorite language: C/C++, C#, Cocoa, Delphi, Flash AS3, Flex AS3, Java, LabVIEW, MATLAB, Max/MSP, MRS, Python, REALBasic, Visual Basic.NET, Visual Basic 6.0, Visual Basic for Applications, Visual Basic Script, and Visual C/C++/Borland.NET.

Unfortunately, there is one language that is absent from this list: Ruby.

Several years ago, there was an effort started by Craig DeHaan and later picked up by Kit Plummer which worked pretty well but the callbacks seemed a little fragile and I wanted the interface to be a little more idiomatically Ruby. Also, using FFI means it works on multiple Ruby VMs without issue, MRI, JRuby, etc. Like the previous libraries, there aren’t many devices supported yet but that’s just a matter of having them. There are traditional and idiomatic examples in the repository and it can be installed with everybody’s favorite command: gem install phidgets-ffi.

The source and additional documentation can be found at https://github.com/kreynolds/phidgets-ffi. Enjoy :)

Bookmark and Share
Read full story · Comments { 0 }

Modbus/RTU via TCP Serial Gateway with Ruby

We recently had a need to connect to a PowerLogic BCM42 through a Barionet-50 from Barix. While the Barionet-50 speaks Modbus/TCP for itself, it does not perform as a TCP/RTU gateway for devices hooked up to it via the RS485 port which is a straight serial gateway. Our project is being implemented in ruby so we started with the excellent RModbus gem and modified it to send Modbus/RTU commands via TCP and it works perfectly. This solution is also significantly cheaper than buying an off-the-shelf Modbus TCP/RTU gateway as those tend to *start* at about $400 and rapidly get more expensive.

 

require 'rubygems'
require 'rmodbus'
ModBus::RTUViaTCPClient.connect('10.10.100.33', '10002', 4) do |cl|
        total_ma = cl.read_holding_registers(0, 42).inject(0) { |acc, i| acc += i; acc}
        puts "Total mA: #{total_ma}"
end
$ ./test.rb
Total mA: 12510

Our code for accessing Modbus/RTU devices via TCP can be found at http://github.com/kreynolds/RModBus

Bookmark and Share
Read full story · Comments { 1 }