[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Serial interface





On Sat, 10 Oct 1998, Garry Paine wrote:

> >
> >Sorry, that plain doesn't work. There are modules for accessing the serial
> >port
> >(CommConnect, for instance), but as I've never done much work with them, they
> >might not work all that well.
> >
> >Matthias
> >
> 
> The CommConnect module refers to a Hypercard stack (documentation on how to
> use it). I didn't see it in the distribution of MacPerl including the
> MacPerl disk that came with the book.  Any pointers to where I could find
> it?
> 
> Thanks, Garry
> 

	I couldn't find it either--I searched the 'net and didn't find it.
You could try emailing the author or maybe someone in the list has it.  I
just took CommConnect.t and started to modify it.  Here are some examples
that might give you some ideas ( I'm sure my code is ugly and improper,
but it works.  The other guy's code looks good):


Admittedly, this code is a mess but it worked well for talking to a mud
on compuserve (as good as was possible without threading).  The main thing
is to figure out what the server is sending
and modify your script accordingly, with do-while loops until a certain
string is received, or using sleeps, etc.  I did have to modify
CommConnect.pl itself to get my script to log on successfully to
compuserve.

 while (1) {
   my($input,$output,$alloutput,$x);
   $input="";
   $_ = <STDIN>;
   $input=$_;
   if ($_ =~/^\$\d*,\d*$/ || $_=~/^\$[A-Z][a-z]+/) {
    $_=~s/\$//;
    &SEARCH($_,'CIS');
   }
   if ($_=~/NO\sCARRIER/) {&DISCONNECT;}
  print &CommConnect'Send($_);
  $output="";
  $alloutput="";

  do {
   $x+=1;
   $output = &CommConnect'Receive();
   $output =~tr/\012\015/\n/s;
   $output=~s/$input//;
   $alloutput .= $output;
  } until (($alloutput =~ /.\n.\n\-\-\-\-\*$|.\n.\n\(\-\-\-\-\*\)$/) || 

$x==200);

  print STDOUT "\$x is now $x \n";
  $back = &BUFFOMATIC($alloutput,'CIS');
  @OUTPUT = split(/\n/,$alloutput);
  for ($i=0;$i<=$#OUTPUT;$i++) {
   if ($i!=($#OUTPUT) && $OUTPUT[$i]) {
    print STDOUT "$OUTPUT[$i]\n";
   }
   else {
    print STDOUT "$OUTPUT[$i]";
   }
 }

} #end while (1)





Re:
[MacPerl] CommConnect

Eric Jensen (jensen@singha.astro.wisc.edu)
Mon, 11 Mar 96 10:50:36 -0600

   * Messages sorted by: [ date ][ thread ][ subject ][ author ]
   * Next message: Glen Osterhout: "[MacPerl] MacPerl cgi-script question"
   * Previous message: Hal Wine: "[MacPerl] On the meaning of '\n'..."
   * Maybe in reply to: Johnson, Steve: "[MacPerl] CommConnect"

----------------------------------------------------------------------------

> i'm trying to write a script that can log onto a mainframe that's
> connected to my serial port.  i tried using the CommConnect.pl
> commands and was able to see the prompt from the terminal server
> but i haven't been able to send or receive anything meaningful
> through the serial port.  has anyone done something similar?

Appended below is a MacPerl script I wrote which uses CommConnect.pl.
It's for an application that's a bit different than yours, but might
give you some ideas.  I use the script to download data from a
handheld blood glucose testing meter via an RS-232 interface.  (I have
diabetes, and test my blood glucose levels several times a day, and
this script is part of a MacPerl program which lets me download and
plot the data.)

        The script isn't very complex, but gives you some idea of how
CommConnect works.  You'll see that the script checks the content of
the data received to look for specific markers that denote the
beginning and end of the expected data - if you don't know what to
expect from the other end, I'm not sure how you would decide that all
the data had arrived.

Good luck,

Eric Jensen

------------------------------------------------------------------
sub DumpData {

# Revisions:
# 5/2/95: Added code to allow user to select printer or modem port.
#         Would like to be able to show pictures of the port icons.

require "CommConnect.pl";

print &CommConnect'Prepare("Serial Tool (1.0.2)"), "\n";
$question = "To which port is the One Touch II meter connected?";
$answer = &MacPerl'Answer($question, "Printer port", "Modem port");
if ($answer) {
   $settings = "Port \"Printer Port\"";
} else {
   $settings = "Port \"Modem Port\"";
}
print &CommConnect'ChangeSettings($settings), "\n";

# Try to open a connection to the Serial Tool on the desired port;
# Returns empty string if successful; otherwise, dies with the error
message:
$status = &CommConnect'OpenConnection();
if ($status) { die($status, "  Exiting program.\n"); }

print "\n\nTrying to establish connection with the meter...\n\n\n";

# Start reading data from the meter, and wait until
# it starts flashing "INSERT STRIP"

do {
   $data = &CommConnect'Receive();
   $alldata .= $data;
}
until ($alldata =~ /INSERT/);

print "Sending command to dump data...\n\n\n";

# Now that the meter is ready, send the command to dump
# the meter's memory.

$command = "DMP";
$status = &CommConnect'Send($command);
if ($status) { die($status, "  Exiting program.\n"); }

print "Reading data from the meter...\n\n\n";

# Now read that data into one long string, until
# 1) We've read at least some data, as evidenced by the
#    presence of at least one comma in the data string, and
# 2) the meter goes back to flashing "INSERT STRIP" again:

# The subroutine "Receive2" is just a small hack of the original
# "Receive" to allow it to implement the "small buffer" option.
#  Look at the documentation for the CommConnect Hypercard stack
# for details.

$alldata = "";
do {
   $data = &CommConnect'Receive2("strip linefeeds","small buffer");
   $alldata .= $data;
}
until (($data =~ /INSERT/)); #&& ($alldata =~ /,/));

print "Data downloaded successfully.\n\n\n";

# Split the data into an array, splitting on newlines:
@data_array = split(/\n/,$alldata);

# Occasionally we get a few blank lines or "INSERT STRIPS" on the end
# of the data, so get rid of those here, identifying
# the data lines as those with commas in them:

while (@data_array[$#data_array] !~ /,/) {
   $deleted = pop(@data_array);
}

print &CommConnect'CloseConnection(), "\n";
print &CommConnect'Cleanup(), "\n";

return(@data_array);

# End of subroutine DumpData
}
1;

----------------------------------------------------------------------------

   * Next message: Glen Osterhout: "[MacPerl] MacPerl cgi-script question"
   * Previous message: Hal Wine: "[MacPerl] On the meaning of '\n'..."
   * Maybe in reply to: Johnson, Steve: "[MacPerl] CommConnect"


> 
> 
> 
> ***** Want to unsubscribe from this list?
> ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch
> 
> 


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch