SFS,
been a while, but I do remember getting it to work bi
directionaly, and also know that eh Keyspan works well.
try this for your output statements:
$count_out = $obj->write($output_string);
warn "write failed\n" unless ($count_out);
warn "write incomplete\n" if ( $count_out != length
($output_string) );
and see what it returns, either no characters passed, only some, or all.
Dave
On Mar 1, 2006, at 5:08 PM, slimboyfatboyslim wrote:
hi list,
I'm working on a small script which fetch data via finance::quote
and send it to a microcontroller via SerialPort (installed via
DarwinPort). Working with Keyspan, when I run the script, the LED
light flashes which normally means data have been sent.
But while I connect the serial port to a PC with hyper terminal
(same with another PB), it's seems it doesn't get any data.
I've tried sending both strings and hex vaule, but it doesn't work,
does anyone working on WRITING SerialPort on Mac?
Here's my code
#!/usr/bin/perl
# import module
use strict;
use Finance::Quote;
use Device::SerialPort;
use Math::BigRat;
# create object
my $q = Finance::Quote->new();
my $file = "/dev/tty.KeySerial1"; # check /dev/
my $ob = Device::SerialPort->new ($file) || die "Can't open $file:
$!";
$ob->baudrate(9600) || die "fail setting baudrate";
$ob->parity("none") || die "fail setting parity";
$ob->databits(8) || die "fail setting databits";
$ob->stopbits(1) || die "fail setting stopbits";
$ob->handshake("none") || die "fail setting handshake";
$ob->write_settings || die "fail write setting";
# retrieve stock quote
my %data = $q->fetch('nasdaq', 'LNUX');
while($data{'LNUX', 'price'}){
# print price
#print "The current price of LNUX on the NASDAQ is " . $data
{'LNUX', 'price'};
my $scale_price = $data{'LNUX', 'price'} * 100; #LNUX ranges aounrd
1.xxx to 2.xxx
my $rat_price = Math::BigRat->new($scale_price);
$rat_price -> bfloor(); #Truncate to integer, that's y we need
Math::BigRat
#print "Scale from BigRat " . $rat_price;
#$ob->write($rat_price);
#$ob->write("\x02\x30\x33\x80\x90\x41\x80\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\xc1\x03\r\n");
my $hex_test = "\x00\x0B\x16\x0A\x14\x00\x05\x06\x25\x00\x01\x00\x22
\r";
$ob->write("\x00\x0B\x16\x0A\x14\x00\x05\x06\x25\x00\x01\x00\x22\r");
warn "write failed\n" unless ($hex_test);
#print "Outputting " . $hex_test;
}
Cheers,
SFS