Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / March 2006



Tip: Looking for answers? Try searching our database.

Device::SerialPort and Keyspan

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Slimboyfatboyslim - 02 Mar 2006 00:08 GMT
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
Dave Gomez - 02 Mar 2006 04:20 GMT
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,
>
[quoted text clipped - 60 lines]
> Cheers,
> SFS
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.