I would like to use a Raspberry Pi4 to control a syringe pump [(see datasheet here and in particular the quick start manual on page1)][1]
The connector cables I used are RJ11 from the Pump to RS232 (from the manufacturer) as well as a standard RS232 to USB converter cable from Benfei ([drivers can be downloaded here][2])
On Windows it worked fine after installing the drivers (was needed). The COM port was recognized and I could test the pump with Arduino.
On my Raspberry I am not getting it to work.
I am this far: The RS232 adapter is recognized:
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port / Mobile Action MA-8910P Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
> pi@raspberrypi:~ $ dmesg | grep "tty" [ 960.932258] usb 1-1.3: pl2303
> converter now attached to ttyUSB0
When using this bare minimum code example:
import time
import serial
Serial = serial.Serial("/dev/ttyUSB0", baudrate = 19200, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1)
#Rate Units
#mL/hr - MH
#µL/hr - UH
#mL/min - MM
#µL/min - UM
def test_syringe(diameter = 10.00, pumping_rate = 10.00, pumping_rate_unit = 'MH', volume_to_dispense = 20.00):
Serial.write(("DIA " + str(diameter) + "\n").encode())
message = Serial.read()
print(message.decode())
Serial.write("DIA \r".encode())
message = Serial.read()
print(message.decode())
Serial.write("RAT ".encode() + str(pumping_rate).encode() + " ".encode() + pumping_rate_unit.encode())
Serial.write("VOL ".encode() + str(volume_to_dispense).encode())
Serial.write("DIR INF".encode())
Serial.write("RUN \n".encode())
test_syringe()
I get at least some feedback from the pump:
b'\x02'
0
But it is not starting. The linux driver is only available for Redhat. I'm thinking about purchasing another RS232 adapter cable.
Is the code with the carrier return corect? [1]: https://www.syringepump.com/download/NE-500%20OEM%20Syringe%20Pump%20User%20Manual%20V3.9.pdf [2]: https://www.think-benfei.com/p_driver.html
b"like this"without encoding/formatting, and reproduce exactly what the Arduino did. \$\endgroup\$Serial.read()tries to read. In general you need to know how many bytes you want to read, or read one at a time until you get some kind of ending byte \$\endgroup\$Serial.read_until(ETX)where ETX = 0x03 might be helpful to read an entire reply. \$\endgroup\$