problem in using win32::SerialPort

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hi All
I am using win32::SerialPort in my perl application.
I am able to read and write at COM1 using API of win32::SerialPort
Now I am trying to open a port which does not exist on my machine(e.g.
When I open this port , I get an error
****" Can't open \.\COM3: The system cannot find the file specified"
and application exits.
I dont want to get my application exit after this.
I read the manual of win32::SerialPort and found that using $quiet I
can get return value 0 if port is not opened.
Below is my code I have used
sub IntializeUART
  $quiet = 1;
  $PortObj = new Win32::SerialPort ($_[0], $quiet)
       || die "Can't open $_[0]: $^E\n";    # $quiet is optional

  if($PortObj == 0)
    return 0;


I set this $quiet to 1 but my application still exits.
Actually my board is connected to one of the port on the PC.Now I want
to open ports from COM1 to COM20 and see on which port my board is
But as soon as my application comes across any port which it is not
able to open it shows me the above mentioned message(****) and
application exits.

So can you please tell me how to use $quiet so that I get return value
0 when port is not opened and my application does not exit.

Your suggestions are welcome.
Thanks in advance

Re: problem in using win32::SerialPort

Quoted text here. Click to load it

Doctor, doctor it hurts when I do this...

If you don't want your application to die when Win32::SerialPort->new
returns false then I would suggest you should remove the die() that is
executed when Win32::SerialPort->new returns false.

Site Timeline