eisental/Rubyc — Issue #24: @tx.transmit n,1,8  - wrong number of arguments (3 for 2)
Author: mstram
Created: 2012-01-28 17:30:36+00:00
State: open

```ruby
require 'java'
import 'org.tal.rubychip.RubyCircuit'
import 'org.tal.redstonechips.wireless.Transmitter'

import 'org.tal.redstonechips.bitset.BitSetUtils'
import 'org.tal.redstonechips.bitset.BitSet7'

def init
....
@tx.init sender, args[0], 9, circuit

--------------------
def sendMsgByte

char = msg.txt[msg.indx]
n = char.ord
@tx.transmit n,1,8

```

-------------------------------- rest of script -------------------------------

```ruby
#
# wlspr8c.rb
#
# send message(s) to a wireless sign (print chip)
#

require 'java'
import 'org.tal.rubychip.RubyCircuit'
import 'org.tal.redstonechips.wireless.Transmitter'

import 'org.tal.redstonechips.bitset.BitSetUtils'
import 'org.tal.redstonechips.bitset.BitSet7'
# local irb syntax check
#

#class RubyCircuit
# def initialize
# puts "dummy RubyCircuit (initialize)"
#print "args[0] = #{args[0]}"
# end
#end

class Msg
attr_reader :txt, :msgType, :len
attr_accessor :indx
def initialize(txt,msgType)
@txt = txt
@msgType = msgType
@indx = 0
@len = @txt.length
end
end
##########################################

class Wlspr8c < RubyCircuit
CLOCKPIN = 0
CLEARPIN = 1
TESTPIN = 2
MSGREQPINS = 5

def init
# info "(mike01) Transmitter test. arg 1: channel name[:start-bit]"
info "args.length = '#{args.length}'"
# print "args[0] = #{args[0]}"
#if args.length >
if args.length == 1
@tx = Transmitter.new()
# @tx.init sender, args[0], 1, circuit

# should be 8 for replace, 9 for add and 10 for scroll
@tx.init sender, args[0], 9, circuit
info "@tx = #{@tx}"

@msgs = []
@currentMsg = 0
@msgReq = 0

@testMsg = ''
@testing = false

@clrSign = false

setupMsgs
@numOfMsgs = @msgs.size

true
elsif args.length == 2
debug "(debug) args[1] = '#{args[1]}'"
info "(info) args[1] = '#{args[1]}'"

if args[1] == 'replace'
debug '(debug) replace mode'
info '(info) replace mode'
elsif args[1] = 'add'
debug '(debug) add mode'
info '(info) add mode'
elsif args[1] = 'scroll'
debug '(debug) scroll mode'
info '(info) scroll mode'
end
true
else
info "(info)Wireless print : arg 1: channel name [replace | add | scroll]"
debug "(debug)Wireless print : arg 1: channel name [replace | add | scroll]"
false
end

#true

end
#########################
def setupMsgs
@clrMsg = Msg.new(" ",-1)

@testMsg = Msg.new(" TEST : Abcdefg hijklmnop qrstuv wxyz 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ ",99)

@msgs << Msg.new("(m0) This sign is receiving wireless data from a rubyc wireless chip ",1)

@msgs << Msg.new(" Message #1 is here ",0)
@msgs << Msg.new(" Message #2 is here ",0)
@msgs << Msg.new(" Message #3 is here ",0)
@msgs << Msg.new(" Message #4 is here ",0)
@msgs << Msg.new(" Message #5 is here ",0)
@msgs << Msg.new(" Message #6 is here ",0)
@msgs << Msg.new(" Message #7 is here ",0)

end

#class Msg
# attr_reader :txt,msgType,len
# attr_accessor :indx
# def initialize(txt,msgType)
# @txt = txt
# @msgType = type
# @indx = 0
# @len = @txt.length
# end
# end

#in replace mode
#in add mode bit 0 is clear bits 1-9 are the char
#in scroll mode bit 0 is clear, bit 1 is scroll and bits 2-10 are the char

def sendMsgByte
if @testing
msg = @testMsg
elsif @clrSign
msg = @clrMsg
# @clrSign = false
else
msg = @msgs[@currentMsg]
end

if msg.indx < msg.len
char = msg.txt[msg.indx]

# debug "============= sendMsgByte ==============="
# debug "sending: char = '#{char.chr}' '#{char.ord}'"
# debug "========================================="

# n = char.ord * 2 # shift msg left 1 bit bit 0= clear bit
# @tx.transmit BitSetUtils.intToBitSet(n,9), 9
n = char.ord
begin
@tx.transmit n,1,8
# @tx.transmit n,8
# @tx.transmit 65,1,8
rescue Exception
debug "(sendMsgByte) @tx.transmit n,1,8 n = #{n} : #{$!}"
end

# replace mode
#@tx.transmit BitSetUtils.intToBitSet(char.ord,8), 8
# begin
msg.indx +=1
# rescue Exception
# STDERR.puts "(sendMsgByte) error #{$!}"
# debug "error = #{$!}"
# debug "(sendMsgByte) @msgs[@currentMsg].indx = " + @msgs[@msgnum].indx.to_s
# debug "(sendMsgByte) @currentMsg = " + @currentMsg.to_s
# end
else # reset to beginning of msg loop forever
msg.indx = 0
#@msgs[@currentMsg].indx = 0
end
#@haveMsg = false
end

# protected void send(int idx, boolean state)
# protected void send(int startIdx, int length, int val)

def input(idx, state)
# when getting clock
# debug "(input) idx = " + idx.to_s + " state: " + state.to_s

#TESTPIN = 2
#CLEARPIN = 1
#CLOCKPIN = 0

if idx == CLOCKPIN
if state
sendMsgByte
end

elsif idx == CLEARPIN
debug "CLEARPIN "
@clrSign = true
sendMsgByte

elsif idx==TESTPIN
if state
debug "Test pin:on - msg set to testMsg"
@testing = true
else
@testing = false
# debug "Test pin:off - msg set to rubyMsg"
# #@msg = @rubyMsg
end
elsif idx<=MSGREQPINS
@msgReq = bits_to_i(3, 3, inputs)
debug "@msgReq = " + @msgReq.to_s
if @msgReq < @numOfMsgs

@currentMsg = @msgReq
debug "OK @currentMsg set to @msgReq (" + @msgReq.to_s + ")"
else
debug "ERR @msgReq is out of range (" + @msgReq.to_s + ")"
end
# @tx.transmit BitSetUtils.intToBitSet(@testMsg.ord,8), 8
end
# else
#
end

# ---- Wlspr4

end

Wlspr8c.new()
```