You don't need to use threads to do this. The comm buffers are filled for you behind the scenes with Win32::Serialport.
You can use threads if you want but there is no need. Cheers, John > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Lin Jingxian > Sent: Wednesday, November 24, 2004 12:01 PM > To: [EMAIL PROTECTED] > Subject: Win32::SerialPort and thread > > > hi, > can Win32::SerialPort be used in multi-thread > environment? I want to > use two threads to access COM1 on my computer, one for > reading and one for > writing.I have wrotten some code to do it,but it didn't work.any idea? > > here is my code: > > # reopen COM and Tie it > $commPort = tie (*COMM, 'Win32::SerialPort', > $Configuration_File_Name) > || die "Can't tie: $^E\n"; > > my $thr2 = threads->new(\&transfer,$sock,*COMM,1); > $thr2->join(); > print "sock -> port terminated.\n"; > > my $thr1 = threads->new(\&transfer,*COMM,$sock,0); > $thr1->join(); > print "port -> sock terminated.\n"; > > sub transfer { > my $from = shift; > my $to = shift; > my $exitOnUndef = shift; > my $buf=''; > my $ret=0; > while(1){ > $ret = sysread($from,$buf,100); > #if($exitOnUndef == 1){ > # $ret or last; > #} > if($ret > 0){ > print "read $ret bytes.\n"; > $ret = syswrite($to,$buf); > if(!defined $ret || $ret == 0){ > print "$^E\n"; > last; > }else{ > print "write $ret bytes.\n"; > } > } > else{ > last; > } > print "loop\n"; > } > print "thread "; > print threads->self()->tid(); > print " exit : [$^E]\n"; > } > > _______________________________________________ > Perl-Win32-Users mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs