develooper Front page | perl.macosx | Postings from March 2006

Device::SerialPort and Keyspan

Thread Next
From:
slimboyfatboyslim
Date:
March 1, 2006 16:07
Subject:
Device::SerialPort and Keyspan
Message ID:
1D2A880B-19EB-4D86-A92B-9EC75EBCD20B@slimboyfatboyslim.org
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 

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About