EEVblog Electronics Community Forum

Products => Test Equipment => Topic started by: kgmuzungu on December 09, 2019, 10:47:35 pm

Title: accessing Keysight U1177a bluetooth adaptor via Python
Post by: kgmuzungu on December 09, 2019, 10:47:35 pm
Hi,

you will find more information here:
http://blog.philippklaus.de/2014/02/agilent-u1273a (http://blog.philippklaus.de/2014/02/agilent-u1273a)
https://www.mjoldfield.com/atelier/2011/06/agilent-macos.html (https://www.mjoldfield.com/atelier/2011/06/agilent-macos.html)

Here an example code that worked for me on a Windows10 machine running Python 3.8
Code: [Select]
import serial
import time
from datetime import datetime

prevTimeStamp = datetime.now()
print(prevTimeStamp)


def send_receive(command):
    print(command)
    command = command + '\n'
    ser.write(command.encode())
    time.sleep(0.05)
    received = ser.readline().decode('utf-8')
    # print(received)
    return received


"""
#possible commands
send_receive('*IDN?')
send_receive('SYST:BATT?')
send_receive('CONF?')
send_receive('STAT?')
send_receive('FETC?')
#send_receive('*RST')
send_receive('SYST:VERS?')
send_receive('SYST:ERR?')
"""
with serial.Serial('COM6', 9600, timeout=1) as ser:
    for x in range(10):
        line = send_receive('READ?')
        # line = ser.readline().decode('utf-8')
        # print(line, float(line.decode('utf-8')))
        timestamp = datetime.now()
        timeDelta = (timestamp - prevTimeStamp).microseconds
        print(str(timestamp.second) + ',' + str(timestamp.microsecond), ' : ', float(line), "timedif to prev:",
              timeDelta,
              "microseconds")
        prevTimeStamp = timestamp