-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.pl
executable file
·66 lines (54 loc) · 1.51 KB
/
log.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl
#
#
# Author: Bruce S. Garlock
# Date: 2002-09-11
# Requirements: Device::SerialPort 0.12 (from cpan)
#
# Version: 0.1
#
#
# Description: This perl script is for logging of data from a serial
# port, to a specified logfile. The logfile can then be parsed with
# other programs for reporting purposes.
#
# This program was written for specifically logging Multitech's
# MTASR2-203 T1 Router. The router outputs text to the command
# port with 57.6k, 8-1-N, and No flow control.
#
#
use Device::SerialPort 0.12;
$LOGDIR = "/Users/ako/Trash"; # path to data file
$LOGFILE = "nikon.log"; # file name to output to
$PORT = "/dev/tty.usbserial-A505BQWI"; # port to watch
#
#
# Serial Settings
#
#
$ob = Device::SerialPort->new ($PORT) || die "Can't Open $PORT: $!";
$ob->baudrate(4800) || die "failed setting baudrate";
$ob->parity("none") || die "failed setting parity";
$ob->databits(8) || die "failed setting databits";
$ob->handshake("none") || die "failed setting handshake";
$ob->write_settings || die "no settings";
#
# Send a string to the port
#
#
$pass=$ob->write("AT");
sleep 1;
#
# open the logfile, and Port
#
open(LOG,">>${LOGDIR}/${LOGFILE}")
|| die "can't open smdr file $LOGDIR/$LOGFILE for append: $SUB $!\n";
open(DEV, "<$PORT")
|| die "Cannot open $PORT: $_";
select(LOG), $| = 1; # set nonbufferd mode
#
# Loop forver, logging data to the log file
#
while($_ = <DEV>){ # print input device to file
print LOG $_;
}