Solved

Perl USB Com port issue

Posted on 2013-12-19
8
1,024 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
[X]
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
  • 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
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…

751 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