problem in using win32::SerialPort
am 07.09.2007 08:27:35 von SachinHi All
I am using win32::SerialPort in my perl application.
I am able to read and write at COM1 using API of win32::SerialPort
module.
Now I am trying to open a port which does not exist on my machine(e.g.
COM3)
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;
}
else
{
$PortObj->handshake("xoff");
$PortObj->baudrate(115200);
$PortObj->parity("even");
$PortObj->databits(8);
$PortObj->stopbits(1);
........
........
}
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
connected.
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