0

Fatal error: Uncaught exception 'Exception' with message 'Unable to setup COM port, check it is correct' in C:\xampp\htdocs\jsms\sms.php:61 Stack trace: #0 C:\xampp\htdocs\jsms\sms.php(17): gsm_send_sms->init() #1 {main} thrown in C:\xampp\htdocs\jsms\sms.php on line 61 public function init() {

    $this->debugmsg("Setting up port: \"{$this->port} @ \"{$this->baud}\" baud");

    exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);

    if ($retval != 0) 
    {
        throw new Exception('Unable to setup COM port, check it is correct');
    }

    $this->debugmsg(implode("\n", $output));
    $this->debugmsg("Opening port");

    //Open COM port
    $this->fp = fopen($this->port . ':', 'r+');

    //Check port opened
    if (!$this->fp) {
        throw new Exception("Unable to open port \"{$this->port}\"");
    }

1 Answers1

0

You are not catching the exception you throw at:

if ($retval != 0) 
{
    throw new Exception('Unable to setup COM port, check it is correct');
}

that is thrown if

exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);

returns an error int (anything != 0).

Use:

try {
    exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);
    if ($retval != 0) 
    {
        throw new Exception('Unable to setup COM port, check it is correct');
    }
} catch (Exception $e) {
    // do whatever you want to handle the error
}
Shoe
  • 74,840
  • 36
  • 166
  • 272