Example #1
0
def compressor(state=None):
    if state == None:
        return DAQC.getDOUTbyte(0)
    if state == True:
        DAQC.setDOUTbit(0, 0)
    if state == False:
        DAQC.clrDOUTbit(0, 0)
Example #2
0
def calc_vswr(ant, f, r):
    """Calculates the Voltage Standing Wave Ratio (VSWR) for a given antenna.

  Arguments:
  ant -- The antenna height (aquired from the config file)
  f -- Analog I/O pin on the DAQCplate board to read
  r -- Analog I/O pin on the DAQCplate board to read
  """

    #  fwdcalfac = get_calfac(f)
    #  revcalfac = get_calfac(r)

    f = abs(DAQC.getADC(0, f))
    r = abs(DAQC.getADC(0, r))
    # TODO For normalizing elements when true test rig is ready
    #  f=f-fwdcalfac
    #  r=r-revcalfac
    # Need to divide voltage by 50 ohm to get current, multiply current times voltage to get watts
    x = abs(1 + math.sqrt(rm_utils.safe_div(r, f)))
    y = abs(1 - math.sqrt(rm_utils.safe_div(r, f)))
    swr = round(rm_utils.safe_div(x, y), 3)
    if swr > 3.0:
        logger.warning(
            "calc_vswr: Ant Height: {} SWR:  \033[91m {} \033[0m".format(
                ant, swr))
        if DEBUG:
            print("Ant Height: {} SWR:  \033[91m {} \033[0m".format(ant, swr))
    else:
        if DEBUG:
            print("Ant Height: {} SWR:  \033[92m {} \033[0m".format(ant, swr))
    return swr
Example #3
0
 def vdelta(self):
     if (self.state.get() == "ON"):
         x = self.voltage.get() / 60.84 + 4.9
         if (x < 0): x = 0
         if (x > 4.095): x = 4.095
         DAQC.setDAC(0, 1, x)
     else:
         DAQC.setDAC(0, 1, 0)
     print "bias V:", DAQC.getDAC(0, 1)
 def setValues(self, address, values):
     caddress = self.corrected_address(address)
     for i, value in enumerate(values):
         bit_addr = caddress + i
         self.log('writing {} to {}'.format(value, bit_addr))
         if value:
             dp.setDOUTbit(self._board_address, bit_addr)
         else:
             dp.clrDOUTbit(self._board_address, bit_addr)
Example #5
0
def task():
    global lastT
    global lastR
    global lastSW
    global swMode
    global GC
    adata = DAQC.getADCall(3)
    val = round(DAQC.getADC(0, 8), 1)
    Power5Text.set(val)

    val = round((adata[1] - 2.73) * 100, 2)
    val = 0.2 * val + 0.8 * lastT
    lastT = val
    TempText.set(str("{:>3.1f}".format(val)) + 'C')

    val = round(adata[2] * 12.21 / 1.636, 1)
    Power12Text.set(val)

    val = round(adata[0] / 4.096 * 100, 1)
    FanText.set(str(val) + '%')
    DAQC.setPWM(0, 0, int(val * 1024 / 100))

    val = DAQC.getRANGE(0, 6, 'c')
    if isinstance(val, float):
        if val > 100:
            val = 99.9
    else:
        val = 0
    val = round(val, 1)
    val = 0.8 * lastR + 0.2 * val
    lastR = val
    RangeText.set(str("{:>2.1f}".format(val)) + 'cm')

    lamp = 0
    if (DAQC.getDINbit(0, 2) == 1):
        lamp = 32

    sw = DAQC.getSWstate(0)
    if (sw == 1) and (lastSW == 0):
        lastSW = 1
        swMode = not swMode
        if swMode:
            GCmode.set('Binary Code :')
        else:
            GCmode.set('Grey Code :')
    if (sw == 0) and (lastSW == 1):
        lastSW = 0

    val = (int(adata[7] * 32 / 4.096))
    if swMode == 0:
        GCText.set(GC[val])
        num = GC[val]
    else:
        GCText.set(val)
        num = val
    DAQC.setDOUTall(0, (num + lamp))

    root.after(100, task)
    def run(self, *args):
        logger.info("ButtonPushedThread run start")

        DAQC.enableSWint(self.daqcBoard)
        DAQC.intEnable(self.daqcBoard)
        while True:
            if self.isShutdown:
                break
            if DAQC.getINTflags(self.daqcBoard) == 256:
                self.pillDispenser.setDispenseState('CONFIRMING')
                break
            time.sleep(.25)
def main():
	signal.signal(signal.SIGINT, signal_handler)
	while True:
		value = round(DAQC.getADC(0, DACport), 2)
		if (value < 3.20) or (value > 3.7) :
			print "Value " + str(value) + ", Activated!"
			DAQC.setDOUTbit(0,0)
			playAudio()
			DAQC.clrDOUTbit(0,0)
		else:
			print "Value " + str(value) + ", Waiting..."
		time.sleep(0.1)
	GPIO.cleanup()
Example #8
0
 def logData(self):
     global data
     if (self.logstate.get() == "Logging"):
         print "Logging..."
         sampleSet = np.zeros(shape=[10, 1])
         for x in range(10):
             sampleSet[x] = DAQC.getADC(0, self.sumChannel)
         averageSum = np.mean(sampleSet)
         data = np.append(
             data,
             [[DAQC.getADC(0, self.tempChannel), averageSum, fb_bias]],
             axis=0)
     root.after(self.subInterval.get(), self.logData)
Example #9
0
    def run(self, *args):
        logger.info("BlinkLedThread run start")

        while True:
            if self.isShutdown:
                break
            for i in range(0, 100):
                DAQC.clrLED(self.daqcBoard, 0)
                DAQC.clrLED(self.daqcBoard, 1)
            time.sleep(.25)
            for i in range(0, 100):
                DAQC.setLED(self.daqcBoard, self.led)
            time.sleep(.25)
        for i in range(0, 100):
            DAQC.clrLED(self.daqcBoard, 0)
            DAQC.clrLED(self.daqcBoard, 1)
Example #10
0
    def __init__(self, master, channel, r, c):
        self.master = master
        self.channel = channel
        self.tm = Frame(self.master, padx=4, pady=4, bd=2, relief='sunken')
        self.tm.grid(row=r, column=c, sticky=N + S + W + E)

        ##Font
        self.heading = tkFont.Font(family='Helvetica', size=18, weight='bold')

        ##Title
        self.labelt = Label(self.tm,
                            text="Temperature (C):",
                            padx=4,
                            pady=4,
                            font=self.heading)
        self.labelt.grid(row=0, sticky=W + E)

        ##display
        self.temp = DoubleVar()
        self.temp.set(18.14 * DAQC.getADC(0, channel) - 20.32)
        self.tempLabel = Label(self.tm,
                               textvariable=self.temp,
                               font=self.heading,
                               fg='green')
        self.tempLabel.grid(row=1, sticky=W + E)

        ##update button, until better solution found
        self.buttonu = Button(self.tm,
                              text="Update",
                              command=self.update,
                              padx=4,
                              pady=4)
        self.buttonu.grid(row=2, sticky=W + E)
Example #11
0
def db_din():
    """Scans the Digital Input pins for status."""

    for din in DIGIN:
        if din == 0:
            din_0 = DAQC.getDINbit(0, 0)
            val = rm_utils.eval_din(din_0)
            if DEBUG:
                print("Din {}: {}".format(0, val))
        elif din == 1:
            din_1 = DAQC.getDINbit(0, 1)
            val = rm_utils.eval_din(din_1)
            if DEBUG:
                print("Din {}: {}".format(1, val))
        elif din == 2:
            din_2 = DAQC.getDINbit(0, 2)
            val = rm_utils.eval_din(din_2)
            if DEBUG:
                print("Din {}: {}".format(2, val))
        elif din == 3:
            din_3 = DAQC.getDINbit(0, 3)
            val = rm_utils.eval_din(din_3)
            if DEBUG:
                print("Din {}: {}".format(3, val))
        elif din == 4:
            din_4 = DAQC.getDINbit(0, 4)
            val = rm_utils.eval_din(din_4)
            if DEBUG:
                print("Din {}: {}".format(4, val))
        elif din == 5:
            din_5 = DAQC.getDINbit(0, 5)
            val = rm_utils.eval_din(din_5)
            if DEBUG:
                print("Din {}: {}".format(5, val))
        elif din == 6:
            din_6 = DAQC.getDINbit(0, 6)
            val = rm_utils.eval_din(din_6)
            if DEBUG:
                print("Din {}: {}".format(6, val))
        elif din == 7:
            din_7 = DAQC.getDINbit(0, 7)
            val = rm_utils.eval_din(din_7)
            if DEBUG:
                print("Din {}: {}".format(7, val))

    query = """INSERT INTO `digInput` (`id`, `unix_time`, `dig0`, `dig1`, `dig2`, `dig3`, `dig4`, `dig5`, `dig6`, `dig7`) VALUES (NULL, CURRENT_TIMESTAMP, '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}')"""

    try:
        cursor.execute(
            query.format(din_0, din_1, din_2, din_3, din_4, din_5, din_6,
                         din_7))
        mariadb_connection.commit()
    except mariadb.Error as err:
        logger.error("DB: db_din FAILED: {}".format(err))
        mariadb_connection.rollback()
        if DEBUG:
            print("\033[91m Error digInput db \033[0m {}".format(err))
Example #12
0
 def __init__(self, loginVo, sensorName):
     logger.info('ProcessLedGreen init')
     self.loginVo = loginVo
     self.sensorName = sensorName
     DAQC.clrLED(0, 0)
     DAQC.clrLED(0, 1)
     DAQC.enableSWint(0)
     DAQC.intEnable(0)
     self.ledColor = 'green'
     self.btnPressed = '0'
Example #13
0
def Curr(addr, bit):
  Vmax = 0.0

  for x in range (0,128):
    Vin = daqc.getADC(addr, bit)
    Vin = (Vin - V_OFFSET)
    if Vin > Vmax:
      Vmax = Vin

  return (Vmax * 30)
Example #14
0
 def update(self):
     if (self.var.get() == 1):
         self.val.set(DAQC.getDINbit(self.addr, self.chan))
         self.valstring.set(str(self.val.get()))
         self.log[self.nextPtr] = self.val.get()
         self.nextPtr = (self.nextPtr + 1) % self.maxrange
         self.plot()
         return self.val.get()
     else:
         return ''
Example #15
0
    def createIote2eRequest(self ):
        time.sleep(1)
        logger.info('ProcessTempToFan createIote2eRequest:')
        #TODO: get temp from DAQC
        tempC = str(round(DAQC.getTEMP(0,0,'c'),2))
        pairs = { self.sensorName: tempC }

        iote2eRequest = Iote2eRequest( login_name=self.loginVo.loginName,source_name=self.loginVo.sourceName, source_type='temperature', 
                                       request_uuid=str(uuid.uuid4()), 
                                       request_timestamp=ClientUtils.nowIso8601(), 
                                       pairs=pairs, operation='SENSORS_VALUES')
        return iote2eRequest
Example #16
0
def Vrms(plate, addr):
   Vmax = 0
   Vmin = 1000

   for x in range(0,200):
      Vin = (daqc.getADC(plate ,addr) - V_OFFSET)
      if Vin > Vmax:
         Vmax = Vin
      if Vin < Vmin:
         Vmin = Vin

   Veff = Vmax * V_RATIO
   return Veff
Example #17
0
 def __init__(self, root, addr, channel):
     self.addr = addr
     self.root = root
     self.chan = channel
     self.var = IntVar()  #This is the select button for each channel
     self.var.set(1)
     self.val = DoubleVar()
     self.val.set(DAQC.getADC(self.addr, self.chan))
     self.valstring = StringVar()
     self.valstring.set(str(self.val.get()))
     off = H - 2 - 17 * SLICE + self.chan * SLICE
     BG = '#888FFFFFF'
     self.CWidth = int(.75 * W + 20)
     self.a2df = Frame(self.root, bg=BG, bd=0, relief="ridge")
     self.a2df.place(x=0, y=off, width=W, height=SLICE)
     self.a2dc = Checkbutton(self.a2df,
                             fg="Black",
                             bg=BG,
                             variable=self.var,
                             onvalue=1,
                             offvalue=0,
                             command=self.cb)
     self.a2dc.grid(row=0, column=0, sticky="w")
     self.var.set(1)
     self.a2dl = StringVar(root,
                           value="A2D Channel " + str(self.chan) + ":")
     self.a2dt = Label(self.a2df,
                       textvariable=self.valstring,
                       fg="Black",
                       bg=BG,
                       width=5).grid(row=0, column=2, sticky="w")
     self.a2dtxt = Entry(self.a2df,
                         textvariable=self.a2dl,
                         fg="Black",
                         bg=BG,
                         bd=0,
                         relief="flat",
                         width=12)
     self.a2dtxt.grid(row=0, column=1, sticky="w")
     self.a2dcanvas = Canvas(self.a2df,
                             bg=BG,
                             width=self.CWidth,
                             height=SLICE,
                             bd=0,
                             relief="flat")
     self.a2dcanvas.grid(row=0, column=3, sticky="e")
     self.maxrange = self.CWidth
     self.log = range(self.maxrange)
     for i in range(self.maxrange):
         self.log[i] = 0.0
     self.nextPtr = 0
Example #18
0
    def __init__(self, root, addr, channel):
        self.root = root
        self.addr = addr
        self.chan = channel
        self.var = IntVar()
        self.var.set(1)
        self.val = IntVar()
        self.val.set(DAQC.getDINbit(self.addr, self.chan))
        self.valstring = StringVar()
        self.valstring.set(str(self.val.get()))

        off = H - 2 - 9 * SLICE + self.chan * SLICE
        BG = '#FFFFFF888'
        self.CWidth = int(.75 * W + 20)
        self.dinf = Frame(self.root, bg=BG, bd=0, relief="ridge")
        self.dinf.place(x=0, y=off, width=W, height=SLICE)
        self.dinc = Checkbutton(self.dinf,
                                fg="Black",
                                bg=BG,
                                variable=self.var,
                                command=self.cb)
        self.dinc.grid(row=0, column=0, sticky="w")
        self.dinl = StringVar(root,
                              value="DIN Channel " + str(self.chan) + ":")
        self.dint = Label(self.dinf,
                          textvariable=self.valstring,
                          fg="Black",
                          bg=BG,
                          width=5)
        self.dint.grid(row=0, column=2, sticky="w")
        self.dintxt = Entry(self.dinf,
                            textvariable=self.dinl,
                            fg="Black",
                            bg=BG,
                            bd=0,
                            relief="flat",
                            width=12)
        self.dintxt.grid(row=0, column=1, sticky="w")
        self.dincanvas = Canvas(self.dinf,
                                bg=BG,
                                width=self.CWidth,
                                height=SLICE,
                                bd=0,
                                relief="flat")
        self.dincanvas.grid(row=0, column=3, sticky="e")
        self.maxrange = self.CWidth
        self.log = range(self.maxrange)
        for i in range(self.maxrange):
            self.log[i] = 0.0
        self.nextPtr = 0
Example #19
0
def triggerINT():
    """Callback rountine when a Digital Input has been triggered.
  """
    logger.debug("triggerINT")

    DAQC.setDOUTbit(0, 0)
    DAQC.getINTflags(0)
    if DEBUG:
        print("\033[94m _-*xmit triggered!*-_ \033[0m")
    vswr()
    DAQC.clrDOUTbit(0, 0)
Example #20
0
def plot_update():
    global voltages
    global currents
    x.append(len(x))
    voltage1 = DAQC.getADC(0, 0)
    voltage2 = DAQC.getADC(0, 1)
    voltage3 = DAQC.getADC(0, 2)
    voltage4 = DAQC.getADC(0, 3)
    voltage5 = DAQC.getADC(0, 4)
    voltage6 = DAQC.getADC(0, 5)
    voltage7 = DAQC.getADC(0, 6)
    voltage8 = DAQC.getADC(0, 7)
    voltages1.append(voltage1)
    voltages2.append(voltage2)
    voltages3.append(voltage3)
    voltages4.append(voltage4)
    voltages5.append(voltage5)
    voltages6.append(voltage6)
    voltages7.append(voltage7)
    voltages8.append(voltage8)
    length = len(x)
    source.data = dict(x=x,
                       voltages1=voltages1,
                       voltages2=voltages2,
                       voltages3=voltages3,
                       voltages4=voltages4,
                       voltages5=voltages5,
                       voltages6=voltages6,
                       voltages7=voltages7,
                       voltages8=voltages8)
    change = str(length).strip() + "," + str(datetime.datetime.now(
    )) + "," + str(time.time() - t0) + "," + str(voltage1).strip(
    ) + "," + str(voltage2).strip() + "," + str(voltage3).strip() + "," + str(
        voltage4).strip() + str(voltage5).strip() + "," + str(voltage6).strip(
        ) + "," + str(voltage7).strip() + "," + str(voltage8).strip() + ","
    with open(os.path.join(directory_control.value, file_control.value),
              'a') as f:
        # writer = csv.writer(f)
        f.write(change)
        f.write("\n")
        f.close()
Example #21
0
 def createIote2eRequest(self):
     iote2eRequest = None
     if DAQC.getINTflags(0) == 256:
         logger.info("ProcessLedGreen createIote2eRequest {}".format(
             self.sensorName))
         pairs = {self.sensorName: self.btnPressed}
         iote2eRequest = Iote2eRequest(
             login_name=self.loginVo.loginName,
             source_name=self.loginVo.sourceName,
             source_type='switch',
             request_uuid=str(uuid.uuid4()),
             request_timestamp=ClientUtils.nowIso8601(),
             pairs=pairs,
             operation='SENSORS_VALUES')
         if self.btnPressed == '1':
             self.btnPressed = '0'
         else:
             self.btnPressed = '1'
     return iote2eRequest
Example #22
0
def main():
    try:
        """Main program loop."""
        logger.debug("Main loop start")

        cursor.execute("SHOW TABLES LIKE 'swr'")
        result = cursor.fetchone()
        if result:
            if DEBUG:
                print("\033[92mDB: database and tables exist \033[0m")
        else:
            if DEBUG:
                print("\033[91mDB: no tables, creating database \033[0m")
            createDB()

        while True:
            if GPIO.event_detected(22):
                triggerINT()
            rm_utils.clr_all()
            # Two red flashes denotes start of cycle
            rm_utils.blink_red()
            rm_utils.blink_red()
            if DEBUG:
                print(time.ctime())
                print("INT flags: {}".format(DAQC.getINTflags(0)))
            db_analog()
            db_din()
            rm_utils.blink_red()
            rm_utils.blink_red()
            # Two red flashes denotes end of cycle
            rm_utils.clr_all()
            if DEBUG:
                print("\033[91mDEBUG sleep 10s\033[0m")
                sleep(10)
            else:
                # sleep for 30 minutes
                sleep(900)
    except KeyboardInterrupt:
        cursor.close()
        mariadb_connection.close()
        GPIO.cleanup()
Example #23
0
    def __init__(self, master, title, channel, r, c):
        self.master = master
        self.channel = channel
        self.tm = Frame(self.master, padx=4, pady=4, bd=2, relief='sunken')
        self.tm.grid(row=r, column=c, sticky=N + S + W + E)

        ##Fonts
        self.title = tkFont.Font(family='Helvetica', size=24, weight='bold')
        self.heading = tkFont.Font(family='Helvetica', size=16, weight='bold')
        self.normal = tkFont.Font(family='Helvetica', size=14)

        ##Title
        self.labelt = Label(self.tm,
                            text=title,
                            padx=4,
                            pady=4,
                            font=self.title)
        self.labelt.grid(row=0, column=0, columnspan=2, sticky=W + E)

        ##display
        self.labelv1 = Label(self.tm,
                             text="Voltage:",
                             font=self.heading,
                             anchor=E)
        self.labelv1.grid(row=1, column=0, sticky=W + E)
        self.tvoltage = DoubleVar()
        self.tvoltage.set(DAQC.getADC(0, channel))
        self.labelv2 = Label(self.tm,
                             textvariable=self.tvoltage,
                             font=self.heading,
                             fg='green',
                             anchor=W)
        self.labelv2.grid(row=1, column=1, sticky=W + E)

        ##update button, until better solution found
        self.buttonu = Button(self.tm,
                              text="Update",
                              command=self.update,
                              padx=4,
                              pady=4)
        self.buttonu.grid(row=2, column=0, columnspan=2, sticky=W + E)
def signal_handler( signal, frame ):
	pygame.mixer.stop()
	DAQC.clrDOUTbit(0,0)
	sys.exit(0)
Example #25
0
def showTemperature():
    for i in range(0, 10):
        t = round(DAQC.getTEMP(0, 0, 'c'), 2)
        print(t)
        sleep(1)
Example #26
0
    HC-SR04
Aansluitschema:
    5V: Digital-Output socket 10
    Ground: Digital-Input socket 10
    Trigger: Digital-Output socket 0
    Echo: Digital Input socket 0

Zie voor details:
    https://pi-plates.com/daqc-users-guide/#Distance_Measurement_with_the_HC-SR04
'''

#### werkt alleen als de hardware is aangesloten
# distance = DAQC.getRANGE(0,0,'c') # geeft afstand in cm
# print(distance)

####### Lees data van Analoge Input

val = DAQC.getADC(0, 1)  # DAQC 0, adres Analog-Input 1
print(val)
val8 = DAQC.getADCall(0)  # lees alle 8 Analog-Inputs
print(val8)

######## Lees meerdere data punten

data = get_data.readPiPlate(DAQC,
                            [0, 1, 2])  # kanaal [0,1,2], 1000 punten, ADC 0

# maak een (unieke) filenaam aan
filename = 'meting_test1_%s.txt' % (int(time.time()))
write_data.saveArray(data, filename)
 def getValues(self, address, count=1):
     caddress = self.corrected_address(address)
     value = dp.getADC(self._board_address, caddress)
     self.log('read {} from board {} input {}'.format(
         value, self._board_address, caddress))
     return self._pack_float(value)
Example #28
0
	detector = DAQX.getINTflags(0)
	if detector & 0b1:
		counter1 += 1
	if detector & 0b10:
		counter2 += 1

def storecpm(value1, value2):
	f = open("log.dat", 'a')
	f.write(str(time.time()) + ",")
	f.write(str(value1) + ",")
	f.write( str(value2) + "\n")
	f.close()
 
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(22, GPIO.FALLING, callback=counterDET)  
DAQC.enableDINint(0,0,'r')   #enable the push button interrupt
DAQC.enableDINint(0,1,'f')
DAQC.intEnable(0)     #enable global interrupts


checkpoint = time.time()

try:
           	
	if (checkpoint < time.time()):
		print "Counter is ", counter
		storecpm(counter1, counter2)
		counter1 = 0
		counter2 = 0
		checkpoint = time.time() + 60
 def values(self):
     inport = dp.getDINall(self._board_address)
     return [bool((inport >> i) & 1) for i in range(self._pincount)]
Example #30
0
def task():
    global logFile, lfOpen, Logging, streamOpen, fName, SampleC, SampleT, logHeader
    global theta, dnum
    aChannelCount = 0
    dChannelCount = 0
    try:
        SampleT = float(SamplePeriod.get())
        if (SampleT < SampleTmin):
            SampleT = SampleTmin
    except ValueError:
        SampleT = SampleTmin
    root.after(int(SampleT * 1000), task)
    logString = ''
    dTypes = ''
    j = 0
    for i in range(0, 8):  #for boards 0 through 8
        a2dvals = range(8)
        dinvals = range(8)
        if (DAQCpresent[i] == 1):
            #Test Signal Generation
            if (DoutSignal.get() == 1):
                dnum[i] = (dnum[i] + 1) % 128
                DAQC.setDOUTall(i, dnum[i])
            if (AoutSignal.get() == 1):
                theta[i] = (theta[i] + 1) % 360
                rad = math.radians(theta[i])
                dacval = 2.048 * (1 + math.sin(rad))
                dacval2 = 2.048 * (1 + math.sin(2 * rad))
                DAQC.setDAC(i, 0, dacval)
                DAQC.setDAC(i, 1, dacval2)

            #Retrieve and plot  values
            a2dvals = daqc[i].a2dupdate()
            dinvals = daqc[i].dinupdate()

            #Convert data to strings for log
            for k in range(8):
                if (a2dvals[k] != ''):
                    logString = logString + str(a2dvals[k]) + ','
                    aChannelCount += 1
                    dTypes = dTypes + 'a,'
            for k in range(8):
                if (dinvals[k] != ''):
                    logString = logString + str(dinvals[k]) + ','
                    dChannelCount += 1
                    dTypes = dTypes + 'd,'

    dtypes = dTypes[:-1]
    logString = logString[:-1]
    logString = time.strftime("%H:%M:%S", time.localtime()) + ',' + logString
    if (Logging and lfOpen):
        #logString = logString[:-1]
        #logString = time.strftime("%H:%M:%S",time.localtime())+','+logString
        logFile.write(logString)
        logFile.write('\n')

    if (Logging and streamOpen):
        headerList = logHeader.split(",")
        #logString = logString[:-1]
        dataList = logString.split(",")
        typeList = dTypes.split(",")
        #print aChannelCount, dChannelCount, aChannelCount+dChannelCount
        for i in range(0, aChannelCount + dChannelCount):
            k = i + 1
            if (typeList[i] == 'a'):
                streamer.log(headerList[k], float(dataList[k]))
                #print i,typeList[i],headerList[k],float(dataList[k])
            else:
                if (dataList[k] == '0'):
                    streamer.log(headerList[k], "false")
                    #print i,typeList[i],headerList[k], 'false'
                else:
                    streamer.log(headerList[k], "true")
                    #print i,typeList[i],headerList[k], 'true'

    if (Logging):
        SampleC -= 1
        root.wm_title("DAQCplate Data Logger - LOGGING - " + str(SampleC) +
                      " Samples and " + str(SampleT * SampleC) +
                      " Seconds Remaining")
        if (SampleC == 0):
            StopLog()
            try:
                updateSheets()
                StartLog()
                #showinfo("Logging","Logging Complete")
            except:
                shutDown()
Example #31
0

def VersionErr():
    print "For best performance, please install the latest Pi-Plates library."
    print "Do so by executing the following from the command line:"
    print "sudo pip install --upgrade pi-plates"
    response = raw_input("Would you like to upgrade now? (y/n)")
    if (response.lower() == 'y'):
        os.system("sudo pip install --upgrade pi-plates")
        reload(DAQC)
    else:
        sys.exit()


try:
    version = DAQC.getVersion()
    if (version < 1.02):
        VersionErr()
except AttributeError:
    VersionErr()

try:  #check for presence of Intial State module
    imp.find_module('ISStreamer')
    ISSfound = True
    from ISStreamer.Streamer import Streamer
except ImportError:
    ISSfound = False
    print
    print 'Visit https://www.initialstate.com'
    print 'and learn how to stream your data to the cloud.'
    print
 def values(self):
     # getDOUTbyte returns a list with one int in it for some dumbass reason
     outport = dp.getDOUTbyte(self._board_address)[0]
     return [bool((outport >> i) & 1) for i in range(self._pincount)]
Example #33
0
    Parameters:
        empty : float - coltage the sensor gives for empty
        full : float - voltage the sensor gives for full
        channel : int - the daqc channel the sensor is on
    Return:
        checkValue : int - returns the percentage of the voltage
	'''
    voltageInput = 0     #initialize sensorInput
    percent = 200      #initialize percUsed

    #while input is zero - zero means it didn't get a reading
    while voltageInput == 0:
        #try to get a reading
        try:
            #gets the voltage inut from the daqc board
            voltageInput = DAQC.getADC(0, channel)
            #if the voltage is greater than 0 it got a reading.
            if voltageInput > 0:
				#calculates the percentage for water
                if typeSensor == 'W':
                    percent = round(((empty - voltageInput)/(empty-full))*100)
                #calculates the percentage for the battery
				elif typeSensor == 'B':
                    percent = round((voltageInput/5)*100)
            #time.sleep(1)
        #If not voltage was read or it errored
        except:
            print("")
    #checkValue of the percentage bounds and than return it
    return checkValueBounds(percent)