If you happen to own a Globalsat GH-615M GPS Sports watch and want to connect to it using the serial interface and ruby, you might want to look at two things:

Here's a short sample of how to do it in ruby (more op-codes are in the "gh615"; python app)

#require the ruby-serialport library

#fixes a crash when doing a "require rubygems"
#use instead of require "serialport"
Kernel::require "serialport"


#connecting to the usb adapter and returning the port object
def connect
  port = SerialPort.new("/dev/tty.usbserial")
  # configure the serial port
  port.baud = 57600
  port.read_timeout = 2
  return port
end


#will return model information
def whoami(port)
  #a curtesy sleep
  sleep 2
  ##########SENDING
  #the code will be converted to decimal and then to the matching character
  #each of the resulting characters will be put into the serial connection
  '020001BFBE'.scan(/../).each{|tuple|
    port.putc tuple.hex.chr
  }
  #a curtesy sleep
  sleep 2 

  ##########RECEIVING
  answer=""

  #getting integers until "nil" is returned...
  #integers are converted to their matching ASCII characters and returned as a string
  while (1)
    character = port.getc
    if character.nil?
      break
    else 
      answer+=character.chr
    end
  end
  #removing the header
  if answer[3..9].nil?
    return "No Answer"
  else
    return answer[3..9]
  end
end



puts "Connecting"
myport = connect()
puts "Asking for model-information:"
puts "Answer: " + whoami(myport)
myport.close
sleep 2

Comments