On 3 Oct 2010, at 03:40, Rob Gleeson wrote:
On 3 Oct 2010, at 03:36, Shaun August wrote:
Hi There,
I am trying to run a ruby TCPsocket to get information from a quatech serial device server. The code runs well in ruby but I get an error when I try to reference the class in my MacRuby code:
uninitialized constant Coin_Counter::TCPsocket (NameError)
Here is the class where the error takes place:
class Coin_Counter def open_socket(host) port=(5000)
@s = TCPsocket.open(host, port) puts "Opened Connection to", host,"\n" end
def close_socket() @s.close end
def poll_microcoin() hexBool = true byteNum = 0 coins = true loonie = 0 hex = "\x82\x88\x90\xff\x90\x00\x03\x77" hex1 = "\x82\x88\x11\xff\x90\x00\x03\xf6"
while coins eof = false if hexBool @s.write(hex) hexBool = false else @s.write(hex1) hexBool = true end
while eof == false results = @s.read(1) if byteNum == 5 if results == "\030" AppController.startImageCapture elsif results == "\220" loonie = loonie + 1 if loonie > 1 AppController.startImageCapture loonie = 0 end end end if results == "\003" p "end of bytes" eof = true byteNum = byteNum + 1 end byteNum = byteNum + 1 end check = @s.read(1) byteNum = 0 sleep(0.5) end end end
I really need to use raw TCP sockets to communicate with my device. I am hoping I don't have to re-impliment this code.
Thanks for your help,
Shaun _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
It looks like you haven't required any file that defines TCPSocket. Try: require('socket')
Rob _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Oh, just spotted a typo as well. it's TCPSocket and not TCPsocket. Rob