我用 Neo-6M GPS module 做了一些小项目datasheet , 在 Windows 10 中跟踪 全局定位系统 卫星。
下面的代码片段演示了 communication core
的程序。
我发现有时在程序启动时它不与 通信。 GPS模块我必须按 来打断它Ctrl+C 几次,以便能够重新启动它并在程序和 之间建立通信。全局定位系统 模块。
有时,在程序从 读取数据之前可能需要几次尝试。全局定位系统 模块。
全局定位系统 模块通过USB转串口模块连接电脑cp2102 , cp2102 datasheet .
全局定位系统 模块和驱动程序正常工作——通过 u-center 确认软件。
有人可以通过程序与 之间的交互来发现所描述问题的原因吗?全局定位系统 模块?
use strict;
use warnings;
use feature 'say';
use Time::HiRes qw(usleep);
use Win32::SerialPort;
use Win32::Process;
use Win32::Console::ANSI qw/Cls Title Cursor/;
use Term::ANSIScreen qw/:color :cursor :screen/;
use sigtrap 'handler' => \&sig_handler, qw(INT TERM KILL QUIT);
use Data::Dumper;
my $debug = 1;
my $port_name = 'COM4';
my $baudrate = 9600;
my $databits = 8;
my $parity = 'none';
my $stopbits = 1;
my $portObj = new Win32::SerialPort($port_name)
|| die "Can't open $port_name: $^E\n"; # $quiet is optional
$portObj->baudrate($baudrate);
$portObj->databits($databits);
$portObj->parity($parity);
$portObj->stopbits($stopbits);
sub sig_handler {
Cls();
cursor_mode('on');
$portObj->lookclear();
$portObj->close();
exit 0;
}
cursor_mode('off');
while(1) {
my $line = $portObj->lookfor();
if( $line ) {
{
local $/ = "\r";
chomp $line;
}
say "[$line]" if $debug;
# Some data processing takes place
} else {
usleep(50); # Allocate time for other processes to run
}
}
# Data processing subroutines
# Positioned output to terminal window
sub cursor_mode {
my $mode = shift;
print "\e[?25l" if $mode eq 'off';
print "\e[?25h" if $mode eq 'on';
}
最佳答案
您必须登录 GPS 模块主机并重新启动 GPS 模块守护程序(或以其他方式终止陈旧的连接)。在程序上执行 ctrl-c 是不够的。有时您可以重新建立连接,因为之前的连接超时。
关于windows - Perl 串口访问 [Windows 10],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60312343/