0

I am trying to connect a Cobright DX4 laser to my computer to control it from my computer. However I am unable to do so. I have tried using both rm.openresource() and through pyserial. However neither seem to work.

#import visa
import serial
import numpy as np
#rm = visa.ResourceManager() #checks devices that are
rm = visa.ResourceManager('@py') #to take the python backend
#rm = visa.ResourceManager('@sim')

print(rm.list_resources())

inst1 = rm.list_resources() 

    The output is ('ASRL5::INSTR')

However when I query the ID:

inst2 = rm.open_resource("ASRL5::INSTR",read_termination = '\n', write_termination="\r\n")

print(inst2.query("*IDN?"))

I get a timeout error

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

I have also tried to connect using pyserial.

import pyvisa as visa # note the recommended way to import pyvisa changed as there is an unrelated visa module
#import visa
import serial
import numpy as np

import serial.tools.list_ports
import sys

list = serial.tools.list_ports.comports()
connected = []
for element in list:
    connected.append(element.device)
print("Connected COM ports: " + str(connected))
# compliments of https://stackoverflow.com/questions/12090503/listing-available-com-ports-with-python#14224477
""" Lists serial port names

    :raises EnvironmentError:
        On unsupported or unknown platforms
    :returns:
        A list of the serial ports available on the system
"""
if sys.platform.startswith('win'):
# !attention assumes pyserial 3.x
    ports = ['COM%s' % (i + 1) for i in range(256)]
elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
    # this excludes your current terminal "/dev/tty"
    ports = glob.glob('/dev/tty[A-Za-z]*')
elif sys.platform.startswith('darwin'):
    ports = glob.glob('/dev/tty.*')
else:
    raise EnvironmentError('Unsupported platform')

result = []
for port in ports:
    try:
        s = serial.Serial(port)
        s.close()
        result.append(port)
    except (OSError, serial.SerialException):
        pass
print("Availible COM Ports: " + str(result))

Connected COM ports: ['COM5'] Availible COM Ports: ['COM5']

ser = serial.Serial(
    port="COM5", # assumes pyserial 3.x, for 2.x use integer values
    baudrate=9600,
    bytesize=8,
    parity="E",  # options are: {N,E,O,S,M}
    stopbits=1,
    timeout=1)

print(ser)

Serial<id=0x243e051beb0, open=True>(port='COM5', baudrate=9600, bytesize=8, parity='E', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False)

ser.isOpen()

True

Now when I try to send a command eg

ser.write(str.encode('*IDN?'))

5

is the output. I am unsure as to what the issue. I cannot decode having encoded.

Port should be working correctly

enter image description here

enter image description here

Any help appreciated, and sorry for the long post! I have also connected a power meter which worked fine.

  • Thankyou for any help, forgot to say! – OverflowofStack Sep 21 '22 at 15:52
  • What is the expected output of the command you sent? If you send another command, do you still get `5` as the output? – Jarvis Sep 21 '22 at 17:55
  • The command should identify the device. When I send other commands I get different numbers. Here is a link to the manual if it is of use: https://www.laserdiodesource.com/files/manuals/laserdiodesource_com/9006/Manual_CoBrite_DX_DX2-1615913063.pdf – OverflowofStack Sep 21 '22 at 20:58
  • @OverflowofStack Do you have NI Max installed and can you see COM5 in it? Does `*IDN?` work from that console? or from putty? – Nifim Sep 21 '22 at 22:41
  • @Nifim Yes I have it installed. And I cannot run it in NI max either., I also get a timeout error! I have not used putty before. – OverflowofStack Sep 22 '22 at 07:25
  • @Nifim The identification command works using a hyperterminal. However, I still cannot get it to work using python, either through resource manager or a serial port. I can connect but the commands do not seem to register. I do not have a c-compiler on my computer, could this be the issue? – OverflowofStack Sep 22 '22 at 08:27

0 Answers0