def close(self): """close the output.""" #c.comedi_cancel(self.device,self.subdevice) ljm.close(self.handle) print "output handle closed" #def set_PID(self,wanted_position,sensor_input): #"""send a signal through a PID, based on the wanted command and the sensor_input""" #self.time= time.time() #self.out=(wanted_position/self.gain)-self.offset #self.error=self.out-sensor_input #self.I_term += self.Ki*self.error*(self.last_time-self.time) #if self.I_term>self.out_max: #self.I_term=self.out_max #elif self.I_term<self.out_min: #self.I_term=self.out_min #self.out_PID=self.last_output+self.K*self.error+self.I_term-self.Kd*(sensor_input-self.last_sensor_input)/(self.last_time-self.time) #if self.out_PID>self.out_max: #self.out_PID=self.out_max #elif self.out_PID<self.out_min: #self.out_PID=self.out_min #self.last_time=copy.copy(self.time) #self.last_sensor_input=copy.copy(sensor_input) #self.last_output=copy.copy(self.out_PID) #out_a=c.comedi_from_phys(self.out_PID,self.range_ds,self.maxdata) # convert the wanted_position #c.comedi_data_write(self.device0,self.subdevice,self.channel,self.range_num,c.AREF_GROUND,out_a) # send the signal to the controler #t=time.time() #return (t,self.out_PID)
def disconnect(self): try: ljm.close(self.handle) except ljm.LJMError: pass finally: self.handle = None
def close(self): """Close the device.""" try: ljm.eStreamStop(self.handle) except ljm.LJMError: #if no streamer open pass finally: ljm.close(self.handle) print ("LabJack device closed")
def prepare_for_exit(handle, stop_stream=True): if stop_stream: print("\nStopping Stream") try: ljm.eStreamStop(handle) except ljm.LJMError as exception: if exception.errorString != "STREAM_NOT_RUNNING": raise ljm.close(handle)
def __new__(cls, *args): try: from labjack import ljm handle = ljm.openS("ANY", "ANY", "ANY") ljm.close(handle) return STORMDAQ(*args) except: return mockers.MockDAQ()
for k in range(0, NUM_IN_CHANNELS): ainStr += "%s: %0.5f, " % (POS_IN_NAMES[k], data[j * NUM_IN_CHANNELS + k]) print(" %s" % (ainStr)) print( " Scans Skipped = %0.0f, Scan Backlogs: Device = %i, LJM = " "%i" % (curSkip / NUM_IN_CHANNELS, ret[1], ret[2]) ) i += 1 end = datetime.now() print("\nTotal scans = %i" % (totScans)) tt = (end - start).seconds + float((end - start).microseconds) / 1000000 print("Time taken = %f seconds" % (tt)) print("LJM Scan Rate = %f scans/second" % (scanRate)) print("Timed Scan Rate = %f scans/second" % (totScans / tt)) print("Timed Sample Rate = %f samples/second" % (totScans * NUM_IN_CHANNELS / tt)) print("Skipped scans = %0.0f" % (totSkip / NUM_IN_CHANNELS)) except ljm.LJMError: ljme = sys.exc_info()[1] print(ljme) except Exception: e = sys.exc_info()[1] print(e) print("\nStop Stream") ljm.eStreamStop(handle) # Close handle ljm.close(handle)
def Close(handle): ljm.close(handle)
#handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier info = ljm.getHandleInfo(handle) print("Opened a LabJack with Device type: %i, Connection type: %i,\n" "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % (info[0], info[1], info[2], ljm.numberToIP(info[3]), info[4], info[5])) # Setup and call eWriteNames to set the ethernet configuration on the LabJack. numFrames = 4 names = [ "ETHERNET_IP_DEFAULT", "ETHERNET_SUBNET_DEFAULT", "ETHERNET_GATEWAY_DEFAULT", "ETHERNET_DHCP_ENABLE_DEFAULT" ] values = [ ljm.ipToNumber("192.168.1.207"), ljm.ipToNumber("255.255.255.0"), ljm.ipToNumber("192.168.1.1"), 1 ] ljm.eWriteNames(handle, numFrames, names, values) print("\nSet ethernet configuration:") for i in range(numFrames): if names[i] == "ETHERNET_DHCP_ENABLE_DEFAULT": print(" %s : %.0f" % (names[i], values[i])) else: print(" %s : %.0f - %s" % (names[i], values[i], ljm.numberToIP(int(values[i])))) # Close handle ljm.close(handle)
def close(self): ljm.close(self.handle)
def __del__(self): if self.valid is True: ljm.close(self.lj_handle) print("Goodbye from analog backend")
def __del__(self): if self.valid is True: ljm.close(self.lj_handle)
class DAC(): def __init__(self,device,channel): self.lj = device self.ch = str(channel) def set_v(self,value): """value """ name = ["DAC" + self.ch] self.lj.write(name,[value]) if __name__ == "__main__": #import time lj = LabJack() print("Opened a LabJack with Device type: %i, Connection type: %i,\n" \ "Serial number: %i, IP address: %s, Port: %i,\nMax bytes per MB: %i" % \ (lj.info[0], lj.info[1], lj.info[2], ljm.numberToIP(lj.info[3]), lj.info[4], lj.info[5])) ch0 = LJChannel(lj,0) #(device,DIO_channel_number) lj.clock(time2clock(9999)) ch0.pulse_start(time2clock(114)) #dac = DAC(lj,0) #dac.set_v(3) #time.sleep(3) #dac.set_v(0) # Close handle ljm.close(lj.handle)
def close(self): """ Close the device. """ ljm.close(self.handle)