#!/usr/bin/python # NAME # GetCameraParameters - a module for getting the Dalsa 1M60 parameters # # PACKAGE # Part of the Dalsa1M60 python package # # SYNOPSIS # GetCameraParameters( serial_cmd_location ) # - serial_cmd_location: the location of the file serial_cmd that access the menu of the camera # # EXPLANATION # The serial command 'gcp' is sent to the Dalsa 1M60 - it typically respsonds with # # # G E N E R A L C A M E R A S E T T I N G S: # # Camera Model No.: DS-22-01M60-11E # Camera Serial No.: 04437062 # Sensor Serial No.: 0411218 # # Tap 1 Gain: 0 # Tap 2 Gain: 0 # # Firmware Design Rev.: 03-81-00070-03 Sep 30 2004 # DSP Design Rev.: 17.3 # # Pretrigger: 0 # Video Mode: Test Pattern Left Side # Data Mode: 12 bit # Binning Mode: 1x1 # # Gain Mode: 1x Output Gain Mode # Output Configuration: 2 Tap # Exposure Control: enabled # Exposure Mode: 4 # # SYNC Frequency: in an external trigger mode # Exposure Time: external # # OK> # # # # Written by Aidan Brooks. 5th May 2010 import subprocess def GetCameraParameters( serial_cmd_location ): # set the default values modelNoSTR = 'DS-22-01M60-11E' serialNoSTR = '04437062' sensorNoSTR = '0411218' tap1Gain = 0 tap2Gain = 0 firmwareSTR = '03-81-00070-03 Sep 30 2004' DSPDesignSTR = '17.3' videoModeSTR = 'Normal Operating Mode' pretrigger = 0 dataMode = 12 binningMode = 1 gainMode = 1 outputConfig = 2 exposureMode = 2 exposureControlSTR = 'enabled' syncFrequencySTR = '58 Hz' syncFrequency = 58 exposureTimeSTR = '16000.0 uSec' exposureTime = 16000.0 serialCommunicationsStatus = 1 # run the subprocess to execute the 'serial_cmd gcp' command process = subprocess.Popen(serial_cmd_location + ' gcp', shell=True, stdout = subprocess.PIPE) # get the response serial_cmd_response = process.communicate() parameters_string = serial_cmd_response[0] command_errors = serial_cmd_response[1] # if there are no errors then start to extract the data if (command_errors == None): # 1. CAMERA MODEL NO. # Locate the substring that corresponds to Camera Model No: substring = 'Camera Model No.:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the next newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc modelNoSTR = parameters_string[startval:endval] modelNoSTR = modelNoSTR.lstrip() # remove all the leading white spaces from the string else: serialCommunicationsStatus = 0 # 2. CAMERA SERIAL NO. # Locate the substring that corresponds to Camera Serial No: substring = 'Camera Serial No.:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the next newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc serialNoSTR = parameters_string[startval:endval] serialNoSTR = serialNoSTR.lstrip() # remove all the leading white spaces from the string else: serialCommunicationsStatus = 0 # 3. SENSOR SERIAL NO. # Locate the substring that corresponds to Sensor Serial No: substring = 'Sensor Serial No.:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the next newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc sensorNoSTR = parameters_string[startval:endval] sensorNoSTR = sensorNoSTR.lstrip() # remove all the leading white spaces from the string else: serialCommunicationsStatus = 0 # 4. TAP 1 GAIN # Locate the substring that corresponds to Tap 1 Gain: substring = 'Tap 1 Gain:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the next newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc tap1GainSTR = parameters_string[startval:endval] tap1GainSTR = tap1GainSTR.lstrip() # remove all the leading white spaces from the string try: tap1Gain = int(tap1GainSTR) finally: pass else: serialCommunicationsStatus = 0 # 5. TAP 2 GAIN # Locate the substring that corresponds to Tap 2 Gain: substring = 'Tap 2 Gain:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the next newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc tap2GainSTR = parameters_string[startval:endval] tap2GainSTR = tap2GainSTR.lstrip() # remove all the leading white spaces from the string try: tap2Gain = int(tap2GainSTR) finally: pass else: serialCommunicationsStatus = 0 # 6. FIRMWARE DESIGN REV.: # Locate the substring that corresponds to Firmware Design Rev.: substring = 'Firmware Design Rev.:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the next newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc firmwareSTR = parameters_string[startval:endval] firmwareSTR = firmwareSTR.lstrip() # remove all the leading white spaces from the string else: serialCommunicationsStatus = 0 # 7. DSP DESIGN REV.: # Locate the substring that corresponds to DSP Design Rev.: substring = 'DSP Design Rev.:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the next newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc DSPDesignSTR = parameters_string[startval:endval] DSPDesignSTR = DSPDesignSTR.lstrip() # remove all the leading white spaces from the string else: serialCommunicationsStatus = 0 # 8. PRETRIGGER # Locate the substring that corresponds to Pretrigger: substring = 'Pretrigger:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the next newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc pretriggerSTR = parameters_string[startval:endval] pretriggerSTR = pretriggerSTR.lstrip() # remove all the leading white spaces from the string try: pretrigger = int(pretriggerSTR) finally: pass else: serialCommunicationsStatus = 0 # 9. VIDEO MODE: *** This is shown as a string but there is a number as well # Locate the substring that corresponds to Video Mode: substring = 'Video Mode:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the next newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc videoModeSTR = parameters_string[startval:endval] videoModeSTR = videoModeSTR.lstrip() # remove all the leading white spaces from the string else: serialCommunicationsStatus = 0 # 10. DATA MODE # Locate the substring that corresponds to Data Mode: substring = 'Data Mode:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('bit', ssloc) # locate the suffix 'bit' after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc dataModeSTR = parameters_string[startval:endval] dataModeSTR = dataModeSTR.lstrip() # remove all the leading white spaces from the string try: dataMode = int(dataModeSTR) finally: pass else: serialCommunicationsStatus = 0 # 11. BINNING MODE # Locate the substring that corresponds to Binning Mode: substring = 'Binning Mode:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('x', ssloc) # locate the suffix 'x' after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc binningModeSTR = parameters_string[startval:endval] binningModeSTR = binningModeSTR.lstrip() # remove all the leading white spaces from the string try: binningMode = int(binningModeSTR) finally: pass else: serialCommunicationsStatus = 0 # 12. GAIN MODE # Locate the substring that corresponds to Gain Mode: substring = 'Gain Mode:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('x', ssloc) # locate the suffix 'x' after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc gainModeSTR = parameters_string[startval:endval] gainModeSTR = gainModeSTR.lstrip() # remove all the leading white spaces from the string try: gainMode = int(gainModeSTR) finally: pass else: serialCommunicationsStatus = 0 # 13. OUTPUT CONFIGURATION # Locate the substring that corresponds to Output Configuration: substring = 'Output Configuration:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('Tap', ssloc) # locate the suffix 'Tap' after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc outputConfigSTR = parameters_string[startval:endval] outputConfigSTR = outputConfigSTR.lstrip() # remove all the leading white spaces from the string try: outputConfig = int(outputConfigSTR) finally: pass else: serialCommunicationsStatus = 0 # 14. EXPOSURE CONTROL: *** This is shown as a string but there is a number as well # Locate the substring that corresponds to Exposure Control: substring = 'Exposure Control:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the next newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc exposureControlSTR = parameters_string[startval:endval] exposureControlSTR = exposureControlSTR.lstrip() # remove all the leading white spaces from the string else: serialCommunicationsStatus = 0 # 15. EXPOSURE MODE # Locate the substring that corresponds to Exposure Mode: substring = 'Exposure Mode:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc exposureModeSTR = parameters_string[startval:endval] exposureModeSTR = exposureModeSTR.lstrip() # remove all the leading white spaces from the string try: exposureMode = int(exposureModeSTR) finally: pass else: serialCommunicationsStatus = 0 # 16. SYNC FREQUENCY # Locate the substring that corresponds to SYNC Frequency: substring = 'SYNC Frequency:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc syncFrequencySTR = parameters_string[startval:endval] syncFrequencySTR = syncFrequencySTR.lstrip() # remove all the leading white spaces from the string try: nwloc = syncFrequencySTR.find('Hz') # if it is in exposure mode 2 (or 7?) then this will be a freq. if (nwloc > 0): syncFrequency = int(syncFrequencySTR[0:nwloc]) finally: pass else: serialCommunicationsStatus = 0 # 17. EXPOSURE TIME # Locate the substring that corresponds to Exposure Time: substring = 'Exposure Time:' ssloc = parameters_string.find(substring) nwloc = parameters_string.find('\n', ssloc) # locate the newline character after the substring # if the string exists then extract the data if ((nwloc > 0) and (ssloc > 0)): startval = ssloc + len(substring) endval = nwloc exposureTimeSTR = parameters_string[startval:endval] exposureTimeSTR = exposureTimeSTR.lstrip() # remove all the leading white spaces from the string try: nwloc = exposureTimeSTR.find('uSec') # if it is in exposure mode 2 (or 7?) then this will be a time if (nwloc > 0): exposureTime = float(exposureTimeSTR[0:nwloc]) finally: pass else: serialCommunicationsStatus = 0 # define the output dictionary that holds the camera parameters cameraParameters = {'modelNoSTR': modelNoSTR, \ 'serialNoSTR': serialNoSTR, \ 'sensorNoSTR': sensorNoSTR, \ 'tap1Gain': tap1Gain, \ 'tap2Gain': tap2Gain, \ 'firmwareSTR': firmwareSTR, \ 'DSPDesignSTR': DSPDesignSTR, \ 'videoModeSTR': videoModeSTR, \ 'pretrigger': pretrigger, \ 'dataMode': dataMode, \ 'binningMode': binningMode, \ 'gainMode': gainMode, \ 'outputConfig': outputConfig, \ 'exposureMode': exposureMode, \ 'exposureControlSTR': exposureControlSTR, \ 'syncFrequencySTR': syncFrequencySTR, \ 'syncFrequency': syncFrequency, \ 'exposureTimeSTR': exposureTimeSTR, \ 'exposureTime': exposureTime, \ 'serialCommunicationsStatus': serialCommunicationsStatus}; return(cameraParameters)