Interfacing Lakeshore 335 Temperature Controller with Debian Squeeze
How to connect a LakeShore 335 temperature controller via USB to Debian 6.0 (Squeeze) and access it with Python using the python-serial package. Ans some USB kernel magic.
Problem
The LakeShore temperature controller has an USB-to-Serial converter built-in. Connecting the controller with the USB port one gets the following message in dmesg:
dmesg output
[2409208.888037] usb 5-1: new full speed USB device using ohci_hcd and address 4
[2409209.057001] usb 5-1: New USB device found, idVendor=1fb9, idProduct=0300
[2409209.057004] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[2409209.057006] usb 5-1: Product: Model 335 Temperature Controller
[2409209.057007] usb 5-1: Manufacturer: Silicon Labs
[2409209.057008] usb 5-1: SerialNumber: 335A0NX
[2409209.057086] usb 5-1: configuration #1 chosen from 1 choice
[2410981.259615] hub 5-0:1.0: port 1 disabled by hub (EMI?), re-enabling...
[2410981.259620] usb 5-1: USB disconnect, address 4
[2410981.520032] usb 5-1: new full speed USB device using ohci_hcd and address 5
[2410981.688579] usb 5-1: New USB device found, idVendor=1fb9, idProduct=0300
[2410981.688582] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[2410981.688584] usb 5-1: Product: Model 335 Temperature Controller
[2410981.688585] usb 5-1: Manufacturer: Silicon Labs
[2410981.688586] usb 5-1: SerialNumber: 335A0NX
[2410981.688641] usb 5-1: configuration #1 chosen from 1 choice
[2410982.870602] hub 5-0:1.0: port 1 disabled by hub (EMI?), re-enabling...
[2410982.870606] usb 5-1: USB disconnect, address 5
[2410983.132033] usb 5-1: new full speed USB device using ohci_hcd and address 6
[2410983.300567] usb 5-1: New USB device found, idVendor=1fb9, idProduct=0300
[2410983.300570] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[2410983.300581] usb 5-1: Product: Model 335 Temperature Controller
[2410983.300582] usb 5-1: Manufacturer: Silicon Labs
[2410983.300583] usb 5-1: SerialNumber: 335A0NX
[2410983.300651] usb 5-1: configuration #1 chosen from 1 choice
Where is our /dev/ttyUSBn device? The problem is that the idVendor and idProduct IDs are not recognized by the device driver, thus it does not know that we want to load the driver module (cp210x) and obtain a serial port.
Since kernel 2.6.17(?) there is the possibility to add new IDs. This allows the correct driver to be loaded automatically.
First we need to load the driver:
load cp210 module
~# modprobe cp210x
this will give the kernel messages:
dmesg
[2420294.757750] usbcore: registered new interface driver cp210x
[2420294.757752] cp210x: v0.09:Silicon Labs CP210x RS232 serial adaptor driver
OK, the chip is recognized, still no sign of our serial usb device file.
In order to get our device file, we need to make this driver aware of our unknown idVendor and idProduct. It is not anymore necessary to modify the driver source code to add a new device:
~# echo 1fb9 0300 > /sys/bus/usb-serial/drivers/cp210x/new_id
This will finally create the missing serial USB device:
[2420375.056040] usb 5-1: reset full speed USB device using ohci_hcd and address 6
[2420375.218625] usb 5-1: cp210x converter now attached to ttyUSB0
In order to communicate we need to connect to this port with the proper baud rate etc. . Make sure your user is in the same group like the device file (dialout in Debian).
Here is a short example in how to interface with the temperature controller in Python:
import serial
s = serial.Serial("/dev/ttyUSB0", timeout=1, baudrate=57600, bytesize=7,parity="O")
s.write("*IDN?\r\n")
print s.readline()
'LSCI,MODEL335,335A0NX/#######,1.2\r\n'