def init(): try: ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1) usb = usbiss.USBISS('/dev/ttyACM0', 'spi', spi_mode=2, freq=500000) alphasense = opc.OPCN2(usb) alphasense.on() time.sleep(10.0) return True except: return False
def init_opc (): print ("initializing OPC reader...") try: spi = usbiss.USBISS("/dev/opc", 'spi', spi_mode = 2, freq = 500000) sleep(2) opc_reader = opc.OPCN2(spi) sleep (2) opc_reader.on () sleep (2) print ("success.") return opc_reader except: print ("Failed to init OPC") return None
time.sleep(5.0) # In connection case get the values of particle sensor and sending by Xbee transceiver # in the opposite case print negative case if (a): with silence(): # Create the saving file if the hardware is ready #Create the saving values and create news each the time change t0 = datetime.datetime.now() Name = "OPCN2_" + str(t0.year) + "_" + str(t0.month) + "_" + str( t0.day) + "_" + str(t0.hour) + "_" + str(t0.minute) + "_" + str( t0.second) + ".txt" FileSave = open(Name, 'w') # Again configure the hardware (global object) ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=1) usb = usbiss.USBISS('/dev/ttyACM0', 'spi', spi_mode=2, freq=500000) alphasense = opc.OPCN2(usb) alphasense.on() time.sleep(10.0) while True: # Contruct the data to send. Use the frame construction and # send using Xbee Hist = alphasense.histogram() Hist['Time'] = str(datetime.datetime.now()) d0 = str(Hist['PM1']) + " " d1 = str(Hist['PM2.5']) + " " d2 = str(Hist['PM10']) + " " d3 = str(Hist['Time']) D = d0 + d1 + d2 + d3 Dat0 = range(0, len(D)) for k in range(0, len(D)):
import usbiss import opc # Get arguments if len(sys.argv) != 2: print('Usage: {} dev-path'.format(sys.argv[0])) sys.exit(1) # Port port = sys.argv[1] # Sample period period = 10 # Open connection to USB-ISS in SPI mode. usb = usbiss.USBISS(port, 'spi', spi_mode=2, freq=500000) # Give the USB connection to py-opc alpha = opc.OPCN2(usb) # Toggle to tur on properly alpha.off() sleep(1) alpha.on() sleep(1) # log data lastUpdated = 0 # data
#Importing necessary packages import usbiss import opc import argparse import sys import os import time import csv import datetime import serial #Initiating the OPCN2 try: time.sleep(5) #Open an SPI connection spi = usbiss.USBISS("/dev/ttyACM0", 'spi', spi_mode = 2, freq = 500000) time.sleep(5) alpha = opc.OPCN2(spi) except Exception as e: print ("Startup Error: {}".format(e)) sys.exit(1) #Turn on the OPC alpha.on() #Wait for ten seconds to allow the sensor to boot up time.sleep(10) #change firmware to correct version alpha.firmware = {'major': 18, 'version': 18.2, 'minor': 2}
import spidev import usbiss import opc import sys from time import sleep #spi = spidev.SpiDev() #spi.open(0, 0) #spi.mode = 1 #spi.max_speed_hz = 500000 spi = usbiss.USBISS("/dev/opc", 'spi', spi_mode=2, freq=500000) sleep(2.0) try: alphasense = opc.OPCN2(spi) except: print("Failed to init OPC N2") sys.exit(1) # Turn the opc ON alphasense.on() sleep(2.0) # Read the information string print(alphasense.read_info_string()) for k in range(5): # Read the histogram sleep(2.0)