📄 indexv2.html
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="Free resources for developers">
<meta name="keywords" content="Serial Communication WIN32 free software source C C++ JAVA hardware interface">
<meta name="copyright" content="copyright (c) 2001 TETRAEDRE Sarl">
<meta name="GENERATOR" content="Mozilla/4.77 [en] (Windows NT 5.0; U) [Netscape]">
<meta name="Author" content="thierry@tetraedre.com">
<title>Developer's corner</title>
</head>
<body text="#000000" bgcolor="#D8D2E8" link="#0000EE" vlink="#551A8B" alink="#FF0000" background="background.gif" nosave>
<table BORDER=0 WIDTH="100%" >
<tr VALIGN=BOTTOM>
<td ALIGN=LEFT VALIGN=TOP><img SRC="tetraedre.gif" ALT="ENTER" NOSAVE BORDER=0 height=145 width=145 align=ABSBOTTOM><b><i><a href="http://www.tetraedre.com">Tetraedre
Company</a> - embedded
solutions</i></b></td>
<td><a href="../index.php3">Back</a></td>
<td><a href="../../index.php3">Home</a></td>
</tr>
</table>
<hr ALIGN=LEFT SIZE=3 WIDTH="100%">
<h1>
Serial Communication for WIN32</h1>
<blockquote>by <a href="mailto:thierry@tetraedre.com">Thierry Schneider</a>,
April 8th 2001
<br>revised April 14th 2001, minor corrections
<br>revised April 24th 2001, modification for Visual C++
<br>revised April 29th 2001, correction of bugs that occured during reconnection
<br>revised May 14th 2001, The sertest.cpp example contains a prototype
error for Connect()
<h3>
<font color="#000000">February 1st 2002, </font><font color="#FF6666">New
Version (V2.0) completely updated. Handles modems directly</font></h3>
<h4>
Foreword: If you experience any problem using this software, please be
sure that you have the latest version. Check our web site <a href="http://www.tetraedre.com">www.tetraedre.com
</a>for
an updated version of the software. <br>
Otherwise report any bug to the address above or check the FAQ</h4>
<p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p>Here it is. Finally, I think I've reached the final step in serial communication
programmation on Win32. This new version (V2.0) is much more structured
when the previous one. I can handle either 1-byte exchange (like a UART)
or arrays of byte. The application is 100% event-driven on the user side
(the object itself is using one thread). And more important of all, this
new version handles also modem specific signals like CD and RI. CD allows
you to know if the modem is connected (to the other modem) or if you are
in command mode. And RI is the RING indicator.
<br>With this version, you can make whatever you like (like for example
implementing PPP or simulating a microcontroller's UART)
<br>
<h3>
Download</h3>
I've removed the "non event-driven" version since I believe it is not so
usefull. Anyway, you can still download the V1.x package here (<a href="serial.zip">serial.zip</a>).
The version 2 can be downloaded here (<a href="serial2.zip">serial2.zip</a>).
<br>
<h3>
Feedback</h3>
I hope that this version will be the ultimate library for the serial port.
I hope to receive your comments about it. Since the version 1.x was downloaded
more than 4'000 times in 8 months, I hope this one will be even better.
If you like this software, please let me know, 'cause I like to know what
people think of my work.
<br>
<p>Please find hereafter the updated version of the documentation.
<br>
<p>Bye
<br><a href="mailto:thierry@tetraedre.com">Thierry Schneider</a>
<br> </blockquote>
<hr ALIGN=LEFT SIZE=3 WIDTH="100%">
<h2>
Documentation</h2>
<blockquote>Each programmer knows that accessing the hardware ports of
a computer is getting more and more complicated. The software presented
here intends to ease the development of applications using the serial port
(COM) on computer running Windows 32-bits operating systems.
<p>Allen Denver, from the Microsoft Windows Developer Support wrote one
of the only technical article describing in details how to use the serial
port under Win32. This article can be downloaded on Microsoft's web site.
A copy of this article can also be found <a href="msdn_serial.htm">here</a>.
<br>
<p>From that article, I've written two different software packages. You
are currently reading the documentation of version 2.x which is an "event-driven"
communication component. I define it event-driven since there is no busy
loop, no blocking waiting inside the whole software. Everything is done
on events, and can thus be very easily integrated inside a Windows application
(with user interface).
<p>All software and documentation described here can be downloaded directly
here : <a href="serial2.zip">serial2.zip</a>
<p>This software was developed with C++ Borland Builder 5 and tested also
with Visual C++ 6.
<p>If you have questions, don't hesitate to send me an email (<a href="mailto:developer@tetraedre.com">developer@tetraedre.com</a>)
and/or visit our website (<a href="http://www.tetraedre.com">www.tetraedre.com</a>)
to read the FAQ (look inside the developer's corner)
<p>
<hr ALIGN=LEFT SIZE=3 WIDTH="100%">
<h3>
Compilation with Borland C++ Builder</h3>
The ZIP file contains two Borland C++ project files (serialtest.bpr). Simply
open them, compile, run and enjoy !
<h3>
Compilation with Microsoft Visual C++</h3>
The project was originally created to be compiled with the Borland C++
Builder development environment. In order to permit compilation with
Microsoft's Visual C++, I've modified a little the source code. A "#ifdef
__BORLANDC__" has been inserted in the header part of the <i>serialtest.cpp</i>
file in order to skip some Borland's specific pre-compiler commands.
<p><b>IMPORTANT</b>
<br>But more important. The event-driven application uses multithreading
in order to generate the events. So Visual C++ projects that use multithreading
must be compiled with the appropriate setting. In your project settings,
you MUST choose the multithreaded run-time library, otherwise the programme
will not compile
<br>
<br>
<blockquote><tt>Project settings</tt>
<br><tt> |</tt>
<br><tt> *--- C/C++</tt>
<br><tt> |</tt>
<br><tt> *---
Code generation</tt>
<br><tt>
|</tt>
<br><tt>
*---- Use run-time library</tt>
<br><tt>
|</tt>
<br><tt>
*---- Multithreaded</tt></blockquote>
<hr WIDTH="100%">
<br>
<h3>
Events description</h3>
Before going into details, I would like to describe a little bit the concept
that I used here: In order to work with the serial port, you need to create
a Tserial_event object and configure it. In particular you must specify
a "manager". This is a callback function used by the serial object to notify
events. Seven kind of events can occur:
<ol>
<li>
SERIAL_CONNECTED</li>
<li>
SERIAL_DISCONNECTED</li>
<li>
SERIAL_DATA_SENT</li>
<li>
SERIAL_DATA_ARRIVAL</li>
<li>
SERIAL_RING</li>
<li>
SERIAL_CD_ON</li>
<li>
SERIAL_CD_OFF</li>
</ol>
These events will help managing the serial port (or the modem) successfully
and efficiently. They are also usefull to manipulate input and output message
buffers.
<ol>
<table BORDER >
<tr VALIGN=TOP>
<td>SERIAL_CONNECTED</td>
<td>This event is generated when the serial port is opened and ready to
work. If the port is not opened successfully, the <b>connect </b>returns
directly with an error value</td>
</tr>
<tr VALIGN=TOP>
<td>SERIAL_DISCONNECTED</td>
<td>This event is generated when the serial communication is closed. This
might occur either after you called <b>disconnect</b> or if an error occured</td>
</tr>
<tr VALIGN=TOP>
<td>SERIAL_DATA_SENT</td>
<td>This event is generated when the data you want to transmit have been
passed to the device driver (this doesn't mean that they reached the other
side of the serial cable). This event will allow you to send further outgoing
message and thus avoiding output buffer overflow. If you send only one
byte after the other, this event is similar to the UART's "TX EMPTY" IRQ.</td>
</tr>
<tr VALIGN=TOP>
<td>SERIAL_DATA_ARRIVAL</td>
<td>This event is generated when data are received. You can specify how
much data you would like to receive by calling <b>setRxSize</b>, but this
doesn't mean that you will receive that number of data. Once again, if
you specify an RxSize of 1, then the event is similar to the UART's "RX
FULL" IRQ.</td>
</tr>
<tr VALIGN=TOP>
<td>SERIAL_RING</td>
<td>This event is generated when a RING occurs on your telephone line (if
you have a modem and if you specified to notify modem's events).</td>
</tr>
<tr VALIGN=TOP>
<td>SERIAL_CD_ON</td>
<td>This event is generated when the modem is connected to the other modem
(for example after an "ATDT" command). For example, if you want to implement
PPP, this will tell you if you can send modem's command (ATZ,...) or if
you can send PPP messages.</td>
</tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -