PYTEST FLAGS ------------ --testdox -- display test output in testdox format -v -- verbose (show each test name, otherwise just . for passing tests) -q -- quiet (. for passing test, then a one-line summary) --color yes -- print in color (green for passing, red for failing) """ # Unit test framework import unittest # Chromation spectrometer API from microspeclib.simple import MicroSpecSimpleInterface # Open communication. Communication closes when this script finishes. kit = MicroSpecSimpleInterface() # ------------- # | Constants | # ------------- # status OK = 0 ERROR = 1 # led_setting OFF = 0 GREEN = 1 RED = 2 # Spectrometer photodiode array config
"-------------------------------------------\n") print(f"Pixel {start_pixel} is {chr_map[start_pixel]}nm") print(f"Pixel {stop_pixel} is {chr_map[stop_pixel]}nm") # Index the frame data for logging to file under a heading of # wavelengths # Create the heading of wavelengths data = ",".join([str(w) for w in wav]) + "\n" with open('datalog.txt', "w", encoding="utf-8") as df: df.write(data) # Grab three frames and append each to the file # # Open communication kit = MicroSpecSimpleInterface() # Datalog with open('datalog.txt', "a", encoding="utf-8") as df: num_frames = 3 for i in range(num_frames): reply = kit.captureFrame() frame = dict( zip( range(1, reply.num_pixels + 1), # <- pixel number 1:N reply.pixels) # <---------------- counts ) # Extract ONLY the data in the wavelength range # and join each counts value with commas data = ",".join([ str(frame[pixel])
if "-i" in sys.argv or "--ignore" in sys.argv: parser.add_argument("-i", "--ignore", help="Ignore argument") # hidden argument for internal use args = parser.parse_args() from microspeclib.internal.stream import MicroSpecEmulatedStream from microspeclib.logger import debug if args.debug or args.verbose: debug(args.debug>0) timeout = args.timeout si = None if args.emulator: log.info("Starting emulation process...") hardware = MicroSpecEmulatedStream(socat=True, fork=True, timeout=0.1) software = MicroSpecSimpleInterface(device=hardware.software, timeout=timeout) log.info("Connecting to emulation") si = software elif args.file: log.info("Connecting to device '%s'", args.file) si = MicroSpecSimpleInterface(device=args.file, timeout=timeout) else: log.info("Connecting to default hardware") si = MicroSpecSimpleInterface(timeout=timeout) try: getcmd = get_command(args.command) command = getcmd[0].lower() + getcmd[1:] except: log.critical("Command '%s' not found!\n%s", args.command, command_help_string()) sys.exit(1)
def setUpClass(cls): super().setUpClass() cls.hardware = None if not hasattr(cls, "software"): cls.software = MicroSpecSimpleInterface(timeout=0.1)
#!/usr/bin/env python # Copyright 2020 by Chromation, Inc # All Rights Reserved by Chromation, Inc if __name__ == "__main__": from microspeclib.simple import MicroSpecSimpleInterface from microspeclib.datatypes import * si = MicroSpecSimpleInterface(timeout=0.1) #si = MicroSpecSimpleInterface(timeout=0.1, device="COM3") #si = MicroSpecSimpleInterface(timeout=0.1, device="/dev/cu.usbserial-CHROMATION09310") #si = MicroSpecSimpleInterface(timeout=0.1, emulation=True) print(si.setBridgeLED(led_num=0, led_setting=LEDOff)) print(si.setSensorLED(led_num=0, led_setting=LEDGreen)) print(si.setSensorLED(led_num=1, led_setting=LEDRed)) print(si.getBridgeLED(led_num=0)) print(si.getSensorLED(led_num=0)) reply = si.getSensorLED(led_num=1) print(reply.status) print(reply.led_setting) print(si.setSensorConfig(binning=True, gain=Gain1x, row_bitmap=0x1F)) print(si.setExposure(cycles=100)) import time for i in range(0, 5): reply = si.captureFrame() print(reply.status) print(reply.num_pixels)
# for all other commands, show the reply in a table else: print(f"{'Variable':>19} |{'Value':>8} | {'Number of bytes'}") print(f"{'--------':>19} |{'-----':>8} | {'---------------'}") # ----------response[0] is variable name # | --response[1] is variable size in bytes # | | # v v # example response: (status, 1) for response in zip(reply.variables, reply.sizes): print(f"{response[0]:>19} |" # Variable f"{getattr(reply, response[0]):>8} | " # Value f"{response[1]}") # Number of bytes def report(reply): _print_the_command_sent(reply) _print_the_reply_received(reply) if __name__ == '__main__': from microspeclib.simple import MicroSpecSimpleInterface kit = MicroSpecSimpleInterface(timeout=2.0) print(f"\nOpened kit: {kit.serial.serial_number}...") # Send the command and get the reply. reply = kit.getSensorConfig() # <----- TRY COMMAND HERE report(reply) print(f"\n...Closed kit: {kit.serial.serial_number}")
def setUpClass(cls): super().setUpClass() cls.software = MicroSpecSimpleInterface(emulation=True, timeout=1)
def main(): '''A few examples using the microspec API. Usage ----- Execute this function at the command line with command "microspec-api-example": $ microspec-api-example Entry Point ----------- The name of this function must match the attribute in `setup.py` `setuptools.setup()` argument `entry_points`. ''' from microspeclib.simple import MicroSpecSimpleInterface from microspeclib.datatypes import LEDOff, LEDGreen, LEDRed, Gain1x si = MicroSpecSimpleInterface(timeout=0.1) #si = MicroSpecSimpleInterface(timeout=0.1, device="COM3") #si = MicroSpecSimpleInterface(timeout=0.1, device="/dev/cu.usbserial-CHROMATION09310") #si = MicroSpecSimpleInterface(timeout=0.1, emulation=True) print(si.setBridgeLED(led_num=0, led_setting=LEDOff)) print(si.setSensorLED(led_num=0, led_setting=LEDGreen)) print(si.setSensorLED(led_num=1, led_setting=LEDRed)) print(si.getBridgeLED(led_num=0)) print(si.getSensorLED(led_num=0)) reply = si.getSensorLED(led_num=1) print(reply.status) print(reply.led_setting) print(si.setSensorConfig(binning=True, gain=Gain1x, row_bitmap=0x1F)) print(si.setExposure(cycles=100)) import time for i in range(0, 5): reply = si.captureFrame() print(reply.status) print(reply.num_pixels) pixels = [str(pixel) for pixel in reply.pixels] print("first 3 pixels: %s" % (",".join(pixels[:3]))) time.sleep(0.5)