Controlling Ifos from Mac OS X
More progress on my Mac development path migration: I can now control Ifos slaves from my iMac. This is the culmination of a few related successes, and means:
- The Mac sees and can use my USB-to-Serial cable
ruby-serialport
is installed and working- My tiny Modbus master in Ruby is working
- The Ifos slave still works (you never know with these “invention”-type thing-a-bobs)
Related, but not specifically required for basic Ifos control via Modbus/Ruby:
- javax.comm is installed and working
There were a few things I had to do:
1) Install ruby-serialport. This is a gem now (that’s cool), so installation was trivial. I had to update RubyGems first, though—the version installed by default was slightly too old:
peter@McMullen ~ $ sudo gem update --system
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.3.5
:0:Warning: Gem::SourceIndex#search support for String patterns is deprecated
Updating RubyGems to 1.3.5
Installing RubyGems 1.3.5
RubyGems 1.3.5 installed
=== 1.3.5 / 2009-07-21
Bug fixes:
* Fix use of prerelease gems.
* Gem.bin_path no longer escapes path with spaces. Bug #25935 and #26458.
Deprecation Notices:
* Bulk index update is no longer supported (the code currently remains, but not
the tests)
* Gem::manage_gems was removed in 1.3.3.
* Time::today was removed in 1.3.3.
------------------------------------------------------------------------------
RubyGems installed the following executables:
/usr/bin/gem18
RubyGems system software updated
peter@McMullen ~ $ sudo gem install ruby-serialport
Building native extensions. This could take a while...
Successfully installed ruby-serialport-0.7.0
1 gem installed
Installing ri documentation for ruby-serialport-0.7.0...
Installing RDoc documentation for ruby-serialport-0.7.0...
peter@McMullen ~ $
2) Include rubygems in modbus.rb. Not unexpected (and a small price to pay) now that we benefit from the new gem nature of serialport. Not much to the diff:
--- modbus.rb (revision 383)
+++ modbus.rb (working copy)
@@ -21,7 +21,8 @@
-Kernel::require "serialport"
+require 'rubygems'
+require 'serialport'
3) Open the serial port by name instead of number. On the PC, numbered COM ports correspond to the serial ports (COM1, COM2, etc.). OS X uses filesystem names, like other *nixes (e.g. /dev/tty.Modem
). My USB-to-Serial cable is accessible at /dev/tty.PL2303-0000201A
, so I that’s what I pass to my Modbus master. Here I create a Modbus master on the serial port at 19200 baud in ASCII mode, then write 1 to register 0 on device 3 (turn on LED 0 at lowest intensity red):
peter@McMullen ~/Documents/saphum/PIC/modbus $ irb -r modbus.rb
>> mb = Modbus.new "/dev/tty.PL2303-0000201A", false, 19200
=> #<Modbus:0x306d80 @sp=#<SerialPort:0x306d30>>
>> mb.writeRegister 3, 0, 1
=> [1]
Now that I know can control Ifos from the Mac, I can start on the more difficult task of controlling it from the TINI.