I have tried Win32::SerialPort but it fails with an error "invalid COMMPROP block length= 66".
use Win32::SerialPort; use strict; use warnings; my $Port = "COM9"; # port to watch my $Baud=15200; my $PortObj = Win32::SerialPort->new ($Port,1) || die "Can't Open $Por +t: $!"; $PortObj->write_settings || undef $PortObj; print "Can't change Device_Control_Block: $^E\n" unless ($PortObj); $PortObj->baudrate($Baud) || die "failed setting baudrate to $Baud"; $PortObj->parity("none") || die "failed setting parity"; $PortObj->databits(8) || die "failed setting databits"; $PortObj->handshake("none") || die "failed setting handshake"; my $rtn=$PortObj->write("help"); print $rtn; sleep 1; print "DONE\n"; undef $PortObj; exit;
I have tried Device::USB but it does not seem to support USB devices on windows.
I have tried to use sysopen and syswrite (code below) but I am now sure how to get to to do anything for me. I hangs on the sysread. Plus I am not sure how to set the baudrate,etc with this method.
Any help would be greatly appreciated. If I use hyperterminal, I can simply choose COM9 and set the baudrate to 115200 and I connect fine.#!perl $port="COM9"; sysopen(COM,$port,O_RDWR) || die "Can't open $port $^E"; $length=1024; while(1){ print ">"; $cmd=<STDIN>; if($cmd=~/^(x|q|exit|quit)$/is){last;} $cmd =~s/[\r\n]+$//; print "Cmd: $cmd\n"; my $packcmd=pack("A*",$cmd); print "Send: $packcmd\n"; syswrite(COM,$packcmd); #sends $string to COM1 print "Reading...\n"; #code to read data from port sysread(COM,$buf,$length); #read $length bytes print "Buf: $buf\n"; $received = unpack("C*",$buf); #unpack them print "Receive: $received\n"; } exit;
In reply to Connecting to a USB Serial Device on Windows by slloyd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |