The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
    <HTML> 
	<HEAD> 
	    <TITLE>Win32API::CommPort - Raw Win32 system API calls for serial communications.

</TITLE> 
	</HEAD>

	<BODY>

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<UL>

		<LI><A HREF="#Constructors">Constructors</A>
		<LI><A HREF="#Configuration_Utility_Methods">Configuration Utility Methods</A>
		<LI><A HREF="#Capability_Methods_read_only_">Capability Methods (read only)</A>
		<LI><A HREF="#Configuration_Methods">Configuration Methods</A>
		<LI><A HREF="#Operating_Methods">Operating Methods</A>
	</UL>

	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<UL>

		<LI><A HREF="#Initialization">Initialization</A>
		<LI><A HREF="#Configuration_and_Capability_Met">Configuration and Capability Methods</A>
		<LI><A HREF="#Exports">Exports</A>
	</UL>

	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#KNOWN_LIMITATIONS">KNOWN LIMITATIONS</A>
	<LI><A HREF="#BUGS">BUGS</A>
	<LI><A HREF="#AUTHORS">AUTHORS</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#COPYRIGHT">COPYRIGHT</A>
	<UL>

		<LI><A HREF="#COMPATIBILITY">COMPATIBILITY</A>
	</UL>

</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME

</A></H1>
Win32API::CommPort - Raw Win32 system API calls for serial communications.


<P>

<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS

</A></H1>
<PRE>  use Win32;    ## not required under all circumstances
  require 5.003;
  use Win32API::CommPort qw( :PARAM :STAT 0.19 );
</PRE>

<P>

<PRE>  ## when available ##  use Win32API::File 0.07 qw( :ALL );
</PRE>

<P>

<P>
<HR>
<H2><A NAME="Constructors">Constructors

</A></H2>
<PRE>  $PortObj = new Win32API::CommPort ($PortName, $quiet)
       || die &quot;Can't open $PortName: $^E\n&quot;;    # $quiet is optional
</PRE>

<P>

<PRE>  @required = qw( BAUD DATA STOP );
  $faults = $PortObj-&gt;initialize(@required);
  if ($faults) { die &quot;Required parameters not set before initialize\n&quot;; }
</PRE>

<P>

<P>
<HR>
<H2><A NAME="Configuration_Utility_Methods">Configuration Utility Methods

</A></H2>
<PRE>  set_no_messages(1);                   # test suite use
</PRE>

<P>

<PRE>      # exported by :PARAM
  nocarp || carp &quot;Something fishy&quot;;
  $a = SHORTsize;                       # 0xffff
  $a = LONGsize;                        # 0xffffffff
  $answer = yes_true(&quot;choice&quot;);         # 1 or 0
  OS_Error unless ($API_Call_OK);       # prints error
</PRE>

<P>

<PRE>  $PortObj-&gt;init_done  || die &quot;Not done&quot;;
</PRE>

<P>

<PRE>  $PortObj-&gt;fetch_DCB  || die &quot;Not done&quot;;
  $PortObj-&gt;update_DCB || die &quot;Not done&quot;;
</PRE>

<P>

<PRE>  $milliseconds = $PortObj-&gt;get_tick_count;
</PRE>

<P>

<P>
<HR>
<H2><A NAME="Capability_Methods_read_only_">Capability Methods (read only)

</A></H2>
<PRE>     # true/false capabilities
  $a = $PortObj-&gt;can_baud;      # else fixed
  $a = $PortObj-&gt;can_databits;
  $a = $PortObj-&gt;can_stopbits;
  $a = $PortObj-&gt;can_dtrdsr;
  $a = $PortObj-&gt;can_handshake;
  $a = $PortObj-&gt;can_parity_check;
  $a = $PortObj-&gt;can_parity_config;
  $a = $PortObj-&gt;can_parity_enable;
  $a = $PortObj-&gt;can_rlsd;       # receive line signal detect (carrier)
  $a = $PortObj-&gt;can_rlsd_config;
  $a = $PortObj-&gt;can_16bitmode;
  $a = $PortObj-&gt;is_rs232;
  $a = $PortObj-&gt;is_modem;
  $a = $PortObj-&gt;can_rtscts;
  $a = $PortObj-&gt;can_xonxoff;
  $a = $PortObj-&gt;can_xon_char;
  $a = $PortObj-&gt;can_spec_char;
  $a = $PortObj-&gt;can_interval_timeout;
  $a = $PortObj-&gt;can_total_timeout;
</PRE>

<P>

<PRE>     # list output capabilities
  ($rmax, $wmax) = $PortObj-&gt;buffer_max;
  ($rbuf, $wbuf) = $PortObj-&gt;are_buffers;       # current
  @choices = $PortObj-&gt;are_baudrate;            # legal values
  @choices = $PortObj-&gt;are_handshake;
  @choices = $PortObj-&gt;are_parity;
  @choices = $PortObj-&gt;are_databits;
  @choices = $PortObj-&gt;are_stopbits;
</PRE>

<P>

<P>
<HR>
<H2><A NAME="Configuration_Methods">Configuration Methods

</A></H2>
<PRE>     # most methods can be called two ways:
  $PortObj-&gt;is_handshake(&quot;xoff&quot;);           # set parameter
  $flowcontrol = $PortObj-&gt;is_handshake;    # current value (scalar)
</PRE>

<P>

<PRE>     # similar
  $PortObj-&gt;is_baudrate(9600);
  $PortObj-&gt;is_parity(&quot;odd&quot;);
  $PortObj-&gt;is_databits(8);
  $PortObj-&gt;is_stopbits(1);
  $PortObj-&gt;debug_comm(0);
  $PortObj-&gt;is_xon_limit(100);      # bytes left in buffer
  $PortObj-&gt;is_xoff_limit(100);     # space left in buffer
  $PortObj-&gt;is_xon_char(0x11);
  $PortObj-&gt;is_xoff_char(0x13);
  $PortObj-&gt;is_eof_char(0x0);
  $PortObj-&gt;is_event_char(0x0);
  $PortObj-&gt;is_error_char(0);       # for parity errors
</PRE>

<P>

<PRE>  $rbuf = $PortObj-&gt;is_read_buf;    # read_only except internal use
  $wbuf = $PortObj-&gt;is_write_buf;
  $size = $PortObj-&gt;internal_buffer;
</PRE>

<P>

<PRE>  $PortObj-&gt;is_buffers(4096, 4096);  # read, write
        # returns current in list context
</PRE>

<P>

<PRE>  $PortObj-&gt;is_read_interval(100);    # max time between read char (millisec)
  $PortObj-&gt;is_read_char_time(5);     # avg time between read char
  $PortObj-&gt;is_read_const_time(100);  # total = (avg * bytes) + const 
  $PortObj-&gt;is_write_char_time(5);
  $PortObj-&gt;is_write_const_time(100);
</PRE>

<P>

<PRE>  $PortObj-&gt;is_binary(T);               # just say Yes (Win 3.x option)
  $PortObj-&gt;is_parity_enable(F);        # faults during input
</PRE>

<P>

<P>
<HR>
<H2><A NAME="Operating_Methods">Operating Methods

</A></H2>
<PRE>  ($BlockingFlags, $InBytes, $OutBytes, $LatchErrorFlags) = $PortObj-&gt;is_status
        || warn &quot;could not get port status\n&quot;;
</PRE>

<P>

<PRE>  $ClearedErrorFlags = $PortObj-&gt;reset_error;
        # The API resets errors when reading status, $LatchErrorFlags
        # is all $ErrorFlags since they were last explicitly cleared
</PRE>

<P>

<PRE>  if ($BlockingFlags) { warn &quot;Port is blocked&quot;; }
  if ($BlockingFlags &amp; BM_fCtsHold) { warn &quot;Waiting for CTS&quot;; }
  if ($LatchErrorFlags &amp; CE_FRAME) { warn &quot;Framing Error&quot;; }
</PRE>

<P>

Additional useful constants may be exported eventually.


<P>

<PRE>  $count_in = $PortObj-&gt;read_bg($InBytes);
  ($done, $count_in, $string_in) = $PortObj-&gt;read_done(1);
        # background read with wait until done
</PRE>

<P>

<PRE>  $count_out = $PortObj-&gt;write_bg($output_string);      # background write
  ($done, $count_out) = $PortObj-&gt;write_done(0);
</PRE>

<P>

<PRE>  $PortObj-&gt;suspend_tx;                 # output from write buffer
  $PortObj-&gt;resume_tx;
  $PortObj-&gt;xmit_imm_char(0x03);        # bypass buffer (and suspend)
</PRE>

<P>

<PRE>  $PortObj-&gt;xoff_active;                # simulate received xoff
  $PortObj-&gt;xon_active;                 # simulate received xon
</PRE>

<P>

<PRE>  $PortObj-&gt;purge_all;
  $PortObj-&gt;purge_rx;
  $PortObj-&gt;purge_tx;
</PRE>

<P>

<PRE>      # controlling outputs from the port
  $PortObj-&gt;dtr_active(T);              # sends outputs direct to hardware
  $PortObj-&gt;rts_active(Yes);            # returns status of API call
  $PortObj-&gt;break_active(N);            # NOT state of bit
</PRE>

<P>

<PRE>  $PortObj-&gt;pulse_break_on($milliseconds); # off version is implausible
  $PortObj-&gt;pulse_rts_on($milliseconds);
  $PortObj-&gt;pulse_rts_off($milliseconds);
  $PortObj-&gt;pulse_dtr_on($milliseconds);
  $PortObj-&gt;pulse_dtr_off($milliseconds);
      # sets_bit, delays, resets_bit, delays
      # pulse_xxx methods not supported on Perl 5.004
</PRE>

<P>

<PRE>  $ModemStatus = $PortObj-&gt;is_modemlines;
  if ($ModemStatus &amp; $PortObj-&gt;MS_RLSD_ON) { print &quot;carrier detected&quot;; }
</PRE>

<P>

<PRE>  $PortObj-&gt;close || die;
      # &quot;undef $PortObj&quot; preferred unless reopening port
      # &quot;close&quot; should precede &quot;undef&quot; if both used
</PRE>

<P>

<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION

</A></H1>
This provides fairly low-level access to the Win32 System API calls dealing
with serial ports.


<P>

Uses features of the Win32 API to implement non-blocking I/O, serial
parameter setting, event-loop operation, and enhanced error handling.


<P>

To pass in <CODE>NULL</CODE> as the pointer to an optional buffer, pass in <CODE>$null=0</CODE>. This is expected to change to an empty list reference, <CODE>[]</CODE>, when Perl supports that form in this usage.


<P>

Beyond raw access to the API calls and related constants, this module will
eventually handle smart buffer allocation and translation of return codes.


<P>

<P>
<HR>
<H2><A NAME="Initialization">Initialization

</A></H2>
The constructor is <STRONG>new</STRONG> with a <EM>PortName</EM> (as the Registry knows it) specified. This will do a <STRONG>CreateFile</STRONG>, get the available options and capabilities via the Win32 API, and create
the object. The port is not yet ready for read/write access. First, the
desired
<EM>parameter settings</EM> must be established. Since these are tuning constants for an underlying
hardware driver in the Operating System, they should all checked for
validity by the method calls that set them. The <STRONG>initialize</STRONG> method takes a list of required parameters and confirms they have been set.
For others, it will attempt to deduce defaults from the hardware or from
other parameters. The <STRONG>initialize</STRONG> method returns the number of faults (zero if the port is setup ok). The <STRONG>update_DCB</STRONG>
method writes a new <EM>Device Control Block</EM> to complete the startup and allow the port to be used. Ports are opened for
binary transfers. A separate <CODE>binmode</CODE> is not needed. The USER must release the object if <STRONG>initialize</STRONG> or <STRONG>update_DCB</STRONG> does not succeed.


<P>

Version 0.15 adds an optional <CODE>$quiet</CODE> parameter to <STRONG>new</STRONG>. Failure to open a port prints a error message to STDOUT by default. Since
only one application at a time can ``own'' the port, one source of failure
was ``port in use''. There was previously no way to check this without
getting a ``fail message''. Setting <CODE>$quiet</CODE> disables this built-in message. It also returns 0 instead of <CODE>undef</CODE> if the port is unavailable (still FALSE, used for testing this condition -
other faults may still return <CODE>undef</CODE>). Use of <CODE>$quiet</CODE> only applies to <STRONG>new</STRONG>.


<P>

The fault checking in <STRONG>initialize</STRONG> consists in verifying an <EM>_N_$item</EM>
internal variable exists for each <EM>$item</EM> in the input list. The
<EM>_N_$item</EM> is created for each parameter that is set either directly or by default. A
derived class must create the <EM>_N_$items</EM> for any varibles it adds to the base class if it wants <STRONG>initialize</STRONG> to check them. Win32API::CommPort supports the following:


<P>

<PRE>        $item           _N_$item            setting method
        ------          ---------           --------------
        BAUD            &quot;_N_BAUD&quot;           is_baudrate
        BINARY          &quot;_N_BINARY&quot;         is_binary
        DATA            &quot;_N_DATA&quot;           is_databits
        EOFCHAR         &quot;_N_EOFCHAR&quot;        is_eof_char
        ERRCHAR         &quot;_N_ERRCHAR&quot;        is_error_char
        EVTCHAR         &quot;_N_EVTCHAR&quot;        is_event_char
        HSHAKE          &quot;_N_HSHAKE&quot;         is_handshake
        PARITY          &quot;_N_PARITY&quot;         is_parity
        PARITY_EN       &quot;_N_PARITY_EN&quot;      is_parity_enable
        RCONST          &quot;_N_RCONST&quot;         is_read_const_time
        READBUF         &quot;_N_READBUF&quot;        is_read_buf
        RINT            &quot;_N_RINT&quot;           is_read_interval
        RTOT            &quot;_N_RTOT&quot;           is_read_char_time
        STOP            &quot;_N_STOP&quot;           is_stopbits
        WCONST          &quot;_N_WCONST&quot;         is_write_const_time
        WRITEBUF        &quot;_N_WRITEBUF&quot;       is_write_buf
        WTOT            &quot;_N_WTOT&quot;           is_write_char_time
        XOFFCHAR        &quot;_N_XOFFCHAR&quot;       is_xoff_char
        XOFFLIM         &quot;_N_XOFFLIM&quot;        is_xoff_limit
        XONCHAR         &quot;_N_XONCHAR&quot;        is_xon_char
        XONLIM          &quot;_N_XONLIM&quot;         is_xon_limit
</PRE>

<P>

Some individual parameters (eg. baudrate) can be changed after the
initialization is completed. These will automatically update the
<EM>Device Control Block</EM> as required. The <EM>init_done</EM> method indicates when <EM>initialize</EM> has completed successfully.


<P>

<PRE>  $PortObj = new Win32API::CommPort ($PortName, $quiet)
       || die &quot;Can't open $PortName: $^E\n&quot;;    # $quiet is optional
</PRE>

<P>

<PRE>  if $PortObj-&gt;can_databits { $PortObj-&gt;is_databits(8) };
  $PortObj-&gt;is_baudrate(9600);
  $PortObj-&gt;is_parity(&quot;none&quot;);
  $PortObj-&gt;is_stopbits(1);
  $PortObj-&gt;is_handshake(&quot;rts&quot;);
  $PortObj-&gt;is_buffers(4096, 4096);
  $PortObj-&gt;dtr_active(T);
</PRE>

<P>

<PRE>  @required = qw( BAUD DATA STOP PARITY );
  $PortObj-&gt;initialize(@required) || undef $PortObj;
</PRE>

<P>

<PRE>  $PortObj-&gt;dtr_active(f);
  $PortObj-&gt;is_baudrate(300);
</PRE>

<P>

<PRE>  $PortObj-&gt;close || die;
      # &quot;undef $PortObj&quot; preferred unless reopening port
      # &quot;close&quot; should precede &quot;undef&quot; if both used
</PRE>

<P>

<PRE>  undef $PortObj;  # closes port AND frees memory in perl
</PRE>

<P>

The <EM>PortName</EM> maps to both the Registry <EM>Device Name</EM> and the
<EM>Properties</EM> associated with that device. A single <EM>Physical</EM> port can be accessed using two or more <EM>Device Names</EM>. But the options and setup data will differ significantly in the two
cases. A typical example is a Modem on port ``COM2''. Both of these <EM>PortNames</EM> open the same <EM>Physical</EM> hardware:


<P>

<PRE>  $P1 = new Win32API::CommPort (&quot;COM2&quot;);
</PRE>

<P>

<PRE>  $P2 = new Win32API::CommPort (&quot;\\\\.\\Nanohertz Modem model K-9&quot;);
</PRE>

<P>

<CODE>$P1</CODE> is a ``generic'' serial port. <CODE>$P2</CODE> includes
all of <CODE>$P1</CODE> plus a variety of modem-specific added options and
features. The ``raw'' API calls return different size configuration
structures in the two cases. Win32 uses the ``\\.\'' prefix to identify
``named'' devices. Since both names use the same
<EM>Physical</EM> hardware, they can not both be used at the same time. The OS will complain.
Consider this A Good Thing.


<P>

Version 0.16 adds <STRONG>pulse</STRONG> methods for the <EM>RTS, BREAK, and DTR</EM> bits. The
<STRONG>pulse</STRONG> methods assume the bit is in the opposite state when the method is called.
They set the requested state, delay the specified number of milliseconds,
set the opposite state, and again delay the specified time. These methods
are designed to support devices, such as the X10 ``FireCracker'' control
and some modems, which require pulses on these lines to signal specific
events or data. Since the 5.00402 Perl distribution from CPAN does not
support sub-second time delays readily, these methods are not supported on
that version of Perl.


<P>

<PRE>  $PortObj-&gt;pulse_break_on($milliseconds);
  $PortObj-&gt;pulse_rts_on($milliseconds);
  $PortObj-&gt;pulse_rts_off($milliseconds);
  $PortObj-&gt;pulse_dtr_on($milliseconds);
  $PortObj-&gt;pulse_dtr_off($milliseconds);
</PRE>

<P>

Version 0.16 also adds <EM>experimental</EM> support for the rest of the option bits available through the <EM>Device Control Block</EM>. They have not been extensively tested and these settings are NOT saved in
the <STRONG>configuration file</STRONG> by
<EM>Win32::SerialPort</EM>. Please let me know if one does not work as advertised. [Win32 API bit
designation]


<P>

<PRE>  $PortObj-&gt;ignore_null(0);     # discard \000 bytes on input [fNull]
</PRE>

<P>

<PRE>  $PortObj-&gt;ignore_no_dsr(0);   # discard input bytes unless DSR
                                # [fDsrSensitivity]
</PRE>

<P>

<PRE>  $PortObj-&gt;subst_pe_char(0);   # replace parity errors with B&lt;is_error_char&gt;
                                # when B&lt;is_parity_enable&gt; [fErrorChar]
</PRE>

<P>

<PRE>  $PortObj-&gt;abort_on_error(0);  # cancel read/write [fAbortOnError]
</PRE>

<P>

<PRE>      # next one set by $PortObj-&gt;is_handshake(&quot;dtr&quot;);
  $PortObj-&gt;output_dsr(0);      # use DSR handshake on output [fOutxDsrFlow]
</PRE>

<P>

<PRE>      # next one set by $PortObj-&gt;is_handshake(&quot;rts&quot;);
  $PortObj-&gt;output_cts(0);      # use CTS handshake on output [fOutxCtsFlow]
</PRE>

<P>

<PRE>      # next two set by $PortObj-&gt;is_handshake(&quot;xoff&quot;);
  $PortObj-&gt;input_xoff(0);      # use Xon/Xoff handshake on input [fInX]
  $PortObj-&gt;output_xoff(0);     # use Xon/Xoff handshake on output [fOutX]
</PRE>

<P>

<PRE>  $PortObj-&gt;tx_on_xoff(0);      # continue output even after input xoff sent
                                # [fTXContinueOnXoff]
</PRE>

<P>

The <STRONG>get_tick_count</STRONG> method is a wrapper around the <EM>Win32::GetTickCount()</EM>
function. It matches a corresponding method in <EM>Device::SerialPort</EM> which does not have access to the <EM>Win32::</EM> namespace. It still returns time in milliseconds - but can be used in
cross-platform scripts.


<P>

<P>
<HR>
<H2><A NAME="Configuration_and_Capability_Met">Configuration and Capability Methods

</A></H2>
The Win32 Serial Comm API provides extensive information concerning the
capabilities and options available for a specific port (and instance).
``Modem'' ports have different capabilties than ``RS-232'' ports - even if
they share the same Hardware. Many traditional modem actions are handled
via TAPI. ``Fax'' ports have another set of options - and are accessed via
MAPI. Yet many of the same low-level API commands and data structures are
``common'' to each type (``Modem'' is implemented as an ``RS-232''
superset). In addition, Win95 supports a variety of legacy hardware (e.g
fixed 134.5 baud) while WinNT has hooks for ISDN, 16-data-bit paths, and
256Kbaud.


<P>

Binary selections will accept as <EM>true</EM> any of the following:
<CODE>("YES", "Y", "ON", "TRUE", "T", "1", 1)</CODE> (upper/lower/mixed case) Anything else is <EM>false</EM>.


<P>

There are a large number of possible configuration and option parameters.
To facilitate checking option validity in scripts, most configuration
methods can be used in two different ways:


<P>

<DL>
<DT><STRONG><A NAME="item_method">method called with an argument

</A></STRONG><DD>
The parameter is set to the argument, if valid. An invalid argument returns <EM>false</EM> (undef) and the parameter is unchanged. After <STRONG>init_done</STRONG>, the port will be updated immediately if allowed. Otherwise, the value
will be applied when <STRONG>update_DCB</STRONG> is called.


<P>

<DT><STRONG>method called with no argument in scalar context

</A></STRONG><DD>
The current value is returned. If the value is not initialized either
directly or by default, return ``undef'' which will parse to <EM>false</EM>. For binary selections (true/false), return the current value. All current
values from ``multivalue'' selections will parse to <EM>true</EM>. Current values may differ from requested values until <STRONG>init_done</STRONG>. There is no way to see requests which have not yet been applied. Setting
the same parameter again overwrites the first request. Test the return
value of the setting method to check ``success''.


<P>

<DT><STRONG><A NAME="item_Asynchronous">Asynchronous (Background) I/O

</A></STRONG><DD>
This version now handles Polling (do if Ready), Synchronous (block until
Ready), and Asynchronous Modes (begin and test if Ready) with the timeout
choices provided by the API. No effort has yet been made to interact with
Windows events. But background I/O has been used successfully with the Perl
Tk modules and callbacks from the event loop.


<P>

<DT><STRONG><A NAME="item_Timeouts">Timeouts

</A></STRONG><DD>
The API provides two timing models. The first applies only to reading and
essentially determines <EM>Read Not Ready</EM> by checking the time between consecutive characters. The <STRONG>ReadFile</STRONG> operation returns if that time exceeds the value set by <STRONG>is_read_interval</STRONG>. It does this by timestamping each character. It appears that at least one
character must by received in
<EM>every</EM>  <STRONG>read</STRONG>  <EM>call to the API</EM> to initialize the mechanism. The timer is then reset by each succeeding
character. If no characters are received, the read will block indefinitely. 


<P>

Setting <STRONG>is_read_interval</STRONG> to <CODE>0xffffffff</CODE> will do a non-blocking read. The <STRONG>ReadFile</STRONG> returns immediately whether or not any characters are actually read. This
replicates the behavior of the API.


<P>

The other model defines the total time allowed to complete the operation. A
fixed overhead time is added to the product of bytes and per_byte_time. A
wide variety of timeout options can be defined by selecting the three
parameters: fixed, each, and size.


<P>

Read_Total = <STRONG>is_read_const_time</STRONG> + (<STRONG>is_read_char_time</STRONG> * bytes_to_read)


<P>

Write_Total = <STRONG>is_write_const_time</STRONG> + (<STRONG>is_write_char_time</STRONG> * bytes_to_write)


<P>

When reading a known number of characters, the <EM>Read_Total</EM> mechanism is recommended. This mechanism <EM>MUST</EM> be used with
<EM>Win32::SerialPort tied FileHandles</EM> because the tie methods can make multiple internal API calls. The <EM>Read_Interval</EM> mechanism is suitable for a <STRONG>read_bg</STRONG> method that expects a response of variable or unknown size. You should then
also set a long <EM>Read_Total</EM> timeout as a ``backup'' in case no bytes are received.


<P>

</DL>
<P>
<HR>
<H2><A NAME="Exports">Exports

</A></H2>
Nothing is exported by default. The following tags can be used to have
large sets of symbols exported:


<P>

<DL>
<DT><STRONG><A NAME="item__PARAM">:PARAM

</A></STRONG><DD>
Utility subroutines and constants for parameter setting and test:


<P>

<PRE>        LONGsize        SHORTsize       nocarp          yes_true
        OS_Error        internal_buffer
</PRE>

<P>

<DT><STRONG><A NAME="item__STAT">:STAT

</A></STRONG><DD>
Serial communications status constants. Included are the constants for
ascertaining why a transmission is blocked:


<P>

<PRE>        BM_fCtsHold     BM_fDsrHold     BM_fRlsdHold    BM_fXoffHold
        BM_fXoffSent    BM_fEof         BM_fTxim        BM_AllBits
</PRE>

<P>

Which incoming bits are active:


<P>

<PRE>        MS_CTS_ON       MS_DSR_ON       MS_RING_ON      MS_RLSD_ON
</PRE>

<P>

What hardware errors have been detected:


<P>

<PRE>        CE_RXOVER       CE_OVERRUN      CE_RXPARITY     CE_FRAME
        CE_BREAK        CE_TXFULL       CE_MODE
</PRE>

<P>

Offsets into the array returned by <STRONG>status:</STRONG>




<P>

<PRE>        ST_BLOCK        ST_INPUT        ST_OUTPUT       ST_ERROR
</PRE>

<P>

<DT><STRONG><A NAME="item__RAW">:RAW

</A></STRONG><DD>
The constants and wrapper methods for low-level API calls. Details of these
methods may change with testing. Some may be inherited from Win32API::File
when that becomes available.


<P>

<PRE>  $result=ClearCommError($handle, $Error_BitMask_p, $CommStatus);
  $result=ClearCommBreak($handle);
  $result=SetCommBreak($handle);
  $result=GetCommModemStatus($handle, $ModemStatus);
  $result=GetCommProperties($handle, $CommProperties);
  $result=GetCommState($handle, $DCB_Buffer);
  $result=SetCommState($handle, $DCB_Buffer);
  $result=SetupComm($handle, $in_buf_size, $out_buf_size);
  $result=ReadFile($handle, $buffer, $wanted, $got, $template);
  $result=WriteFile($handle, $buffer, $size, $count, $template);
</PRE>

<P>

<PRE>  $result=GetCommTimeouts($handle, $CommTimeOuts);
  $result=SetCommTimeouts($handle, $CommTimeOuts);
  $result=EscapeCommFunction($handle, $Func_ID);
  $result=GetCommConfig($handle, $CommConfig, $Size);
  $result=SetCommConfig($handle, $CommConfig, $Size);
  $result=PurgeComm($handle, $flags);
</PRE>

<P>

<PRE>  $result=GetCommMask($handle, $Event_Bitmask);
  $result=SetCommMask($handle, $Event_Bitmask);
  $hEvent=CreateEvent($security, $reset_req, $initial, $name);
  $handle=CreateFile($file, $access, $share, $security,
                     $creation, $flags, $template);
  $result=CloseHandle($handle);
  $result=ResetEvent($hEvent);
  $result=TransmitCommChar($handle, $char);
  $result=WaitCommEvent($handle, $Event_Bitmask, $lpOverlapped);
  $result=GetOverlappedResult($handle, $lpOverlapped, $count, $bool);
</PRE>

<P>

Flags used by <STRONG>PurgeComm:</STRONG>




<P>

<PRE>        PURGE_TXABORT   PURGE_RXABORT   PURGE_TXCLEAR   PURGE_RXCLEAR
</PRE>

<P>

Function IDs used by EscapeCommFunction:


<P>

<PRE>        SETXOFF         SETXON          SETRTS          CLRRTS
        SETDTR          CLRDTR          SETBREAK        CLRBREAK
</PRE>

<P>

Events used by <STRONG>WaitCommEvent:</STRONG>




<P>

<PRE>        EV_RXCHAR       EV_RXFLAG       EV_TXEMPTY      EV_CTS
        EV_DSR          EV_RLSD         EV_BREAK        EV_ERR
        EV_RING         EV_PERR         EV_RX80FULL     EV_EVENT1
        EV_EVENT2
</PRE>

<P>

Errors specific to <STRONG>GetOverlappedResult:</STRONG>




<P>

<PRE>        ERROR_IO_INCOMPLETE     ERROR_IO_PENDING
</PRE>

<P>

<DT><STRONG><A NAME="item__COMMPROP">:COMMPROP

</A></STRONG><DD>
The constants for the <EM>CommProperties structure</EM> returned by
<STRONG>GetCommProperties</STRONG>. Included mostly for completeness.


<P>

<PRE>        BAUD_USER       BAUD_075        BAUD_110        BAUD_134_5
        BAUD_150        BAUD_300        BAUD_600        BAUD_1200
        BAUD_1800       BAUD_2400       BAUD_4800       BAUD_7200
        BAUD_9600       BAUD_14400      BAUD_19200      BAUD_38400
        BAUD_56K        BAUD_57600      BAUD_115200     BAUD_128K
</PRE>

<P>

<PRE>        PST_FAX         PST_LAT         PST_MODEM       PST_PARALLELPORT
        PST_RS232       PST_RS422       PST_X25         PST_NETWORK_BRIDGE
        PST_RS423       PST_RS449       PST_SCANNER     PST_TCPIP_TELNET
        PST_UNSPECIFIED
</PRE>

<P>

<PRE>        PCF_INTTIMEOUTS         PCF_PARITY_CHECK        PCF_16BITMODE
        PCF_DTRDSR              PCF_SPECIALCHARS        PCF_RLSD
        PCF_RTSCTS              PCF_SETXCHAR            PCF_TOTALTIMEOUTS
        PCF_XONXOFF
</PRE>

<P>

<PRE>        SP_BAUD         SP_DATABITS     SP_HANDSHAKING  SP_PARITY
        SP_RLSD         SP_STOPBITS     SP_SERIALCOMM   SP_PARITY_CHECK
</PRE>

<P>

<PRE>        DATABITS_5      DATABITS_6      DATABITS_7      DATABITS_8
        DATABITS_16     DATABITS_16X
</PRE>

<P>

<PRE>        STOPBITS_10     STOPBITS_15     STOPBITS_20
</PRE>

<P>

<PRE>        PARITY_SPACE    PARITY_NONE     PARITY_ODD      PARITY_EVEN
        PARITY_MARK
</PRE>

<P>

<PRE>        COMMPROP_INITIALIZED
</PRE>

<P>

<DT><STRONG><A NAME="item__DCB">:DCB

</A></STRONG><DD>
The constants for the <EM>Device Control Block</EM> returned by <STRONG>GetCommState</STRONG>
and updated by <STRONG>SetCommState</STRONG>. Again, included mostly for completeness. But there are some combinations
of ``FM_f'' settings which are not currently supported by high-level
commands. If you need one of those, please report the lack as a bug.


<P>

<PRE>        CBR_110         CBR_300         CBR_600         CBR_1200
        CBR_2400        CBR_4800        CBR_9600        CBR_14400
        CBR_19200       CBR_38400       CBR_56000       CBR_57600
        CBR_115200      CBR_128000      CBR_256000
</PRE>

<P>

<PRE>        DTR_CONTROL_DISABLE     DTR_CONTROL_ENABLE      DTR_CONTROL_HANDSHAKE
        RTS_CONTROL_DISABLE     RTS_CONTROL_ENABLE      RTS_CONTROL_HANDSHAKE
        RTS_CONTROL_TOGGLE
</PRE>

<P>

<PRE>        EVENPARITY      MARKPARITY      NOPARITY        ODDPARITY
        SPACEPARITY
</PRE>

<P>

<PRE>        ONESTOPBIT      ONE5STOPBITS    TWOSTOPBITS
</PRE>

<P>

<PRE>        FM_fBinary              FM_fParity              FM_fOutxCtsFlow
        FM_fOutxDsrFlow         FM_fDtrControl          FM_fDsrSensitivity
        FM_fTXContinueOnXoff    FM_fOutX                FM_fInX
        FM_fErrorChar           FM_fNull                FM_fRtsControl
        FM_fAbortOnError        FM_fDummy2
</PRE>

<P>

<DT><STRONG><A NAME="item__ALL">:ALL

</A></STRONG><DD>
All of the above. Except for the <EM>test suite</EM>, there is not really a good reason to do this.


<P>

</DL>
<P>
<HR>
<H1><A NAME="NOTES">NOTES

</A></H1>
The object returned by <STRONG>new</STRONG> is NOT a <EM>Filehandle</EM>. You will be disappointed if you try to use it as one.


<P>

e.g. the following is WRONG!!____<CODE>print $PortObj "some text";</CODE>




<P>

<EM>Win32::SerialPort</EM> supports accessing ports via <EM>Tied Filehandles</EM>.


<P>

An important note about Win32 filenames. The reserved device names such as <CODE><PRE> COM1, AUX, LPT1, CON, PRN 
</PRE>
</CODE> can NOT be used as filenames. Hence
<EM>"COM2.cfg"</EM> would not be usable for <STRONG>$Configuration_File_Name</STRONG>.


<P>

This module uses Win32::API extensively. The raw API calls are <STRONG>very</STRONG>
unforgiving. You will certainly want to start perl with the <STRONG>-w</STRONG> switch. If you can, <STRONG>use strict</STRONG> as well. Try to ferret out all the syntax and usage problems BEFORE issuing
the API calls (many of which modify tuning constants in hardware device
drivers....not where you want to look for bugs).


<P>

Thanks to Ken White for testing on NT.


<P>

<P>
<HR>
<H1><A NAME="KNOWN_LIMITATIONS">KNOWN LIMITATIONS

</A></H1>
The current version of the module has been designed for testing using the
ActiveState and Core (GS 5.004_02) ports of Perl for Win32 without
requiring a compiler or using XS. In every case, compatibility has been
selected over performance. Since everything is (sometimes convoluted but
still pure) Perl, you can fix flaws and change limits if required. But
please file a bug report if you do. This module has been tested with each
of the binary perl versions for which Win32::API is supported: AS builds
315, 316, and 500-509 and GS 5.004_02. It has only been tested on Intel
hardware.


<P>

<DL>
<DT><STRONG><A NAME="item_Tutorial">Tutorial

</A></STRONG><DD>
With all the options, this module needs a good tutorial. It doesn't have a
complete one yet. A <EM>"How to get started"</EM> tutorial appeared
<STRONG>The Perl Journal #13</STRONG> (March 1999). The demo programs are a good starting point for additional
examples.


<P>

<DT><STRONG><A NAME="item_Buffers">Buffers

</A></STRONG><DD>
The size of the Win32 buffers are selectable with <STRONG>is_buffers</STRONG>. But each read method currently uses a fixed internal buffer of 4096
bytes. This can be changed in the module source. The read-only <STRONG>internal_buffer</STRONG> method will give the current size. There are other fixed internal buffers
as well. But no one has needed to change those. The XS version will support
dynamic buffer sizing.


<P>

<DT><STRONG><A NAME="item_Modems">Modems

</A></STRONG><DD>
Lots of modem-specific options are not supported. The same is true of TAPI,
MAPI. <EM>API Wizards</EM> are welcome to contribute.


<P>

<DT><STRONG><A NAME="item_API">API Options

</A></STRONG><DD>
Lots of options are just ``passed through from the API''. Some probably
shouldn't be used together. The module validates the obvious choices when
possible. For something really fancy, you may need additional API
documentation. Available from <EM>Micro$oft Pre$$</EM>.


<P>

</DL>
<P>
<HR>
<H1><A NAME="BUGS">BUGS

</A></H1>
ActiveState ports of Perl for Win32 before build 500 do not support the
tools for building extensions and so will not support later versions of
this extension. In particular, the automated install and test scripts in
this distribution work differently with ActiveState builds 3xx.


<P>

There is no parameter checking on the ``raw'' API calls. You probably
should be familiar with using the calls in ``C'' before doing much
experimenting.


<P>

On Win32, a port must <STRONG>close</STRONG> before it can be reopened again by the same process. If a physical port can
be accessed using more than one name (see above), all names are treated as
one. The perl script can also be run multiple times within a single batch
file or shell script. The <EM>Makefile.PL</EM>
spawns subshells with backticks to run the test suite on Perl 5.003 - ugly,
but it works.


<P>

On NT, a <STRONG>read_done</STRONG> or <STRONG>write_done</STRONG> returns <EM>False</EM> if a background operation is aborted by a purge. Win95 returns <EM>True</EM>.


<P>

EXTENDED_OS_ERROR ($^E) is not supported by the binary ports before 5.005.
It ``sort-of-tracks'' <STRONG>$!</STRONG> in 5.003 and 5.004, but YMMV.


<P>

A few NT systems seem to set <STRONG>can_parity_enable</STRONG> true, but do not actually support setting <STRONG>is_parity_enable</STRONG>. This may be a characteristic of certain third-party serial drivers. Or a
Microsoft bug. I have not been able to reproduce it on my system.


<P>

__Please send comments and bug reports to <A
HREF="MAILTO:wcbirthisel@alum.mit.edu.">wcbirthisel@alum.mit.edu.</A>


<P>

<P>
<HR>
<H1><A NAME="AUTHORS">AUTHORS

</A></H1>
Bill Birthisel, <A
HREF="MAILTO:wcbirthisel@alum.mit.edu,">wcbirthisel@alum.mit.edu,</A> <A
HREF="http://members.aol.com/Bbirthisel/.">http://members.aol.com/Bbirthisel/.</A>



<P>

Tye McQueen, <A HREF="MAILTO:tye@metronet.com,">tye@metronet.com,</A> <A
HREF="http://www.metronet.com/~tye/.">http://www.metronet.com/~tye/.</A>


<P>

<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO

</A></H1>
Wi32::SerialPort - High-level user interface/front-end for this module


<P>

Win32API::File <EM>when available</EM>




<P>

Win32::API - Aldo Calpini's ``Magic'', <A
HREF="http://www.divinf.it/dada/perl/">http://www.divinf.it/dada/perl/</A>


<P>

Perltoot.xxx - Tom (Christiansen)'s Object-Oriented Tutorial


<P>

<P>
<HR>
<H1><A NAME="COPYRIGHT">COPYRIGHT

</A></H1>
Copyright (C) 1999, Bill Birthisel. All rights reserved.


<P>

This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


<P>

<P>
<HR>
<H2><A NAME="COMPATIBILITY">COMPATIBILITY

</A></H2>
Most of the code in this module has been stable since version 0.12. Except
for items indicated as <EM>Experimental</EM>, I do not expect functional changes which are not fully backwards
compatible. However, Version 0.16 removes the ``dummy (0, 1) list'' which
was returned by many binary methods in case they were called in list
context. I do not know of any use outside the test suite for that feature.


<P>

Version 0.12 added an <EM>Install.PL</EM> script to put modules into the documented Namespaces. The script uses <EM>MakeMaker</EM> tools not available in ActiveState 3xx builds. Users of those builds will
need to install differently (see README). Programs in the test suite are
modified for the current version. Additions to the configurtion files
generated by
<STRONG>save</STRONG> prevent those created by Version 0.15 from being used by earlier Versions.
4 November 1999.


<P>

</DL>
    </BODY>

    </HTML>