# Path: config.py
# def editbatconfig(section,item,itemvalue):
# def loadconfig():


import sys
import time
import serial
import binascii
import glob
import logger
from threading import Thread
from config import config
          self.sendcmd('QPIGS',110)
          self.rawdat['BInI']=float(self.reply[47:50].decode('ascii','strict'))
          self.rawdat['BOutI']=float(self.reply[77:82].decode('ascii','strict'))
          self.rawdat['PVI']=float(self.reply[60:64].decode('ascii','strict'))
          self.rawdat['BV']=float(self.reply[41:46].decode('ascii','strict'))
          self.rawdat['ACW']=float(self.reply[28:32].decode('ascii','strict'))
          self.sendQ1()
          self.rawdat['ChgStat']=self.reply[69:71]
          self.rawdat['PVW']=float(self.reply[53:56].decode('ascii','strict'))
          self.rawdat['ibat']=self.rawdat['BOutI']-self.rawdat['BInI']
          self.rawdat['ipv']=-self.rawdat['PVI']
          self.rawdat['iload']=self.rawdat['ibat']-self.rawdat['ipv']
          self.rawdat['DataValid']=True
          break
        except ValueError as err:
          log.error('PIP bad response{} to command {}'.format(self.reply,self.command))
          time.sleep(0.5)
          if i==4:
            self.pipdown=time.time() # flag pip is down
            log.error("PIP sn {} interface down".format(self.sn))
        except IOError as err:
          log.error('PIP interface error {}'.format(err))
          time.sleep(0.5)
          if i==4:
            self.pipdown=time.time() # flag pip is down
            log.error("PIP sn {} interface down".format(self.sn))
        finally:
          self.port.close()
    else:
      missedsamples=(time.time()-self.pipdown)//config['sampling']['sampletime']

# Path: config.py
# def editbatconfig(section,item,itemvalue):
# def loadconfig():


# Path: pip.py
import sys
import time
import serial
import binascii
import glob
import logger
from threading import Thread
from config import config

          self.sendcmd('QPIGS',110)
          self.rawdat['BInI']=float(self.reply[47:50].decode('ascii','strict'))
          self.rawdat['BOutI']=float(self.reply[77:82].decode('ascii','strict'))
          self.rawdat['PVI']=float(self.reply[60:64].decode('ascii','strict'))
          self.rawdat['BV']=float(self.reply[41:46].decode('ascii','strict'))
          self.rawdat['ACW']=float(self.reply[28:32].decode('ascii','strict'))
          self.sendQ1()
          self.rawdat['ChgStat']=self.reply[69:71]
          self.rawdat['PVW']=float(self.reply[53:56].decode('ascii','strict'))
          self.rawdat['ibat']=self.rawdat['BOutI']-self.rawdat['BInI']
          self.rawdat['ipv']=-self.rawdat['PVI']
          self.rawdat['iload']=self.rawdat['ibat']-self.rawdat['ipv']
          self.rawdat['DataValid']=True
          break
        except ValueError as err:
          log.error('PIP bad response{} to command {}'.format(self.reply,self.command))
          time.sleep(0.5)
          if i==4:
            self.pipdown=time.time() # flag pip is down
            log.error("PIP sn {} interface down".format(self.sn))
        except IOError as err:
          log.error('PIP interface error {}'.format(err))
          time.sleep(0.5)
          if i==4:
            self.pipdown=time.time() # flag pip is down
            log.error("PIP sn {} interface down".format(self.sn))
        finally:
          self.port.close()
    else:
      missedsamples=(time.time()-self.pipdown)//config['sampling']['sampletime']

      if missedsamples%(600/config['sampling']['sampletime'])==0:  #retry interface every 10 minutes