Index: powerbar/serial-npm4000.py
===================================================================
--- powerbar/serial-npm4000.py	(revision 157)
+++ powerbar/serial-npm4000.py	(revision 158)
@@ -18,9 +18,8 @@
 # Set to true to enable verbose communication aka debugging
 DEBUG = False
-DEBUG = True
 
 # Default for options
 opt_serial_port = '/dev/ttyUSB0'
-opt_password = 0x1245678
+opt_password = 0x12345678
 opt_address_code = 0xFFFF
 opt_baudrate = 19200
@@ -98,10 +97,10 @@
     """ Send raw command to serial device and wait for response """
 
-    print "Going to send: " + hex_to_str(raw_command)
+    debug("Going to send: " + hex_to_str(raw_command))
     send_line = "".join([chr(item) for item in raw_command])
     ser.write(send_line)
     recv_line = ser.read(response_size)
     recv_command = str_to_hex(recv_line)
-    print "Received: %s (%i)" % (hex_to_str(recv_command), len(recv_line))
+    debug("Received: %s (%i)" % (hex_to_str(recv_command), len(recv_line)))
     return(recv_command)
 
@@ -169,10 +168,15 @@
   return [int(hex(number)[2:].zfill(length)[x:x+2],16) for x in range(0,length,2)]
 
-
-
-def send_command(action, argument=None):
+#print hex_to_str(num_to_hex(opt_password))
+#exit(0)
+
+
+
+def send_command(action, argument=[]):
   """ Send CRC computed command to serial device and wait for response """
   (command, response_size, timeout) = line[action]
-  command = command[0:2] + num_to_hex(opt_address_code) + num_to_hex(argument)
+  if not isinstance(argument, list):
+    argument = num_to_hex(argument)
+  command = command[0:2] + num_to_hex(opt_address_code) + argument
   serial.timeout = timeout
   raw_command = command + [make_checksum(command)]
@@ -191,15 +195,20 @@
 def action_port_on(port):
   """ Enable port on device """
+  global ports_status
+  ports_status = None
+
   action_login()
-  port_status_synced = False
-  return send_command('port_on', port)
+  return send_command('port_on', port_to_hex(port))
 
 def action_port_off(port):
   """ Disable port on device """
+  global ports_status
+  ports_status = None
+
   action_login()
-  port_status_synced = False
-  return send_command('port_off', port)
+  return send_command('port_off', port_to_hex(port))
 
 def get_ports_status():
+   global ports_status
    # Example port 1 is off
    # d1 28 ff ff fe ff ff
@@ -222,5 +231,4 @@
    # Update global state
    ports_status = port_array
-   port_status_synced = True 
    return port_array
 
@@ -228,5 +236,7 @@
 def get_port_status(port):
    """ Get specific port status """
-   if port_status_synced:
+   global ports_status
+
+   if ports_status:
      return ports_status[port]
    else:
@@ -254,5 +264,12 @@
     doCommand('knownError')
 
-
+def bool_to_str(boolean, raw=False):
+   if not raw:
+      return str(boolean)
+   elif boolean:
+      return "1"
+   else:
+      return "0"
+     
 
 def usage(msg="",exitcode=None):
@@ -264,4 +281,5 @@
   [-h|--help]                   Reading right know
   [-d|--debug]                  Print extra communication output
+  [-r|--raw]                    Status(es) is bits like output
   --serialport=                 Serial Port to connect to [%s]
   --password=                   Password to use in hex notation [%s]
@@ -288,8 +306,10 @@
 
 def main():
-    global ser, opt_serial_port, opt_password, opt_address_code, opt_baudrate
+    global DEBUG, ser, opt_serial_port, opt_password, opt_address_code, opt_baudrate
     try:
         opts, args = getopt.getopt(sys.argv[1:], 
-            "df:s:t:o:v", ["debug","verbose", "serialport=", "password=", "addresscode=","toggle=","off=", "on=", "status=", "buadrate="])
+            "df:s:t:ro:v", 
+             ["debug", "verbose", "serialport=", "password=", 
+             "addresscode=","toggle=","off=", "on=", "status=", "buadrate=", "raw="])
     except getopt.GetoptError, err:
         usage(str(err),2)
@@ -297,4 +317,5 @@
     opt_port = None
     opt_action = None
+    opt_raw = False
     for o, a in opts:
         debug("%s : %s" % (o, a))
@@ -320,4 +341,6 @@
             opt_action = "off"
             opt_port = a
+        elif o in ["-r","--raw"]:
+            opt_raw = True
         elif o in ["-o","--on"]:
             opt_action = "on"
@@ -352,5 +375,5 @@
     for port in ports:
       if opt_action == "status":
-        get_port_status(port)
+        print bool_to_str(get_port_status(port),opt_raw),
       elif opt_action == "toggle":
         if get_port_status(port):
