Rev 626 | Rev 650 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 626 | Rev 633 | ||
|---|---|---|---|
| Line 69... | Line 69... | ||
| 69 | # elsif (-e $devicearg) { |
69 | # elsif (-e $devicearg) { |
| 70 | if (!$baudarg) { |
70 | if (!$baudarg) { |
| 71 | print "For a serial device you need to specifiy baudrate, now using default 19200\n"; |
71 | print "For a serial device you need to specifiy baudrate, now using default 19200\n"; |
| 72 | $baudarg = 19200; |
72 | $baudarg = 19200; |
| 73 | } |
73 | } |
| - | 74 | ||
| 74 |
|
75 | eval 'use Device::SerialPort'; ### install module with aptitude install libdevice-serialport-perl |
| - | 76 | if ($@) { |
|
| - | 77 | eval 'use Win32::SerialPort'; |
|
| - | 78 | if ($@) { |
|
| - | 79 | print "Could not find Device::SerialPort or Win32::SerialPort, I quit.\n"; |
|
| - | 80 | exit 0; |
|
| - | 81 | } else { |
|
| - | 82 | $usingWin32Serial = 1; |
|
| - | 83 | } |
|
| - | 84 | } else { |
|
| - | 85 | $usingDeviceSerial = 1; |
|
| - | 86 | } |
|
| - | 87 | ||
| 75 | &serialConnInit; |
88 | &serialConnInit; |
| 76 | $thr = threads->new(\&serialConnThread); |
89 | $thr = threads->new(\&serialConnThread); |
| 77 | $thr->detach; |
90 | $thr->detach; |
| 78 | 91 | ||
| 79 | # } else { |
92 | # } else { |
| Line 99... | Line 112... | ||
| 99 | #print $udpCsocket $retstring; |
112 | #print $udpCsocket $retstring; |
| 100 | 113 | ||
| 101 | ### Send data ### |
114 | ### Send data ### |
| 102 | if (length($hardwareSendFunction) > 0) { |
115 | if (length($hardwareSendFunction) > 0) { |
| 103 | &{$hardwareSendFunction}($retstring); |
116 | &{$hardwareSendFunction}($retstring); |
| 104 | } |
117 | } |
| 105 | 118 | ||
| 106 | } |
119 | } |
| 107 | } |
120 | } |
| 108 | } |
121 | } |
| 109 | 122 | ||
| 110 | sub hardwareConnInit { |
123 | sub hardwareConnInit { |
| 111 | print "Connecting hardware to tcpServer\n"; |
124 | print "Connecting hardware to tcpServer\n"; |
| 112 | $hwCremote = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "localhost", PeerPort => $hubport,) |
125 | $hwCremote = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "localhost", PeerPort => $hubport,) |
| 113 | or die "cannot connect to $hubport port at localhost"; |
126 | or die "cannot connect to $hubport port at localhost"; |
| Line 159... | Line 172... | ||
| 159 | } |
172 | } |
| 160 | 173 | ||
| 161 | sub serialConnInit { |
174 | sub serialConnInit { |
| 162 | print "Connecting to hardware over serial port\n"; |
175 | print "Connecting to hardware over serial port\n"; |
| 163 | $quiet=0; |
176 | $quiet=0; |
| - | 177 | if ($usingDeviceSerial == 1) { |
|
| 164 | $serialPort = new Device::SerialPort($devicearg, $quiet) || die "failed to open serial port, $devicearg is not valid?"; |
178 | $serialPort = new Device::SerialPort($devicearg, $quiet) || die "failed to open serial port, $devicearg is not valid?"; |
| - | 179 | } elsif ($usingWin32Serial == 1) { |
|
| - | 180 | $serialPort = new Win32::SerialPort($devicearg, $quiet) || die "failed to open serial port, $devicearg is not valid?"; |
|
| - | 181 | } |
|
| 165 | $serialPort->databits(8) || die "failed setting databits"; |
182 | $serialPort->databits(8) || die "failed setting databits"; |
| 166 | $serialPort->baudrate($baudarg) || die "failed setting baudrate"; |
183 | $serialPort->baudrate($baudarg) || die "failed setting baudrate"; |
| 167 | $serialPort->parity("none") || die "failed setting parity"; |
184 | $serialPort->parity("none") || die "failed setting parity"; |
| 168 | $serialPort->stopbits(1) || die "failed setting stopbits"; |
185 | $serialPort->stopbits(1) || die "failed setting stopbits"; |
| 169 | $serialPort->handshake("none") || die "failed setting handshake"; |
186 | $serialPort->handshake("none") || die "failed setting handshake"; |