Code Examples
  Home arrow Code Examples arrow Page 6 - Writing a Serial Communication Library for...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Writing a Serial Communication Library for Windows
By: Digvijay Chauhan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 85
    2004-09-28

    Table of Contents:
  • Writing a Serial Communication Library for Windows
  • Opening the Selected Serial Port
  • CSerialComm Class
  • DWORD BaudRate, Parity
  • Write and Read Timeouts
  • How To Use 'CSerialComm' Class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Writing a Serial Communication Library for Windows - How To Use 'CSerialComm' Class


    (Page 6 of 6 )

    Take the following steps to use the CSerialComm class

    • Copy the SerialCom.h & SerialCom.cpp files and paste into your project directory.

    • In your VC++ IDE, add the files to your project

    • Add the line #include "SerialComm.h" in your dialog's header file

    • Create an instance of the CSerialComm class in your dialog's header file.

    You can now call the member functions of CSerialComm when you want to communicate with external device as shown below.

    In Your dialog's .cpp File:

        // Open Communication Port. Please check functions return value to ensure whether
        // Port opened successfully.
        port.OpenPort( );
       
        // Configure Port for Communication. Please check functions return value to
        // ensure whether Port is configured  successfully.
        port.ConfigurePort( ); 

        // Set communication time outs. Please check functions return
        // value to ensure whether communication time outs configured 
        // successfully.
        port.SetCommunicationTimeouts( );
         
        // call this function in a loop till all bytes are written. Please check
        // functions return value to ensure whether Write operation completed 
        // successfully.
        port.WriteByte();
         
        // call this function in a loop till all bytes are received. Please check
        // functions return value to ensure whether Read operation completed 
        // successfully or a time out occurred.
        port.ReadByte( );

        // Call this function to close the handle to the port.
        // Process the received Data
        port.ClosePort();

    If you decide to use the extension DLL directly just include the library SCommLib.lib file in the Project | Settings | Link tab as shown in the figure below.

    Serial Data Communications Library

    Figure 2: Setting the import Library

    Next include the SerialComm.h file in your project (because it contains the class definition for the library).Now you’re free to make any instance of the class and the compiler would compile the code happily for you.

    Source Code

    You may download the source code here. It also contains a Compiled DLL that exports the CSerialComm class that will ease development of serial communication applications using MFC.

    You’re free to use the code in any way. I hope you found the article informative. You may contact me at digvijay.chauhan@rediffmail.com for any comments and suggestions.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article plus its associated download/source code are one of the few a pages on...
     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT