Connecting via USB/Serial port to Newport CONEX-PP Motion Controller in Python

Question:

I’m having trouble getting my Windows 7 laptop to talk to a Newport CONEX-PP motion controller. I’ve tried python (Spyder/Anaconda) and a serial port streaming program called Termite and in either case the results are the same: no response from the device. The end goal is to communicate with the controller using python.

The controller connects to my computer via a USB cable they sold me that is explicitly for use with this device. The connector has a pair of lights that blink when the device receives data (red) or sends data (green). There is also a packaged GUI program that comes with the device that seems to work fine. I haven’t tried every button, the ones I have tried have the expected result.

The documentation for accessing this device is next to non-existant. The CD in the box has one way to connect to it and the webpage linked above has a different way. The first way (CD from the box) creates a hierarchy of modules that ends in a module it does not recognize (this is a code snippet provided by Newport):

import sys  
sys.path.append(r'C:NewportMotionControlCONEX-PPBin')  
import clr  
clr.AddReference("Newport.CONEXPP.CommandInterface")  
from CommandInterfaceConexPP import *  
import System  
instrument="COM5"  
print 'Instrument Key=>', instrument  
myPP = ConexPP()  
ret = myPP.OpenInstrument(instrument)  
print 'OpenInstrument => ', ret  
result, response, errString = myPP.SR_Get(1)

That last line returns:

Traceback (most recent call last):

File “< ipython-input-2-5d824f156d8f >”, line 2, in
result, response, errString = myPP.SR_Get(1)

TypeError: No method matches given arguments

I’m guessing this is because the various module references are screwy in some way. But I don’t know, I’m relatively new to python and the only time I have used it for serial communication the example files provided by the vendor simply worked.

The second way to communicate with the controller is via the visa module (the CONEX_SMC_common module imports the visa module):

import sys  
sys.path.append(r'C:NewportNewportPython')  
class CONEX(CONEXSMC): def __init__(self):  
    super(CONEX,self).__init__() device_key = 'com5'  
    self.connect=self.rm.open_resource(device_key, baud_rate=57600, timeout=2000, data_bits=8, write_termination='rn',read_termination='rn')  
mine.connect.read()  

That last mine.connect.read() command returns:

VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

If, instead, I write to the port mine.connect.write('VE') the light on the connector flashes red as if it received some data and returns:

(4L, < StatusCode.success: 0 >)

If I ask for the dictionary of the “mine” object mine.__dict__, I get:

{‘connect’: <‘SerialInstrument'(u’ASRL5::INSTR’)>,
‘device_key’: u’ASRL5::INSTR’,
‘list_of_devices’: (u’ASRL5::INSTR’,),
‘rm’: )>}

The ASRL5::INSTR resource for VISA is at least related to the controller, because when I unplug the device from the laptop it disappears and the GUI program will stop working.

Maybe there is something simple I’m missing here. I have NI VISA installed and I’m not just running with the DLL that comes from the website. Oh, I found a Github question / answer with this exact problem but the end result makes no sense, the thread is closed after hgrecco tells him to use “open_resource” which is precisely what I am using.

Results with Termite are the same, I can apparently connect to the controller and get the light to flash red, but it never responds, either through Termite or by performing the requested action.

I’ve tried pySerial too:

import serial  
ser = serial.Serial('com5')  
ser.write('VErn')  
ser.read()  

Python just waits there forever, I assume because I haven’t set a timeout limit.

So, if anyone has any experience with this particular motion controller, Newport devices or with serial port communication in general and can shed some light on this problem I’d much appreciate it. After about 7 hours on this I’m out of ideas.

Asked By: Finncent Price

||

Answers:

After coming back at this with fresh eyes and finding this GitHub discussion I decided to give pySerial another shot because neither of the other methods in my question are yet working. The following code works:

import serial  
ser = serial.Serial('com5',baudrate=115200,timeout=1.0,parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)  
ser.write('1TS?rn')  
ser.read(10)

and returns

‘1TS000033r’

The string is 9 characters long, so my arbitrarily chosen 10 character read ended up picking up one of the termination characters.

The problem is that python files that come with the device, or available on the website are at best incomplete and shouldn’t be trusted for anything. The GUI manual has the baud rate required. I used Termite to figure out the stop bit settings – or at least one that works.

Answered By: Finncent Price

3.5 years later…

Here is a gist with a class that supports Conex-CC

It took me hours to solve this!

My device is Conex-CC, not PP, but it’s seem to be the same idea.

For me, the serial solution didn’t work because there was absolutely no response from the serial port, either through the code nor by direct TeraTerm access.

So I was trying to adapt your code to my device (because for Conex-CC, even the code you were trying was not given!).

It is important to say that import clr is based on pip install pythonnet and not pip install clr which will bring something related to colors.

After getting your error, I was looking for this Pythonnet error and have found this answer, which led me to the final solution:

import clr
# We assume Newport.CONEXCC.CommandInterface.dll is copied to our folder
clr.AddReference("Newport.CONEXCC.CommandInterface")
from CommandInterfaceConexCC import *

instrument="COM4"
print('Instrument Key=>', instrument)
myCC = ConexCC()
ret = myCC.OpenInstrument(instrument)
print('OpenInstrument => ', ret)
response = 0
errString = ''
result, response, errString = myCC.SR_Get(1, response, errString)
print('Positive SW Limit: result=%d,response=%.2f,errString='%s''%(result,response,errString))
myCC.CloseInstrument()

And here is the result I’ve got:

Instrument Key=> COM4
OpenInstrument =>  0
Positive SW Limit: result=0,response=25.00,errString=''�
Answered By: ishahak

For Conex-CC serial connections are possible using both pyvisa

import pyvisa
rm = pyvisa.ResourceManager()
inst = rm.open_resource('ASRL6::INSTR',baud_rate=921600, write_termination='rn',read_termination='rn')
pos = inst.query('01PA?').strip()

and serial

import serial
serial = serial.Serial(port='com6',baudrate=921600,bytesize=8,parity='N',stopbits=1,xonxoff=True)
serial.write('01PA?'.encode('ascii'))
serial.read_until(b'rn')

All the commands are according to the manual

Answered By: KlickyStack
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.