0

i got issue to discuss

I want to control my instrument, GW Instek GDS-1000A-U with Python using Pyserial Library. So now i want to send *IDN? to my instrument. So, try to write code like this

import serial
import time       

class GDS1000AU : 
    def __init__(self, port, baudrate, timeout):
        self.ser = serial.Serial()
        self.port = self.ser.port(port)
        self.baudrate = self.ser.baudrate(baudrate)
        self.timeout = self.ser.timeout(timeout)
        self.ser.open()
        if self.ser.is_open == False:
            while self.ser.is_open == False :
                print("initializing...\n")
                time.sleep(0.1)
        else:
            self.ser.write('*IDN?\n'.encode())
            print(self.ser.readline())

GDS1000AU('dev/tty/USB0',9600,1)

i'm expecting return like this

initializing...
initializing...
initializing...
GW, GDS-1152A-U, XXXXXXX, V1.00 

those GW, GDS-1152A-U, XXXXXXX, V1.00 line it's mean format ID for my instruments. Anyone agree for my code or want to give comment for my code ? Thank You

  • You are missing a leading slash at the beginning of the tty device name – Jib Dec 02 '22 at 17:03
  • ok i will fix that, how about my __init__ code ? it's good or must fix again ? – Prayander Sahatma Siahaan Dec 02 '22 at 18:34
  • A good practice is not to do things that may take long time in the init. Instead you can add a dedicated function `connect` to do so. And may be an other function to send data.. – Jib Dec 02 '22 at 19:10
  • As a final word, I would say that you might to the code review stackexchange as your request does not require to fix bug or help you with any problem you face.. – Jib Dec 02 '22 at 19:33

0 Answers0