I have a client who is using the COM320 to call out lake level alarms. He now wants to be able to set a new alarm level over the phone. I was just wondering if anyone had some code examples of this.
Thanks,
Dave
To set a new alarm level over the phone using the COM320, you can typically implement a system that listens for DTMF tones (the tones generated when pressing keys on a phone) and then processes those inputs to set the alarm level. Below is a basic example of how you might structure the code:
import serial # Initialize serial communication with the COM320 ser = serial.Serial('COM_PORT', baudrate=9600, timeout=1) def set_alarm_level(new_level): command = f'SET_ALARM_LEVEL {new_level}\n' ser.write(command.encode()) def listen_for_dtmf(): while True: if ser.in_waiting > 0: dtmf_input = ser.read(1) # Read one byte (DTMF tone) process_input(dtmf_input) def process_input(dtmf_input): try: level = int(dtmf_input.decode()) if 0 <= level <= 100: # Assuming alarm levels are between 0 and 100 set_alarm_level(level) print(f'Alarm level set to: {level}') else: print('Invalid level. Please enter a number between 0 and 100.') except ValueError: print('Invalid input. Please enter a numeric value.') if __name__ == "__main__": listen_for_dtmf()Fnaf