USB interface to a BK-880 LCR meter; Questions I wish I had asked... These meters are a reasonably cheap way to read LCR data into a test station I was building. The interface is finicky though. So, take this as a report of (undocumented) things learned by painful experience. The code isn't spectacular but that isn't the point. I hope this helps somebody.
USB interface to a BK-880 LCR meter; Questions I wish I had asked... These meters are a reasonably cheap way to read LCR data into a test station I was building. The interface is finicky though. So, take this as a report of (undocumented) things learned by painful experience. The code isn't spectacular but that isn't the point. I hope this helps somebody.
Share Improve this question asked Jan 17 at 18:24 ClintFromVaClintFromVa 977 bronze badges1 Answer
Reset to default 1Setting the measuring mode. The available measuring modes, ['L', 'C', 'R', 'Z','DCR'], have to be cycled through in sequence, you can't just set the one you want. The mode must be an uppercase character, as above. The meter display may change immediately but actually responding with data in the new mode can take 10 to 12 seconds.
def get_Mode(self):
presentMode = ()
while not (presentMode in MEASURES): #Bogus value ('000e+00', None), wait and retry
presentMode = self.LCR_Conn.sendcmd('FUNCtion:impa?') #LCR_Conn is the port to the meter
# self.LCR_Conn.sendcmd('FUNCtion:impa?') => current mode (such as 'C'). Sometimes there is a bogus value, ('000e+00', None).
sleep(0.1)
return presentMode
def set_Mode(self, desiredMode):
# Find current mode at start (query until the current setting reads back)
# If the setting is not the desired one, go to next mode in sequence (wrapping to go backwards).
# Sending a mode request out of sequence causes "E12" and you have to power cycle the meter to recover.
Modes = MEASURES # Legal modes: MEASURES = ['L', 'C', 'R', 'Z','DCR']
presentMode = self.get_Mode() #check at beginning if mode is OK (doubtful)
if presentMode == desiredMode:
return presentMode
# align Modes list with current status
while presentMode != Modes[0]:
Modes.append(Modes.pop(0))
# sequence through Modes on meter
for i in range(len(Modes)):
presentMode = self.get_Mode()
if presentMode == desiredMode:
return presentMode
else:
self.LCR_Conn.sendcmd('FUNCtion:impa {0}'.format(Modes[i+1].upper()))
Reading. Data has to be checked for nonsense. Since the results are supposed to be numbers,
doing math on them is a good quality check.
There does not seem to be any way to handshake data reads. It gets updated whenever and if you try to read then it is luck of the draw wether or not a fault will occur. Sometimes, remote reads lock up the meter and you have to power-cycle it.
def get_data(self): # Fetch 1x, rely on timing to let meter settle
sleep(1.5) #Meter is set to slow measurement rate, 1.5 samples/second.
data = self.LCR_Conn.fetch()[0] #return is three items, only want the first
try:
foo = data * 12.34 #any math operation to complain when data is NAN
except(TypeError):
data = -1
raise self.LCR_Exception()
except(IndexError):
data = -1
raise self.LCR_Exception()
return data
Comms. The port may stay open even when the meter shuts off (the USB part stays powered). This confuses things and a reset is required. The assumption is that the LCR is powering up in remote Mode (this is configurable).
def LCR_reset(self):
""" Things may be confused after power cycle. Close and reopen port. """
try:
self.close_port()
except AttributeError: #There is no port
sleep(0)
else:
sleep(1)
try:
self.open_port() #not a sufficient test
self.get_data() #go read numbers
return(True)
except AttributeError: #port is bad. COM# may have changed
print("LCR's USB port ID is invalid")
return(False)
except: # The port is there but we can't get any data
print('LCR meter is not connected, on, and set to USB')
return(False)
USB port ID.
USB devices return metadata set by the OEM. BK has not populated much here that is helpful. The port.vid number is 4292. This is actually associated with the USB transciever chip, which gets used in other types of devices as well. If you only have one such device, this works to automatically recognize the meter. Otherwise, you have to rely on physical address on the USB hub.
Parameter settings. Don't set frequency, voltage, whatever, for modes that don't use them or it causes errors.
Meter defaults: The meter can be set to power on in a specific measuring mode, sample rate, and to be expecting remote control (i.e., USB).