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

Re: [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;