testing if hardware is avalible
Hi can you advise on the best way test if a usb modem is plugged in ? I though about checking if the file/node /dev/ttyACM0 is present, as it's created when the device is plugged in using open (TEST, /dev/tty/ACM0); but just concecned if i do this while the device is acitive it will cause it to drop the connection... What is the best methode for this ?? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: testing if hardware is avalible
On 7/19/07, Gregory Machin [EMAIL PROTECTED] wrote: can you advise on the best way test if a usb modem is plugged in ? I'd look at the socket. But if you're trying to do this via Perl, the best answer is the same way you'd do it via C, INTERCAL, or any other language. In other words, you may need to ask in a forum about usb devices, instead of one about Perl. Once you know what low-level operation will give you your answer, we can help you find a way to do that from Perl. I though about checking if the file/node /dev/ttyACM0 is present, as it's created when the device is plugged in using open (TEST, /dev/tty/ACM0); but just concecned if i do this while the device is acitive it will cause it to drop the connection... Maybe you could use a filetest to do what you want? Perhaps -e or even -c? my $modem_port = '/dev/tty/ACM0'; die Modem not found on '$modem_port' unless -c $modem_port; Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: testing if hardware is avalible
On 7/20/07, Gregory Machin [EMAIL PROTECTED] wrote: Hi can you advise on the best way test if a usb modem is plugged in ? I though about checking if the file/node /dev/ttyACM0 is present, as it's created when the device is plugged in using open (TEST, /dev/tty/ACM0); but just concecned if i do this while the device is acitive it will cause it to drop the connection... What is the best methode for this ?? This is highly OS dependent; however, most OSes provide a utility like ifconfig that can report on the status of network interfaces. Another option (at least under many UNIX flavors) is to use lsof (list open files) to check to see if the file is already open: #!/usr/bin/perl use strict; use warnings; $! = 0; if (my $out = `lsof $ARGV[0]`) { die $out if $?; print $ARGV[0] is open\n; } else { print $ARGV[0] is closed\n; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/