Browse Source

Check connection before writing to serial

Matt Sparks 13 years ago
parent
commit
9589cb72f2
1 changed files with 3 additions and 2 deletions
  1. 3 2
      alphasign/interfaces/local.py

+ 3 - 2
alphasign/interfaces/local.py

@@ -16,6 +16,7 @@ class Serial(base.BaseInterface):
     """
     self.device = device
     self.debug = True
+    self._conn = None
 
   def connect(self):
     """Establish connection to the device.
@@ -42,8 +43,8 @@ class Serial(base.BaseInterface):
     :param packet: packet to write
     :type packet: :class:`alphasign.packet.Packet`
     """
-    if not self._conn:
-      return
+    if not self._conn or not self._conn.isOpen():
+      self.connect()
     if self.debug:
       print "Writing packet: %s" % repr(packet)
     try: