def select_channel_range(global_data: Dict[str, Any], channel: int) -> None: """Select DAC channel output range, voltage or current output. Args: global_data: Dictionary with global variables channel: Channel number Returns: None """ if '1' not in global_data["BOARDS"]: print(Fore.RED + "No analog output board available at MODBUS address", Fore.CYAN + str(global_data["MODBUS_ADDRESS"])) else: print(Fore.CYAN + "Select channel range:") labels = [ '0V to 5V', '0V to 10V', '-5V to 5V', '-10V to 10V', '4mA to 20mA', '0mA to 20mA', '0mA to 24mA' ] for index, _ in enumerate(labels): print(Fore.YELLOW + '\t' + str(index) + ' for ' + labels[index]) cs_addr, reg_val = request_dac_reconfig_data(global_data) utilities.write_output_holding_reg( global_data, [global_data["MODBUS_ADDRESS"], cs_addr, channel - 1], reg_val)
def write_voltage(global_data: Dict[str, Any], channel_address: List[int], channel_value: float, output_range: int) -> None: """Write voltage channel. Args: global_data: Dictionary with global variables channel_address: List of MODBUS address, CS and channel number channel_value: Channel voltage value output_range: Voltage range Returns: None """ channel_address[2] += 3 if output_range == 0: dac_code = int((channel_value / 5.0) * 2**16) elif output_range == 1: dac_code = int((channel_value / 10.0) * 2**16) elif output_range == 2: dac_code = int(((channel_value + 5.0) / 10.0) * 2**16) elif output_range == 3: dac_code = int(((channel_value + 10.0) / 20.0) * 2**16) else: pass utilities.write_output_holding_reg(global_data, channel_address, dac_code)
def set_adc_postfilter(global_data: Dict[str, Any]) -> None: """Set ADC postfilter. Args: global_data: Dictionary with global variables Returns: None """ if '0' not in global_data["BOARDS"]: print(Fore.LIGHTMAGENTA_EX + "No analog input board available at", Fore.CYAN + "MODBUS address", Fore.CYAN + str(global_data["MODBUS_ADDRESS"])) else: print(Fore.CYAN + "Set ADC postfilter:") labels = [ '27 SPS, 47 dB rejection, 36.7 ms settling', '25 SPS, 62 dB rejection, 40 ms settling', '20 SPS, 86 dB rejection, 50 ms settling', '16.67 SPS, 92 dB rejection, 60 ms settling', 'disable postfilter' ] for index, _ in enumerate(labels): print(Fore.YELLOW + '\t' + str(index) + ' for ' + labels[index]) cs_addr, reg_val = utilities.request_reconfig_data(global_data) utilities.write_output_holding_reg( global_data, [global_data["MODBUS_ADDRESS"], cs_addr, 2], reg_val)
def set_adc_output_data_rate(global_data: Dict[str, Any]) -> None: """Set ADC output data rate. Args: global_data: Dictionary with global variables Returns: None """ if '0' not in global_data["BOARDS"]: print(Fore.LIGHTMAGENTA_EX + "No analog input board available at", Fore.CYAN + "MODBUS address", Fore.CYAN + str(global_data["MODBUS_ADDRESS"])) else: print(Fore.CYAN + "Set ADC output data rate:") labels = [ '31250 SPS', '31250 SPS', '31250 SPS', '31250 SPS', '31250 SPS', '31250 SPS', '15625 SPS', '10417 SPS', '5208 SPS', '2597 SPS', '1007 SPS', '503.8 SPS', '381 SPS', '200.3 SPS', '100.5 SPS', '59.52 SPS', '49.68 SPS', '20.01 SPS', '16.63 SPS', '10 SPS', '5 SPS', '2.5 SPS', '1.25 SPS' ] for index, _ in enumerate(labels): print(Fore.YELLOW + '\t' + str(index) + ' for ' + labels[index]) cs_addr, reg_val = utilities.request_reconfig_data(global_data) utilities.write_output_holding_reg( global_data, [global_data["MODBUS_ADDRESS"], cs_addr, 3], reg_val)
def send_hart_command_0(global_data: Dict[str, Any]) -> None: """Send HART command 0. Args: global_data: Dictionary with global variables Returns: None """ if '0' not in global_data["BOARDS"]: print(Fore.CYAN + "No analog input board available at", Fore.CYAN + "MODBUS address", Fore.CYAN + str(global_data["MODBUS_ADDRESS"])) else: print(Fore.CYAN + "Send HART command zero:") print(Fore.YELLOW + '\t' + '1 to send HART command 0') cs_addr, reg_val = utilities.request_reconfig_data(global_data) utilities.write_output_holding_reg( global_data, [global_data["MODBUS_ADDRESS"], cs_addr, 5], reg_val) if reg_val == 1: sleep(2) registers = read_analog_input_regs_cn0414( global_data, [global_data["MODBUS_ADDRESS"], cs_addr, 25], 30) response = '' for index, _ in enumerate(registers): response += str(hex(registers[index]).upper()[2:]) + " " print(Fore.GREEN + "DEVICE RESPONSE: " + Fore.YELLOW + response)
def send_hart_command_0(global_data: Dict[str, Any]) -> None: """Send HART command 0. Args: global_data: Dictionary with global variables Returns: None """ if '1' not in global_data["BOARDS"]: print(Fore.CYAN + "No analog output board available at", Fore.CYAN + "MODBUS address", Fore.CYAN + str(global_data["MODBUS_ADDRESS"])) else: print(Fore.CYAN + "Send HART command zero:") print(Fore.YELLOW + '\t' + '1 to send HART command 0') cs_addr, reg_val = utilities.request_reconfig_data(global_data) utilities.write_output_holding_reg( global_data, [global_data["MODBUS_ADDRESS"], cs_addr, 5], reg_val)
def select_hart_channel(global_data: Dict[str, Any]) -> None: """Select HART channel. Args: global_data: Dictionary with global variables Returns: None """ if '1' not in global_data["BOARDS"]: print(Fore.CYAN + "No analog output board available at", Fore.CYAN + "MODBUS address", Fore.CYAN + str(global_data["MODBUS_ADDRESS"])) else: print(Fore.CYAN + "Select HART channel:") labels = ['Channel 1', 'Channel 2', 'Channel 3', 'Channel 4'] for index, _ in enumerate(labels): print(Fore.YELLOW + '\t' + str(index) + ' for ' + labels[index]) cs_addr, reg_val = utilities.request_reconfig_data(global_data) utilities.write_output_holding_reg( global_data, [global_data["MODBUS_ADDRESS"], cs_addr, 6], reg_val)
def set_adc_output_code(global_data: Dict[str, Any]) -> None: """Set ADC output data coding. Args: global_data: Dictionary with global variables Returns: None """ if '0' not in global_data["BOARDS"]: print(Fore.LIGHTMAGENTA_EX + "No analog input board available at", Fore.CYAN + "MODBUS address", Fore.CYAN + str(global_data["MODBUS_ADDRESS"])) else: print(Fore.CYAN + "Set ADC output code:") labels = ['bipolar coding', 'unipolar coding'] for index, _ in enumerate(labels): print(Fore.YELLOW + '\t' + str(index) + ' for ' + labels[index]) cs_addr, reg_val = utilities.request_reconfig_data(global_data) utilities.write_output_holding_reg( global_data, [global_data["MODBUS_ADDRESS"], cs_addr, 0], reg_val)
def write_current(global_data: Dict[str, Any], channel_address: List[int], channel_value: float, output_range: int) -> None: """Write current channel. Args: global_data: Dictionary with global variables channel_address: List of MODBUS address, CS and channel number channel_value: Channel current value output_range: Current range Returns: None """ channel_address[2] += 3 if output_range == 0: dac_code = int(((channel_value - 4) / 16) * 2**16) elif output_range == 1: dac_code = int((channel_value / 20) * 2**16) elif output_range == 2: dac_code = int((channel_value / 24) * 2**16) else: pass utilities.write_output_holding_reg(global_data, channel_address, dac_code)