Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Perl USB Com port issue

Posted on 2013-12-19
8
999 Views
Last Modified: 2014-01-14
I'm running activeperl on a windows XP box. My code is below:

#!/usr/bin/perl -w

use strict;
use Win32::SerialPort qw( :PARAM :STAT 0.07 );

my $PORT = "COM5";
my $ob = Win32::SerialPort->new($PORT);

$ob->user_msg(1);
$ob->databits(8);
$ob->datatype('raw'); 
$ob->handshake('none');
$ob->parity("none");
$ob->stopbits(1);
$ob->baudrate(57600);
$ob->write_settings;

open( PORT, "$PORT" ) or die "Can't open $PORT: $!";
while (my $line = <PORT>) {
    if ($line =~ m!<ch1><watts>0*(\d+)</watts></ch1>.*<tmpr> *([\-\d.]+)</tmpr>!) {
        my $watts = $1;
        my $temp = $2;
        print "$watts, $temp\n";
    }
}
close(PORT);

Open in new window


However, this gives me an error (I'm running this from a command prompt currently):
Can't open COM5: Permission denied at currentcost.pl line 19.

Open in new window


I am logged in as an administrator account. I have confirmed the port settings match exactly to both my device, and those listed in "device manager" under windows.

The com port is a USB/Serial adapter, which works perfectly under hyperterminal etc and I can read output from the com port just fine.

Could someone please help?

Thanks!

Ross
0
Comment
Question by:RossDagley1
  • 2
  • 2
8 Comments
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 39766425
Under Windows I seem to recall you get "Permission denied" on a COM port that is in use by another process. Could there be 2 instances of your Perl program running?
Can you verify that your program gets further using, say, COM1
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39766712
Ah, good old CurrentCost!

I've got the same code running under Linux. The only real difference is in the open line - I have:
    open(DEV, "<$PORT") || die ....
(I.e. a "<" before the $PORT)
0
 
LVL 2

Accepted Solution

by:
RossDagley1 earned 0 total points
ID: 39768931
Yes. Unfortunately I needed this sorted in a timely manner and never did fix the actual issue. I worked around it by migrating to a linux box to run my stats.

Thanks for dropping in though.
0
 
LVL 19

Expert Comment

by:simon3270
ID: 39769117
Sorry I wasn't in time (didn't see it until shell scripting was added), but glad you got it sorted.

If you get a chance to test it, it would be interesting to see whether the "<" fix worked on Windows.
0
 
LVL 2

Author Closing Comment

by:RossDagley1
ID: 39778774
Resolved by myself with no expert assistance here.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question