This post will show you how to read data into Origin from a serial port, using the pySerial Python module. A dialog allows user to set the time interval and number of data points to be recorded. The data is then imported into an Origin worksheet.
Hardware used in this example:
- HP 34401A Multimeter.
- RS232 cable (to connect the COM port of the computer to the multimeter).
Installation of pySerial module:
pySerial is not included in the embedded Python environment in Origin. The first step therefore is to download and install pySerail “outside” and then add the file path to Origin’s Python environment. The following instruction shows how to do it step by step, This instruction applies for either Python2.7 or Python3.3 , I am using Python 3.3 for example here:
- Download and install Python3.3 from the website: https://www.python.org/
- Download and install pySerial module from the website: https://pypi.python.org/pypi/pyserial . The easiest way might be just download the .exe file (make sure it’s compatible with Python3.3) and run it.
- Launch Python and type “import serial”. If no error message shows up, then the installation is successful.
- Stay in Python console, create a system object by running “import sys”. Run “sys.path” and copy the obtained search path.
- Launch Origin and open up script window by “shift+alt+3”, change it to Python editor by Edit:Script Execution: Python 3.3.
- Create a system object by running “import PyOrigin”, followed by “import sys” and assign the saved search path to the current search path by running “sys.path = pathname”. Of course replace pathname by the string saved in step 4. Now the embedded Python in Origin can use the pySerial module.
Read data into Origin:
- Download this pySerial.OPX Origin Package file (4 kB) and drag and drop the file onto Origin. Note that you may need to launch Origin not-as-administrator.
- A toolbar with a button will appear. Click the button to open the setup dialog. Set the target worksheet, number of rows, and sampling interval. Click send to start importing data.
- The button created from the opx is actually running a piece of Python script. The Python code PyserialToWorksheet is attached here as well.
- For RS232 connection the multimeter need to be set to remote mode to collect data. This is different from the GPIB connection.
\\ Python 2.7
\\ Python 3.3
aa = 'SYSTem:REMote\n'
3. The sampling rate is not very precise, because the data collection method (ser.read(20)) takes an extra 1 second. This doesn’t occur for GPIB connection.