contents
  1. [gainer][BSD] FreeBSDとGainer
    1. [gainer] Python
    2. [gainer] Perl
    3. [gainer] Ruby again
    4. [gainer] 構成変更
    5. [gainer] その他の情報
  2. [KOF2008] 木彫り

KOF2008準備の一日

  • 2008年09月21日(日)

[gainer][BSD] FreeBSDとGainer

[gainer] Python

Hossy’s Workshop: Gainerというのがあるようだ。

でも、Pythonで使っている様子。

まあ、試してみるか。

  • /etc/devd.conf
fuji% diff -u /etc/devd.conf.20080921 /etc/devd.conf
--- /etc/devd.conf.20080921     2008-09-21 12:01:23.000000000 +0900
+++ /etc/devd.conf      2008-09-21 12:02:11.000000000 +0900
@@ -303,3 +303,8 @@
        action                  "/etc/acpi_ac $notify";
 };
 */
+
+attach 10 {
+       device-name "ucom0";
+       action "chmod 666 /dev/ttyU0";
+};

PyGainer

  • comms/py-serial

おお、これは動いてるな。

fuji% python PyGainer.py /dev/ttyU0                 
Q*
Q*
RESET
?*
?1.0.0.15*
KONFIGURATION_1*
KONFIGURATION_1*
h*
h*
l*
l*

まだ、LEDしかつないでないので、出力だけ。

fuji% python
Python 2.5.2 (r252:60911, Sep 12 2008, 18:14:02)
[GCC 4.2.1 20070719  [FreeBSD]] on freebsd7
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyGainer import PyGainer
>>> g=PyGainer()
>>> g.open('/dev/ttyU0')
0
>>> g.reset()
Q*
Q*
True
>>> g.configuration(1)
KONFIGURATION_1*
KONFIGURATION_1*
True
>>> g.set_onboard_led(1)
h*
h*
True
>>> g.set_all_digital_output(1)
D0001*
D0001*
True
>>> g.set_all_digital_output(7)
D0007*
D0007*
True
>>> g.set_all_digital_output(15)
D000F*
D000F*
True

[gainer] Perl

Perl用Device::Gainerモジュールを書いてみた

  • devel/p5-Class-Accessor

うーん、どうもSerialProxy専用のコーディングだと思う。

[gainer] Ruby again

comms/ruby-serialportに変えたら、動いたっぽい。

fuji% diff -u gainer.rb.org gainer-serial.rb
--- gainer.rb.org       2008-09-20 18:13:34.000000000 +0900
+++ gainer-serial.rb    2008-09-21 16:07:33.000000000 +0900
@@ -1,5 +1,7 @@
 require 'gainer/port'
 
+require 'serialport'
+
 module Gainer
   class Basic
     AIN, DIN, AOUT, DOUT = 0, 1, 2, 3
@@ -126,11 +128,9 @@
     end
   end
 
-  require 'termios'
   class Serial < Basic
     def initialize(path, config = nil)
-      @file = File.open(path, 'w+')
-      @file.sync = true
+      @file = SerialPort.new(path, 38400)
       setup_port
 
       super(config)
@@ -139,10 +139,7 @@
     private
 
     def setup_port
-      setting = Termios::getattr(@file)
-      setting.ispeed = setting.ospeed = 38400
-      setting.cflag |= Termios::CS8
-      Termios::setattr(@file, Termios::TCSANOW, setting)
+      @file.baud=38400
     end
 
     def command_send(c)
@@ -181,14 +178,14 @@
   g = Gainer::Serial.new(ARGV.shift)
 
   done = false
-  g.on_press = proc do
+  g.on_pressed = proc do
     done = true
   end
 
   until done
     g.led = ! g.led
 
-    print 'press button to quit. led = ', (g.led ? 'on ' : 'off'), ".\r"
+    print 'press button to quit. led = ', (g.led ? 'on ' : 'off'), ".\n"
     sleep(0.5)
   end
   g.led = false

相変わらず、LED出力だけのテスト。

fuji% cat gainer-test.rb 
require 'gainer-serial'

g = Gainer::Serial.new(ARGV.shift)

done = false
g.on_pressed = proc do
  done = true
end

led=0
until done
  g.led = ! g.led
  g.digital_output=led
  
  print 'press button to quit. led = ', (g.led ? 'on ' : 'off'), ":#{led}.\n"
  sleep(0.5)
  led=(led+1)%16
end
g.led = false
g.digital_output=0

[gainer] 構成変更

CdSとタクトスイッチを増やして、入力できるようにしてみた。

一応、rubyとpythonで動作を確認した。

以下は、rubyの分。

fuji% ruby gainer-test.rb /dev/ttyU0
press button to quit. led = on :0,Input: 0000,E7DAE3E8.
press button to quit. led = off:1,Input: 0000,E6D9E2E7.
press button to quit. led = on :2,Input: 0000,E6DAE3E7.
press button to quit. led = off:3,Input: 0000,E6DBE4E9.
press button to quit. led = on :4,Input: 0000,E6DBE4E9.
press button to quit. led = off:5,Input: 0000,E6DBE4E9.
press button to quit. led = on :6,Input: 1000,E6DEE6EC.
press button to quit. led = off:7,Input: 1000,E6DDE6EA.
press button to quit. led = on :8,Input: 1000,E6DBE3E8.
press button to quit. led = off:9,Input: 1000,E6DAE2E8.
press button to quit. led = on :10,Input: 1000,E6DAE3E8.
press button to quit. led = off:11,Input: 1000,E6DBE3E8.
press button to quit. led = on :12,Input: 1000,E6DBE3E8.
press button to quit. led = off:13,Input: 1000,E6DBE3E7.
press button to quit. led = on :14,Input: 1000,CCD2DAD8.
press button to quit. led = off:15,Input: 1000,8F888A8A.
press button to quit. led = on :0,Input: 1000,A7959EA4.
press button to quit. led = off:1,Input: 0000,BE898FA0.
press button to quit. led = on :2,Input: 0000,E6D5E0E5.

いい感じだ。

[gainer] その他の情報

[KOF2008] 木彫り

開始。

とりあえず、体の内側を彫ってみた。

Last modified: 2009-01-30
Post-it: New Post-it (help)

Text color: [_][_][_][_]

Background: [_][_][_][_][_][_]

Draw Line:

x: y: