# -*- coding: iso-8859-15 -*- import Ly import lys import sys from labjack import ljm TEXT_DeviceType = ["ANY", "T4", "T7"] TEXT_ConnectionType = ["ANY", "USB", "TCP", "ETHERNET", "WIFI"] TEXT_Identifier = ["ANY"] class info(object): def __init__(self): # (oo) # Variables for settings # Click on the help button to get more information. # Example variables self.DeviceType = TEXT_DeviceType[0] self.ConnectionType = TEXT_ConnectionType[0] self.Identifier = TEXT_Identifier[0] class pvar(object): def __init__(self): # (oo) # Working variables # Click on the help button to get more information. # Example variables pass class pscript(lys.mclass): def __init__(self, magic): self.info=info() self.pvar=pvar() def Create (self): # (oo) # Module initialization # Click on the help button to get more information. return True def Delete (self): # (oo) # Tidy up on deletion of the module (if needed) # Click on the help button to get more information. pass def DlgInit (self, dlg): # (oo) # Initialization of settings dialog # Click on the help button to get more information. # Set dialog title dlg.title = "Labjack LJM / Python Interface" # Determine the number of channels, current channel and # maximum number of channels # (Covers moduls which have only outputs and at least one of them. # You need to adjust this section if you have chosen another relation # setting. You can find more information how to do this in the help) self.DlgNumChannels = self.NumOutChannel self.DlgMaxChannels = Ly.MAX_CHANNELS # Setup dialog parameters dm = lys.DialogManager(self, dlg) dm.SelectModulePage() dm.AppendCategory( \ "Labjack Settings", desc="Connection Properties") DeviceTypeChoices = "\n".join(TEXT_DeviceType) dm.AppendEnum( \ "Device Type", DeviceTypeChoices, self.info.DeviceType, desc="") ConnectionTypeChoices = "\n".join(TEXT_ConnectionType) dm.AppendEnum( \ "Connection Type", ConnectionTypeChoices, self.info.ConnectionType, desc="") IdentifierChoices = "\n".join(TEXT_Identifier) dm.AppendEnum( \ "Identifier", IdentifierChoices, self.info.Identifier, desc="") dm.SelectChannelPage() def DlgOk (self, dlg): # (oo) # Get values of dialog parameters # Click on the help button to get more information. dom = lys.DialogOkManager(dlg) dom.SelectModulePage() self.info.DeviceType = dom.GetValue("Device Type") self.info.ConnectionType = dom.GetValue("Connection Type") self.info.Identifier = dom.GetValue("Identifier") dom.SelectChannelPage() # Configure Inputs and Outputs # (Covers moduls which have only outputs and at least one of them. # You need to adjust this section if you have chosen another relation # setting. You can find more information how to do this in the help) self.SetConnectors(0, self.DlgNumChannels) def DlgCancel (self, dlg): # (oo) # Cancel button clicked. # Click on the help button to get more information. pass def Save (self): # (oo) # Prepare data before worksheet will be saved (if needed) # Click on the help button to get more information. pass def Load (self): # (oo) # Prepare data after worksheet has been loaded (if needed) # Click on the help button to get more information. pass def Start (self): # (oo) # Initialize variables on start of measurement (if needed) # Click on the help button to get more information. # Open first found LabJack self.handle = ljm.openS(self.info.DeviceType, self.info.ConnectionType, self.info.Identifier) # Any device, Any connection, Any identifier #handle = ljm.openS("T7", "ANY", "ANY") # T7 device, Any connection, Any identifier #handle = ljm.openS("T4", "ANY", "ANY") # T4 device, Any connection, Any identifier #handle = ljm.open(ljm.constants.dtANY, ljm.constants.ctANY, "ANY") # Any device, Any connection, Any identifier self.pvar.m_outputs_done = 0 return True def Stop (self): # (oo) # Tidy up on stop of measurement (if needed) # Click on the help button to get more information. ljm.close(self.handle) pass def SetupFifo (self, channel): # (oo) # Setup flags, types and max. block size of a channel (if needed) # Click on the help button to get more information. # Comment out the lines below if you want to overwrite the settings # of the channel property dialog. self.SetSampleDistance(channel, Ly.GetTimeBaseSampleDistance(2)) self.SetMaxBlockSize(channel, Ly.GetTimeBaseBlockSize(2)) self.SetChannelType(channel, Ly.CT_NORMAL) self.SetChannelFlags(channel, Ly.CF_NORMAL) return True def ProcessValue (self, v, c): # (oo) # Process single value # Click on the help button to get more information. pass def ProcessData (self): # (oo) # Process data blocks # Click on the help button to get more information. # Process the channels bsize = Ly.GetTimeBaseBlockSize(2) sdist = Ly.GetTimeBaseSampleDistance(2) btime = bsize * sdist this_time = Ly.GetTimeBaseTime(2) next_time = self.pvar.m_outputs_done * btime if (this_time >= next_time): for channel in xrange(self.NumOutChannel): OutBuff = self.GetOutputBlock(channel) for i in xrange(bsize): OutBuff[i] = ljm.eReadName(self.handle, "AIN0") OutBuff.StartTime = next_time OutBuff.SampleDistance = sdist OutBuff.BlockSize = bsize OutBuff.Release() self.pvar.m_outputs_done += 1 return True