def edit_enumeration(nodemap, enum_name): """ Display and allow user to modify the enumeration value. :param nodemap: node map. :param enum_name: name of the enumeration node. """ node = nodemap.get_node(enum_name) if not node.is_writable: return # Cast to PyIEnumeration from PyNode enum_node = st.PyIEnumeration(node) while True: print(enum_name) enum_entries = enum_node.entries for index in range(len(enum_entries)): enum_entry = enum_entries[index] if enum_entry.is_available: print("{0} : {1} {2}".format( index, st.PyIEnumEntry(enum_entry).symbolic_value, "(Current)" if enum_node.value == enum_entry.value else "")) selection = int(input("Select : ")) if selection < len(enum_entries): enum_entry = enum_entries[selection] enum_node.set_int_value(enum_entry.value) break
def set_enumeration(nodemap, enum_name, entry_name): """ Function to set enumeration value. :param nodemap: node map. :param enum_name: name of the enumeration node. :param entry_name: symbolic value of the enumeration entry node. """ enum_node = st.PyIEnumeration(nodemap.get_node(enum_name)) entry_node = st.PyIEnumEntry(enum_node[entry_name]) # Note that depending on your use case, there are three ways to set # the enumeration value: # 1) Assign the integer value of the entry with set_int_value(val) or .value # 2) Assign the symbolic value of the entry with set_symbolic_value("val") # 3) Assign the entry (PyIEnumEntry) with set_entry_value(entry) # Here set_entry_value is used: enum_node.set_entry_value(entry_node)
def display_nodes(node): """ Function to display node :param node: node to display """ if not node.is_implemented: return # Display the interface type and name print("{0} : {1}".format(node.principal_interface_type.name, node.name)) if node.principal_interface_type == st.EGCInterfaceType.ICategory: # Display all the features that belong to the category feature_list = st.PyICategory(node).feature_list for feature in feature_list: display_nodes(feature) elif node.principal_interface_type == st.EGCInterfaceType.IEnumeration: # Display all entries if the type is Enumeration entry_list = st.PyIEnumeration(node).entries for entry in entry_list: display_nodes(entry)
def edit_enum_setting(nodemap, enum_name, numeric_name): """ Display the contents of the current enumeration node and edit settings. :param nodemap: Node map. :param enum_name: Enumeration name. :param numeric_name: Numeric name. """ node = nodemap.get_node(enum_name) if not node.is_writable: return enum_node = st.PyIEnumeration(node) enum_entries = enum_node.entries for index in range(len(enum_entries)): enum_entry = enum_entries[index] if enum_entry.is_available: enum_node.value = enum_entry.value print("{0} = {1}".format( enum_name, st.PyIEnumEntry(enum_entry).symbolic_value)) edit_setting(nodemap, numeric_name)
st_device = st_system.create_first_device() print('Device=', st_device.info.display_name) # ============================================================ # Demostration of set digital Gain to 2 times. # Acquire NodeMap for accessing camera parameter nodemap_remote = st_device.remote_port.nodemap # Switch off gain auto. # If Gain auto is on, gain value cannot be set gain_auto = nodemap_remote.get_node("GainAuto") # Convert to IEnum type for operating enum_gain_auto = st.PyIEnumeration(gain_auto) # Set Gain Auto to Off enum_gain_auto.from_string("Off") # For setting analog gain, gain selector need to be set to Digital to access analog gain. gain_selector = nodemap_remote.get_node("GainSelector") # Convert to IEnum type for operating enum_gain_selector = st.PyIEnumeration(gain_selector) # Set selector to DigitalAll to control analog gain enum_gain_selector.from_string("DigitalAll") # Get Node for Gain gain_node = nodemap_remote.get_node("Gain") # Set digital gain to 2 times(128). gain_node.value = 128
st_device = st_system.create_first_device() print('Device=', st_device.info.display_name) # ============================================================ # Demostration of changing white balance to manual with setting all balance ratio to 10 # Acquire NodeMap for accessing camera parameter nodemap_remote = st_device.remote_port.nodemap # Switch BalanceWhiteAuto to Preset0 for manual input value # Acquire Node for BalanceWhiteAuto balance_auto = nodemap_remote.get_node("BalanceWhiteAuto") # Convert to IEnum type for operating enum_balance_auto = st.PyIEnumeration(balance_auto) # Set BalanceWhiteAuto to Preset0 enum_balance_auto.from_string("Preset0") # Switch balance ration selector to Red for access Red ratio value # Acquire Node for BalanceRatioSelector balance_ratio_selector = nodemap_remote.get_node("BalanceRatioSelector") # Convert to IEnum type for operating enum_balance_ratio_selector = st.PyIEnumeration(balance_ratio_selector) # Switch to Red for Red ratio handling enum_balance_ratio_selector.from_string("Red") # Get Node for value of BalanceRatio balance_ratio = nodemap_remote.get_node("BalanceRatio") # Convert to IFloat type for operating float_balance_ratio = st.PyIFloat(balance_ratio)
st_system = st.create_system() st_device = st_system.create_first_device() print('Device=', st_device.info.display_name) # ============================================================ # Demostration of PixelFormat change. # Acquire NodeMap for accessing camera parameter nodemap_remote = st_device.remote_port.nodemap # Set Pixel Format to Mono8. pixel_format = nodemap_remote.get_node("PixelFormat") enum_pixel_format = st.PyIEnumeration(pixel_format) enum_pixel_format.from_string("Mono8") # ============================================================ st_datastream = st_device.create_datastream() st_datastream.start_acquisition(number_of_images_to_grab) st_device.acquisition_start() while st_datastream.is_grabbing: with st_datastream.retrieve_buffer() as st_buffer: if st_buffer.info.is_image_present: st_image = st_buffer.get_image() print("BlockID={0} Size={1} x {2} First Byte={3}".format(
st_system = st.create_system() st_device = st_system.create_first_device() print('Device=', st_device.info.display_name) # ============================================================ # Demostration of Setting Auto Shutter with dedicated range. # Acquire NodeMap for accessing camera parameter nodemap_remote = st_device.remote_port.nodemap # Switch Exposure Mode to Timed exposure_mode = nodemap_remote.get_node("ExposureMode") # Convert to IEnum type for operating enum_exposure_mode = st.PyIEnumeration(exposure_mode) # Set Exposure Mode to Timed enum_exposure_mode.from_string("Timed") # Switch on Exposure Auto. exposure_auto = nodemap_remote.get_node("ExposureAuto") # Convert to IEnum type for operating enum_exposure_auto = st.PyIEnumeration(exposure_auto) # Set Exposure Auto to Continuous enum_exposure_auto.from_string("Continuous") # Get Node for Auto Luminance Target alc_tgt = nodemap_remote.get_node("AutoLuminanceTarget") # Set Auto Luminance Target to 128 alc_tgt.value = 128
st_system = st.create_system() st_device = st_system.create_first_device() print('Device=', st_device.info.display_name) # ============================================================ # Demostration of Setting Line1 as Exposure Active # Acquire NodeMap for accessing camera parameter nodemap_remote = st_device.remote_port.nodemap # Set Line1 to output line_selector = nodemap_remote.get_node("LineSelector") enum_line_selector = st.PyIEnumeration(line_selector) enum_line_selector.from_string("Line1") line_mode = nodemap_remote.get_node("LineMode") enum_line_mode = st.PyIEnumeration(line_mode) enum_line_mode.from_string("Output") # Set LineSource to Exposure Active line_source = nodemap_remote.get_node("LineSource") enum_line_source = st.PyIEnumeration(line_source) enum_line_source.from_string("ExposureActive") # ============================================================ st_datastream = st_device.create_datastream()
st_system = st.create_system() st_device = st_system.create_first_device() print('Device=', st_device.info.display_name) # ============================================================ # Demostration of set analog Gain to 2dB. # Acquire NodeMap for accessing camera parameter nodemap_remote = st_device.remote_port.nodemap # Set Line0 to input line_selector = nodemap_remote.get_node("LineSelector") enum_line_selector = st.PyIEnumeration(line_selector) enum_line_selector.from_string("Line0") line_mode = nodemap_remote.get_node("LineMode") enum_line_mode = st.PyIEnumeration(line_mode) enum_line_mode.from_string("Input") # Switch on Trigger Mode(IEnumeration). trigger_mode = nodemap_remote.get_node("TriggerMode") enum_trigger_mode = st.PyIEnumeration(trigger_mode) enum_trigger_mode.from_string("On") # Set Trigger Source to Line0 as Hardware input trigger_source = nodemap_remote.get_node("TriggerSource") enum_trigger_source = st.PyIEnumeration(trigger_source) enum_trigger_source.from_string("Line0")
def do_grabbing(st_device): """Perform grabbing using the given st_device. """ # Display DisplayName of the device. print('Device=', st_device.info.display_name) # Get host side device setting (nodemap) st_nodemap = st_device.local_port.nodemap # Get EventDeviceLost node st_event_node = st_nodemap.get_node(CALLBACK_NODE_NAME) # Register callback for EventDeviceLost # To ensure the device lost flag is already updated when fired, here we # use OutsideLock flag (executed on leaving outside the lock-guarded # GenApi node. st_event_node.register_callback(node_callback, st_device, st.EGCCallbackType.OutsideLock) # Enable the transmission of the target event st_event_selector = st.PyIEnumeration(st_nodemap.get_node(EVENT_SELECTOR)) st_event_selector.set_symbolic_value(TARGET_EVENT_NAME) st_event_notification = \ st.PyIEnumeration(st_nodemap.get_node(EVENT_NOTIFICATION)) st_event_notification.set_symbolic_value(EVENT_NOTIFICATION_ON) # Start event handling thread st_device.start_event_acquisition() # Create a datastream object for handling image stream data. st_datastream = st_device.create_datastream() # Start the image acquisition of the host (local machine) side. st_datastream.start_acquisition() # Start the image acquisition of the camera side. st_device.acquisition_start() # A while loop for acquiring data and checking status while st_datastream.is_grabbing: # Create a localized variable st_buffer using 'with' # Warning: if st_buffer is in a global scope, st_buffer must be # cleared to None to allow Garbage Collector release the buffer # properly. with st_datastream.retrieve_buffer(5000) as st_buffer: # Check if the acquired data contains image data. if st_buffer.info.is_image_present: # Create an image object. st_image = st_buffer.get_image() # Display the information of the acquired image data. print("BlockID={0} Size={1} x {2} First Byte={3} " "(Unplug the camera to trigger device lost).".format( st_buffer.info.frame_id, st_image.width, st_image.height, st_image.get_image_data()[0])) else: # If the acquired data contains no image data. print("Image data does not exist.") # Stop the image acquisition of the camera side st_device.acquisition_stop() # Stop the image acquisition of the host side st_datastream.stop_acquisition() # Stop event acquisition thread st_device.stop_event_acquisition()