title: Serial Commands for BrainTree Scientific, Inc. Syringe Pump (model bs-8000) rs232
body: <p><strong>UPDATE:</strong> After ensuring my commands, serial config, and terminator ('\r') were correct I got this working on 1 of 5 computers. This leads me to believe it is an adapter issue. I plan on calling the company to see about ordering a USB/RJ11 adapter (I had been using a Keyspan USB->DB9->RJ11 adapter on my mac)</p>
  
  <hr>
  
  <p>I've read <a href="https://stackoverflow.com/questions/27183874/not-receiving-reply-from-syringe-pump-via-rs232-using-mscomm1-input">this</a> but I am still unable to communicate with this pump. This is the python script I modified (<a href="http://www.varesano.net/blog/fabio/serial%20rs232%20connections%20python" rel="nofollow noreferrer">source</a>),</p>
  
  <pre><code>import time
  import serial
  
  # configure the serial connections (the parameters differs on the device you are connecting to)
  ser = serial.Serial(
    port='/dev/tty.USA19H142P1.1', # /dev/tty.KeySerial1 ?
    baudrate=19200,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS
  )
  
  
  if not ser.isOpen():
    ser.open()
  
  print ser
  commands = ['dia26.59', 'phn01', 'funrat', 'rat15mm', 'vol0.7', 'dirinf',
              'phn02', 'funrat', 'rat7.5mm', 'vol.5', 'dirinf', 'phn03',
              'funrat', 'rat15mm', 'vol0.7', 'dirwdr', 'phn04', 'funstp',
              'dia26.59', 'phn01', 'funrat', 'rat15mm', 'vol1.0', 'dirinf',
              'phn02', 'funrat', 'rat7.5mm', 'vol.5', 'dirinf', 'phn03',
              'funrat', 'rat15mm', 'vol1.0', 'dirwdr', 'phn04', 'funstp']
  
  for cmd in commands:
    print cmd
    ser.write(cmd + '\r')
    time.sleep(1)
    out = ''
    while ser.inWaiting() &gt; 0:
      out += ser.read(1)
    if out != '':
      print '&gt;&gt;' + out
  </code></pre>
  
  <p>tty ports:</p>
  
  <pre><code>$ ls -lt /dev/tty* | head
  crw--w----  1 nathann  tty     16,   0 Oct 13 14:13 /dev/ttys000
  crw-rw-rw-  1 root     wheel   31,   6 Oct 13 14:12 /dev/tty.KeySerial1
  crw-rw-rw-  1 root     wheel   31,   8 Oct 13 13:52 /dev/tty.USA19H142P1.1
  crw-rw-rw-  1 root     wheel    2,   0 Oct 13 10:00 /dev/tty
  crw-rw-rw-  1 root     wheel   31,   4 Oct 12 11:34 /dev/tty.Bluetooth-Incoming-Port
  crw-rw-rw-  1 root     wheel    4,   0 Oct 12 11:34 /dev/ttyp0
  crw-rw-rw-  1 root     wheel    4,   1 Oct 12 11:34 /dev/ttyp1
  crw-rw-rw-  1 root     wheel    4,   2 Oct 12 11:34 /dev/ttyp2
  crw-rw-rw-  1 root     wheel    4,   3 Oct 12 11:34 /dev/ttyp3
  crw-rw-rw-  1 root     wheel    4,   4 Oct 12 11:34 /dev/ttyp4
  </code></pre>
  
  <p>I'm not even sure if it is sending the commands. Not getting any errors or feedback. Nothing is happening on the pump and nothing is getting returned (<code>out</code> string is always empty)</p>
  
  <p>This is my output:</p>
  
  <pre><code>(sweetcrave)nathann@glitch sweetcrave (master) $ python pumptest.py
  Serial&lt;id=0x1093af290, open=True&gt;(port='/dev/tty.USA19H142P1.1', baudrate=19200, bytesize=7, parity='O', stopbits=2, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
  dia26.59
  &gt;&gt;
  phn01
  funrat
  rat15mm
  vol0.7
  ^CTraceback (most recent call last):
    File "pumptest.py", line 28, in &lt;module&gt;
      time.sleep(1)
  KeyboardInterrupt
  </code></pre>
  
  <p>My ultimate goal:</p>
  
  <ul>
  <li>set up pumps parameters</li>
  <li>there are three phases that are specified:</li>
  <li>phase 1: push liquid to end of tube</li>
  <li>phase 2: dispense liquid in specific rate and volume</li>
  <li>phase 3: pull liquid back up</li>
  <li>the liquid is pulled back up (phase 3) so that it won't drip from the manifold, and so the subject can't suck it out. As such, phase 1 is needed to push the</li>
  <li>liquid back to the outflow point.</li>
  <li>volume and dispense rate can be changed. Use the following formula:</li>
  <li>rate= volume/sec * 60</li>
  <li>example: .5/4 x 60 (deliver .5 ml over a 4 sec duration)=7.5</li>
  </ul>