Click here to Skip to main content
15,890,670 members
Articles / Desktop Programming / MFC
Article

Serial communication for Win32 with modem support

Rate me:
Please Sign up or sign in to vote.
4.95/5 (15 votes)
13 Feb 20021 min read 184.2K   5.5K   65   31
Free source code (C++) for WIN32 serial communication. Manages also a modem. Example project provided.

Introduction

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 than 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. With this version, you can make whatever you like (like for example implementing PPP or simulating a microcontroller's UART)

Links

Download

I've removed the "non event-driven" version since I believe it is not so useful. Anyway, you can still download the V1.x package here (serial.zip). The version 2 can be downloaded here serial2.zip.

Feedback

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 4000 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.

Bye

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWhat about sending HexData Pin
MGutmann18-Mar-04 3:10
MGutmann18-Mar-04 3:10 
AnswerRe: What about sending HexData Pin
Thierry Schneider22-Mar-04 21:19
Thierry Schneider22-Mar-04 21:19 
GeneralSimple Serial Pin
HJYap11-Feb-04 21:09
HJYap11-Feb-04 21:09 
QuestionSounds useful, but how can caller know the size it would receive? Pin
jason lue7-May-03 9:05
jason lue7-May-03 9:05 
AnswerRe: Sounds useful, but how can caller know the size it would receive? Pin
Thierry Schneider7-May-03 23:49
Thierry Schneider7-May-03 23:49 
GeneralRe: Sounds useful, but how can caller know the size it would receive? Pin
jason lue10-May-03 13:43
jason lue10-May-03 13:43 
GeneralRe: Sounds useful, but how can caller know the size it would receive? Pin
Thierry Schneider11-May-03 20:51
Thierry Schneider11-May-03 20:51 
GeneralRe: Sounds useful, but how can caller know the size it would receive? Pin
jason lue12-May-03 4:23
jason lue12-May-03 4:23 
Thank you Thierry. Your advice is really valuable to me.

In my application, I have to relay TCP packets secretly on a lower level to a Serially connected device, which is actually a board with our chip on it. We even have a file system on the board so I can expect the data are huge compared to your application.

As I got information from GetCommProperties(), the internal serial packet size is 64 and the driver's receive buffer is typically 4k. While the TCP packet is internally 1518 on ethernet. SPEED really talks except RELIABILITY.

In your proposal, you poll the receiving queue periodically with getNbrOfBytes, because you expect maybe low level error happens and the data don't arrive yet. But how often do you poll? Polling all the time is an inefficient way here for 1% error that may happen. And even you set RxSize to 1, there's still a chance to block anyway. Suppose you expect 1518 bytes from the serial port, I can expect Receiving event would be triggered at least 1518/64=24 times, which doesn't seem to be accepted for only 1 ip packet.

Your concern about receive blocking is really an issue here. And it alarms me a lot. Thank you very much. Maybe we can find another way to handle this issue in a more efficient way?

Here's my preliminary thought:

1. for corrupt data with the expected length. use CRC/Checksum to check integrity.
2. for lost data, set internal ReadFile() waiting with a timeout through SetCommTimeouts(). which is a little longer than a normal receive and check what you're worried about there. As error doesn't happen so frequently, it seems a little efficient than just polling.

What do you think?


GeneralRe: Sounds useful, but how can caller know the size it would receive? Pin
Thierry Schneider12-May-03 4:56
Thierry Schneider12-May-03 4:56 
GeneralRe: Sounds useful, but how can caller know the size it would receive? Pin
Trollslayer31-May-06 1:40
mentorTrollslayer31-May-06 1:40 
GeneralTAPI Pin
Anonymous24-Sep-02 7:01
Anonymous24-Sep-02 7:01 
GeneralSounds useful Pin
Jason Troitsky (was Hattingh)14-Feb-02 6:03
Jason Troitsky (was Hattingh)14-Feb-02 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.