Use SO_REUSEADDR.
authorBernard Blackham <[email protected]>
Sun, 27 Jun 2004 11:58:59 +0000 (11:58 +0000)
committerBernard Blackham <[email protected]>
Sun, 27 Jun 2004 11:58:59 +0000 (11:58 +0000)
Do keypresses.
Fix display

virtualvend/vvend.py

index 3f38cb5..f4d04cb 100644 (file)
@@ -81,13 +81,22 @@ class appgui:
 
 
     return
-  
+
+    def __del__(self):
+       try:
+           self.sock.close()
+           self.sock.shutdown()
+       except:
+           pass
+
 #####CALLBACKS
   def keypad_clicked(self,widget):
-    print "button clicked"
-    print widget.get_label()
-    self.do_send(widget.get_label())
-    sys.stdout.write("\a")
+    key = widget.get_label()
+    if key == 'RESET':
+       key = '11'
+    else:
+       key = '0'+key
+    self.do_send('2'+key+' keypress\n')
 
   def handleNewConnection(self,source,condition):
     #source is a socket in GTK v 1 and a fd in version 2
@@ -119,6 +128,7 @@ class appgui:
      port = 5150
 
      self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+     self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
      self.sock.bind(('localhost', port))
      self.sock.listen(0)
      print "listening on ", port
@@ -235,21 +245,22 @@ Mark Tearle, June 2004
 
   def do_vend_all(self):
      for i in range(11,99):
-       self.do_send("101 Vending ",i)
-       self.do_send("153 Home sensors failing")
-     self.do_send("102 Vend all motors complete")
+       self.do_send("101 Vending "+i+"\n")
+       self.do_send("153 Home sensors failing\n")
+     self.do_send("102 Vend all motors complete\n")
   
   def do_vend(self,command):
      fail = None
      if fail:
-       self.do_send("153 Home sensors failing")
+       self.do_send("153 Home sensors failing\n")
      else:
         self.insert("Vending ",command)
-       self.do_send("100 Vend successful")
+       self.do_send("100 Vend successful\n")
     
   def do_display(self,string):
      display = self.wTree.get_widget("label1")
      display.set_text("%10.10s" % (string))
+     self.do_send('300 Written\n')
 
   def do_beep(self,command):
      sys.stdout.write("\a")
@@ -258,7 +269,7 @@ Mark Tearle, June 2004
      pass
 
   def do_switches(self):
-     pass
+     self.do_send("600 3F 3F\n")
 
   def do_pong(self):
      self.do_send("000 PONG!\n")

UCC git Repository :: git.ucc.asn.au