Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32 Serialport.pm problem

Status
Not open for further replies.

adderm

Programmer
Joined
May 21, 2007
Messages
2
Location
GB
Hi all,

I am relative perl newby, and am trying to use perl to program a PSU through a serial port.

I can't get any communication (either transmitting or recieving to the serial port):
Simple code (should work?):

#!perl

use Win32::SerialPort;
use vars qw($portob);

$portob = new Win32::SerialPort ("COM2") || die "Can't start \n";
$portob->databits(8);
$portob->baudrate(2400);
$portob->parity('none');
$portob->stopbits(1);
$portob->handshake('dtr');
$portob->write('4B 4F 45 0D'); #HEX
$portob->write('K0E\r'); #ASCII
print "end";
exit

I've installed (more than once) Serialport.pm and Commport.pm from CPAN.

NOTE: I know that the connection is working becuase both the simple exe program which came with the instrument works and the downloadable (demo version) program (exe) RS232 HEX COM Tool works fine.

I don't get any warnings, it just runs and finishes and nothing happens at on the PSU(?)

Any tips would be appreciated.

A

 
I'm not familiar with the module, but does it print "end" as you only seem to be printing that.

Also you can use the -w swtich and strict pragma. You can also use eval to see if any errors are being reported by the system, which I doubt.
 
Hi max1x,

Thanks for your post. Yes, the print end does work.

The use strict doesn't make any difference, and the -w flag does not give any warnings.

A
 
Are you sure the parameters, specifically the handshake, match those of the device?
Is it possible that the device wants to see a \r\n or other line termination before reacting to the characters read?
To me the syntax of the write HEX line is new: I would expect a string of 11 characters to be written. The write method returns the number of characters written: you should test it with $c=$portob->write(...;print$c;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top