Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Perl USB Com port issue

Posted on 2013-12-19
8
Medium Priority
?
1,102 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:Ross
  • 2
  • 2
8 Comments
 
LVL 35

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 20

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:
Ross 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 20

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:Ross
ID: 39778774
Resolved by myself with no expert assistance here.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

885 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