Sha256: ada89354597c0f736a946f99c6395636512d9cf5c7c83c5a5e0b7bcb0f14858e

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'rubygems'
require 'bundler/setup'

$LOAD_PATH.unshift(File.expand_path('lib', File.dirname(__FILE__)))

require 'ftdi'

DMX_BREAK = 110. / 1000   # Break 88 uS or more
DMX_MAB   = 160. / 1000   # Mark After Break 8 uS or more
BAUD_RATE = 250000

ctx = Ftdi::Context.new

def dmx_break(ctx)
  ctx.set_line_property2(:bits_8, :stop_bit_2, :none, :break_on)
  sleep DMX_BREAK
  ctx.set_line_property2(:bits_8, :stop_bit_2, :none, :break_off)
  sleep DMX_MAB
end

def dmx_write(ctx, bytes)
  dmx_break(ctx)
  ctx.write_data(bytes)
end

begin
  ctx.usb_open(0x0403, 0x6001)
  begin
    ctx.baudrate = BAUD_RATE
    ctx.set_line_property(:bits_8, :stop_bit_2, :none)
    ctx.flowctrl = Ftdi::SIO_DISABLE_FLOW_CTRL

    arr = [ 0 ]
    512.times { arr << 1 }
    dmx_write(ctx, arr)

    sleep 1

    arr = [ 0 ]
    512.times { arr << 0 }
    dmx_write(ctx, arr)

    puts "Context is:"
    ctx.members.each { |k| puts "#{k} = #{ctx[k]}" }

  ensure
    ctx.usb_close
  end
rescue Ftdi::Error => e
  $stderr.puts e.to_s
end

ctx.dispose

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
libftdi-ruby-0.0.2 test.rb
libftdi-ruby-0.0.1 test.rb