def connectionMade(self): SimpleProtocol.connectionMade(self) self.commands = [] # We will set this flag when we receive any reply from the device self.object['hw_connected'] = 1 SimpleProtocol.message(self, '*RST') SimpleProtocol.message(self, '*IDN?')
def connectionMade(self): SimpleProtocol.connectionMade(self) self.commands = [] # We will set this flag when we receive any reply from the device self.object['hw_connected'] = 0 SimpleProtocol.message(self, 'set_addr %d' % self.object['addr']) SimpleProtocol.message(self, 'L0X') SimpleProtocol.message(self, 'K0X') SimpleProtocol.message(self, '?$U0X') # enable EOI and holdoff SimpleProtocol.message(self, 'R0X') # set autorange
def message(self, string): if string in ['SYSTEM', 'STATUS', 'FRAME']: if string in self.commands.values(): # Such command is already sent and still without reply return SimpleProtocol.message(self, '>%02X%s' % (self.command_id, string)) self.commands[self.command_id] = string self.command_id = (self.command_id + 1) % 0x100 if string not in ['STATUS', 'FRAME', 'SYSTEM']: print 'ARCHON << %s' % string
def message(self, string, keep=False, source='itself'): """ Send the message to the controller. If keep=True, append the command name to internal queue so that we may properly recognize the reply """ if keep: self.commands.append({'cmd': string, 'source': source, 'timeStamp': datetime.datetime.utcnow(), 'keep': keep}) SimpleProtocol.message(self, '?$%s' % string) else: SimpleProtocol.message(self, string)
def update(self): # Request the hardware state from the device if len(self.commands): SimpleProtocol.message(self, self.commands[0]['cmd']) if not self.commands[0]['keep']: self.commands.pop(0) else: for k in self.status_commands: self.commands.append({ 'cmd': k, 'source': 'itself', 'keep': True }) SimpleProtocol.message(self, self.commands[0]['cmd'])
def message(self, string, keep=False, source='self'): """ Send the message to the controller. If keep=True, append the command name to internal queue so that we may properly recognize the reply """ self.update_daemonQs() if source in self.daemonQs.keys(): # This is a GPIB connection, add the command to the corresponding queue self.daemonQs[source].append({'cmd': string}) if keep and source != 'itself' and string not in ['++srq']: self.daemonQs[source].append({'cmd': '++read eoi'}) else: # Handle non-GPIB messages as usual SimpleProtocol.message(self, '%s' % (string)) if keep: self.commands.append(string)
def update(self): print('--------self.commands--------------') for cc in self.commands: print(cc) print('----------------------') # first check if device is hw_connected if self.object['hw_connected'] == 0: # if not connected do not send any commands return if len(self.commands) and not self.commands[0]['sent']: SimpleProtocol.message(self, self.commands[0]['cmd']) if not self.commands[0]['keep']: self.commands.pop(0) else: self.commands[0]['sent'] = True elif not len(self.commands): for k in self.status_commands: self.commands.append({ 'cmd': k, 'source': 'itself', 'keep': True, 'sent': False })
def update(self): if self._debug: print ("Busy flag", self.readBusy) if self.readBusy[0]: if time.time()-self.readBusy[1]>3: SimpleProtocol.message(self, '++read eoi') self.readBusy[1]=time.time() return self.update_daemonQs() if self._debug: print ("daemonQs:", self.daemonQs) last_addr=self.next_addr no_commands = True for k in range(len(self.gpibAddrList)): try: d=self.gpibAddrList.index(last_addr) - k - 1 self.next_addr = self.gpibAddrList[d] if self._debug: print ("Found last addr (", self.next_addr, ")") except BaseException: self.next_addr = self.gpibAddrList[0] if self._debug: print ("Last addr not found (perhaps disconnected meanwhile), switching to the first (", self.next_addr, ")") if len(self.daemonQs[self.next_addr]): if self.object['current_addr'] != self.next_addr: if self._debug: print ("switching to addr (", self.next_addr, ")") SimpleProtocol.message(self, '++addr %i' % self.next_addr) self.object['current_addr'] = self.next_addr #time.sleep(0.1) # we need to wait a bit here to allow the controller to finish changing the addr cmd = self.daemonQs[self.next_addr].pop(0) no_commands = False if cmd['cmd'] in ['++read eoi', '++addr', '++srq']: self.readBusy = [True,time.time()] SimpleProtocol.message(self, cmd['cmd']) break if no_commands and (time.time()-self.readBusy[1])>1.: if self._debug: print ("There is either no GPIB connections, or nothing to do for them, doing ++addr to keep the connection alive") self.message('++addr', keep=True) self.readBusy = [True,time.time()]
def connectionMade(self): SimpleProtocol.connectionMade(self) self.object['hw_connected'] = 0 # We will set this flag when we receive any reply from the device SimpleProtocol.message(self, 'set_addr %d' % self.object['addr']) SimpleProtocol.message(self, '?$SYST:ERR?') self.commands = [{'cmd': 'SYST:ERR?', 'source': 'itself', 'timeStamp': datetime.datetime.utcnow(), 'keep': 'keep'}] SimpleProtocol.message(self, '*RST') SimpleProtocol.message(self, 'OUTP:LOAD 50') self.object['out_load'] = 50 SimpleProtocol.message(self, 'VOLT:OFFS 0') self.object['volt_offs'] = 0 SimpleProtocol.message(self, 'VOLT:UNIT VPP') self.object['volt_unit'] = 'VPP' SimpleProtocol.message(self, '?$*OPC?') self.commands = [{'cmd': '*OPC?', 'source': 'itself', 'timeStamp': datetime.datetime.utcnow(), 'keep': 'keep'}]
def connectionMade(self): SimpleProtocol.connectionMade(self) self.object[ 'hw_connected'] = 0 # We will set this flag when we receive any reply from the device SimpleProtocol.message(self, 'set_addr %d' % self.object['addr']) SimpleProtocol.message(self, '*rst') SimpleProtocol.message(self, '*cls') SimpleProtocol.message(self, ':SYST:ZCH ON') SimpleProtocol.message(self, ':CURR:RANG 2E-9') SimpleProtocol.message(self, ':INIT') SimpleProtocol.message(self, ':SYST:ZCOR:ACQ') SimpleProtocol.message(self, ':SYST:ZCH OFF') SimpleProtocol.message(self, ':SYSR:ZCOR ON') SimpleProtocol.message(self, ':CURR:RANG:AUTO ON') SimpleProtocol.message(self, '?$*opc?') self.commands = [{ 'cmd': '*opc?', 'source': 'itself', 'timeStamp': datetime.datetime.utcnow(), 'keep': 'keep' }]