Does the TRM240 support receiving voice calls

I am getting an incoming call but no audio. Is this compatible.

import serial
import time

class GSMModem:
def init(self, port=‘COM19’, baudrate=9600, timeout=1):
self.ser = serial.Serial(port, baudrate, timeout=timeout)
if self.ser.isOpen():
print(f"Connected to {port}“)
else:
print(f"Failed to connect to {port}”)

def send_command(self, command, wait_for_response=True):
    self.ser.write((command + "\r").encode())
    time.sleep(0.5)
    if wait_for_response:
        response = self.ser.read(self.ser.inWaiting()).decode().strip()
        print(f"Command: {command}\nResponse: {response}")  # Print the command and response for debugging
        return response
    return None

def check_modem(self):
    response = self.send_command('AT')
    if "OK" in response:
        print("Modem is active and responding.")
    else:
        print("Modem not responding.")

def configure_audio(self):
    print("Configuring audio settings...")

    # Set Audio Mode
    response = self.send_command('AT+QAUDMOD=0')
    if "ERROR" in response:
        print("Error: Failed to set audio mode.")
    else:
        print("Audio mode set successfully.")

    # Set Uplink (MIC) Gain
    response = self.send_command('AT+QMIC=0,15')
    if "ERROR" in response:
        print("Error: Failed to set microphone gain.")
    else:
        print("Microphone gain set successfully.")

    # Enable Echo Cancellation
    response = self.send_command('AT+QEEC=1,1')
    if "ERROR" in response:
        print("Error: Failed to enable echo cancellation.")
    else:
        print("Echo cancellation enabled successfully.")

def monitor_incoming(self):
    self.send_command('AT+CMGF=1')  # Set SMS to text mode
    self.send_command('AT+CNMI=2,1,0,0,0')  # Configure to receive new message indications
    print("Monitoring incoming SMS and calls... Press Ctrl+C to stop.")
    
    try:
        while True:
            if self.ser.inWaiting():
                response = self.ser.read(self.ser.inWaiting()).decode().strip()
                if "+CMTI:" in response:
                    print("\nNew SMS received:")
                    self.print_latest_sms()
                elif "RING" in response:
                    print("\nIncoming call detected.")
                    self.answer_call()
            time.sleep(1)
    except KeyboardInterrupt:
        print("Stopped monitoring.")

def print_latest_sms(self):
    self.send_command('AT+CMGF=1')  # Set SMS to text mode
    response = self.send_command('AT+CMGL="REC UNREAD"')
    
    if response and "+CMGL:" in response:
        messages = response.split('+CMGL:')
        for message in messages[1:]:
            parts = message.split(',')
            if len(parts) >= 5:
                sender = parts[2].replace('"', '').strip()
                message_body = message.split('\r\n', 1)[1].strip()
                print(f"Sender: {sender}")
                print(f"Message: {message_body}\n")
    else:
        print("No unread messages found.")

def answer_call(self):
    print("Answering call...")
    
    # Configure audio before answering
    self.configure_audio()

    # Add a short delay before answering
    time.sleep(1)  # 1-second delay

    # Answer the call
    response = self.send_command('ATA')
    if "OK" in response:
        print("Call answered. You can now speak using the modem's microphone.")
        try:
            while True:
                if self.ser.inWaiting():
                    response = self.ser.read(self.ser.inWaiting()).decode().strip()
                    if "NO CARRIER" in response:
                        print("Call ended.")
                        break
                time.sleep(1)
        except KeyboardInterrupt:
            print("Call interrupted.")
    else:
        print(f"Failed to answer the call. Response: {response}")

def hang_up_call(self):
    response = self.send_command('ATH')
    if "OK" in response:
        print("Call ended.")
    else:
        print(f"Failed to hang up the call. Response: {response}")

def close(self):
    if self.ser.isOpen():
        self.ser.close()
        print("Serial connection closed.")

Example usage:

if name == “main”:
modem = GSMModem(port=‘COM19’)
modem.check_modem()

# Monitor incoming SMS messages and calls, answering calls automatically
modem.monitor_incoming()

# Close the modem connection when done
modem.close()

I wasn’t aware there was any Teltonika device that supported voice calls, or FXS port?

Hello,

Thanks for reaching out!
You can find all the information regarding the TRM240 device from our Wiki page.
All the informations about call related commands can be reached from here.

Please check and let me know if you need any further help!

Regards,
Caner

Does this modem support voice calls on a PC.

As I am getting an incoming call but no audio. Is this compatible.??

https://forums.quectel.com/uploads/short-url/xnztA07u1c4hilREu66LYIY6NGR.pdf

Thanks forthe info. I am still struggling. Following ChatGPT I use Voice Meeter to map the audio channels.
With the following code I get
Microphone (2- AC Interface)
Speaker (2- AC Interface)

I got it working on 2 different occasions then stopped but cannot trace the fault.

Have anyone got any sample code (any language) to get this working ?

Or any ready made app that I can test with.
import serial
import time

class GSMModem:
def init(self, port=‘COM10’, baudrate=115200, timeout=1):
self.ser = serial.Serial(port, baudrate, timeout=timeout)
if self.ser.isOpen():
print(f"Connected to {port}“)
else:
print(f"Failed to connect to {port}”)

def send_command(self, command, read_response=True):
    self.ser.write((command + "\r").encode())
    time.sleep(1)
    if read_response:
        response = self.ser.read(self.ser.inWaiting()).decode().strip()
        print(f"Command: {command}\nResponse: {response}")
        return response
    return None

def enable_usb_audio_class(self):
    print("Enabling USB Audio Class (UAC)...")
    response = self.send_command('AT+QPCMV=1,2')
    if "OK" in response:
        print("UAC enabled successfully.")
    else:
        print(f"Failed to enable UAC. Response: {response}")

def set_auto_answer(self, rings=1):
    print(f"Setting auto-answer to {rings} ring(s)...")
    response = self.send_command(f'ATS0={rings}')
    if "OK" in response:
        print(f"Auto-answer set to {rings} ring(s).")
    else:
        print(f"Failed to set auto-answer. Response: {response}")

def answer_call(self):
    print("Answering call...")
    response = self.send_command('ATA')
    if "OK" in response:
        print("Call answered successfully. Audio streaming started.")
        self.monitor_call_status()  # Monitor the call status to detect end
    else:
        print(f"Failed to answer the call. Response: {response}")

def monitor_call_status(self):
    print("Monitoring call status...")
    try:
        call_active = True
        while call_active:
            if self.ser.inWaiting():
                response = self.ser.read(self.ser.inWaiting()).decode().strip()
                print(f"Modem response: {response}")
                if "NO CARRIER" in response:
                    print("Call ended by remote party.")
                    call_active = False
                    self.reinitialize_audio()  # Reinitialize UAC after call ends
                elif "ERROR" in response:
                    print("An error occurred during the call.")
                    call_active = False
                elif "BUSY" in response:
                    print("Call ended: Line busy.")
                    call_active = False
                elif "NO DIALTONE" in response:
                    print("Call ended: No dial tone.")
                    call_active = False
            time.sleep(0.1)
        print("Call monitoring ended.")
    except Exception as e:
        print(f"Exception in call monitoring: {e}")

def reinitialize_audio(self):
    print("Reinitializing USB Audio Class (UAC) after call...")
    self.enable_usb_audio_class()

def monitor_incoming_calls(self):
    print("Waiting for an incoming call... Press Ctrl+C to stop.")
    try:
        while True:
            if self.ser.inWaiting():
                response = self.ser.read(self.ser.inWaiting()).decode().strip()
                if "RING" in response:
                    print("Incoming call detected. Answering call...")
                    self.answer_call()
            time.sleep(1)
    except KeyboardInterrupt:
        print("Stopped monitoring.")
    except Exception as e:
        print(f"Exception in monitoring incoming calls: {e}")
    finally:
        self.close()

def close(self):
    if self.ser.isOpen():
        self.ser.close()
        print("Serial connection closed.")

if name == “main”:
modem = GSMModem(port=‘COM10’) # Ensure correct COM port
modem.enable_usb_audio_class() # Enable UAC mode
modem.set_auto_answer(rings=1) # Set auto-answer after 1 ring
modem.monitor_incoming_calls() # Monitor and automatically answer incoming calls
modem.close()

This topic was automatically closed after 15 days. New replies are no longer allowed.