To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 13119
13118  |  13120
Subject: 
Re: CyberMaster online
Newsgroups: 
lugnet.robotics
Date: 
Fri, 10 Nov 2000 07:29:36 GMT
Viewed: 
1766 times
  
Ok, here's the full code up to now. I'm afraid there are no comments yet and
please bear in mind that it has been programmed on a Linux machine. If you want
to use it, change the pointer to your python interpreter and the name of your
serial port (in init).
The functions get_opcode en write_opcode are used to remember what the last
opcode was, so that it's equivalent can be used (RCX remembers last opcode and
refuses to carry it out when retransmitted).
Upload_datalog is still a work in progress....


#!/usr/local/bin/python

import os, FCNTL, fcntl, TERMIOS, termios, sys, string

class rcx_brick :

def get_opcode(self) :
  opcode = ''
  try :
   fd = open('opcode', 'r')
   opcode = fd.read()
   fd.close()
  except IOError :
   print 'No previous opcode available.'
  return opcode

def write_opcode(self, opcode) :
  try :
   fd = open('opcode', 'w')
   fd.write(opcode)
   fd.close()
  except IOError :
   print 'Problem writing opcode.'

def send_alive(self) :
  o = self.get_opcode()
  if o == '0x10' :
   self.send_bytes(0x18, None)
  else :
   self.send_bytes(0x10, None)

def power_off(self) :
  o = self.get_opcode()
  if o == '0x60' :
   self.send_bytes(0x68, None)
  else :
   self.send_bytes(0x60, None)

def get_battery(self) :
  o = self.get_opcode()
  if o == '0x30' :
   rcv = self.send_bytes(0x38, None)
  else :
   rcv = self.send_bytes(0x30, None)
  low = hex(ord(rcv[14]))
  high = hex(ord(rcv[12]))
  lvl = '0x' + low[2:4] + high[2:4]
  print "Battery level : " + str(string.atoi(str(lvl), 0)) + " MilliVolts"

def set_program(self, prg_nr) :
  o = self.get_opcode()
  if o == '0x91' :
   self.send_bytes(0x99, prg_nr)
  else :
   self.send_bytes(0x91, prg_nr)

def send_message(self, msg) :
  self.send_bytes(0xf7, msg)

def clear_message(self) :
  self.send_bytes(0x90, None)

def play_sound(self, snd) :
  o = self.get_opcode()
  if o == '0x51' :
   self.send_bytes(0x59, snd)
  else :
   self.send_bytes(0x51, snd)

def upload_datalog(self, bnds) :
  o = self.get_opcode()
  if o == '0xa4' :
   rcv = self.send_bytes(0xac, bnds)
  else :
   rcv = self.send_bytes(0xa4, bnds)
  for x in rcv :
   print hex(ord(x))

def set_display(self, dsply) :
  o = self.get_opcode()
  if o == '0x33' :
   self.send_bytes(0x3b, dsply)
  else :
   self.send_bytes(0x33, dsply)

def rcx_init(self) :
  portName = '/dev/ttyS1'
  try :
   fd = os.open(portName, FCNTL. O_RDWR)
  except os.error :
   print "Can't open " + portName
   sys.exit()
  """sts = termios.tcgetattr(fd)
  sts[0] = 0
  sts[1] = 4
  sts[2] = 4027
  sts[3] = 4080
  sts[4] = TERMIOS.B2400
  sts[5] = TERMIOS.B2400
  try:
   termios.tcsetattr(fd, TERMIOS.TCSANOW, sts)
  except IOError :
   print 'Could not set attributes.'
   sys.exit()"""
  return fd

def send_bytes(self, opcode, params) :
  self.write_opcode(hex(opcode))
  sum = (opcode & 0xff)
  fd = self.rcx_init()
  os.write(fd, chr(0x55))
  os.write(fd,chr(0xff))
  os.write(fd, chr(0x00))
  os.write(fd, chr(opcode))
   os.write(fd, chr(~opcode & 0xff))
  if params != None :
   for y in params :
       sum = sum + (y & 0xff)
    os.write(fd, chr(y))
    os.write(fd, chr(~y & 0xff))
  os.write(fd, chr(sum))
  os.write(fd, chr(~sum & 0xff))
  rcv = os.read(fd, 150)
  rcv2 = os.read(fd, 150)
  #rcv3 = os.read(fd, 50)
  os.close(fd)
  return rcv + rcv2 #+ rcv3

x = rcx_brick()
#params = [1,0,3,0]
#params = [7]
#x.set_display(params)
#x.send_message(params)
#x.clear_message()
#x.set_program(params)
#x.upload_datalog(params)
#x.power_off()
#x.play_sound(params)
#x.send_alive()
x.get_battery()

Harald Maehrer wrote:

> Why not post your python code to this ng.
> 
> I'm in a heavy learning process on python right now and i thought of
> doing something similar.
> 
> It would mean a great help for me.
> 
> Thx Harry
> 
> On Wed, 8 Nov 2000 08:37:25 GMT, Philippe Possemiers
> <philippe.possemiers@the-ecorp.com> wrote:
> 
> > I've made a module in python which does essentially the same as send.c and
> > which can easily be extended with more functionality. At this moment, the
> > main functionality which is lacking is the upload of programs.
> > If you're interested, I can mail it to you and you could use that to connect
> > to your website instead of Perl.
> > 
> > Stefan Seiz wrote:
> > 
> > > I made an attempt to put a CyberMaster online on my WebTruck site
> > > 
> > > Using Perl on Win98 was harder than expected, I still am not able to read
> > > from the CyberMaster.
> > > I used RCXCC and NQC to write a small proggy
> > > for the cybermaster, and control it using a Perl Web Server.
> > > 
> > > The only software that connects successfully to the cybermaster is
> > > send.c from Kekoa Proudfoot, and that does not work on cygwin.
> > > So if you know a way to communicate with the CyberMaster in Perl,
> > > please contact me.
> > > 
> > > Try to drive the Cybermaster here:
> > > http://www.webtruck.org/cm/
> > > 
> > > Any suggestions for improvement welcome :-)
> > > 
> > > Regards
> > >   Stefan Seiz
> > 



Message is in Reply To:
  Re: CyberMaster online
 
Why not post your python code to this ng. I'm in a heavy learning process on python right now and i thought of doing something similar. It would mean a great help for me. Thx Harry (...) (26 years ago, 8-Nov-00, to lugnet.robotics)

4 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR