Code Examples
  Home arrow Code Examples arrow Page 4 - 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 / 86
    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 - DWORD BaudRate, Parity


    (Page 4 of 6 )

    DWORD BaudRate

    It represents the Baud rate for communication supported by external device. For example, you can give this parameter as 9600 or CBR_9600 for a BaudRate of 9600. The available Standard Baud rates supported as defined in Winbase.h are:

    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

    BYTE ByteSize

    This represents the number of bits in the bytes transmitted and received. Standard values are 8 or 4.

    DWORD fParity

    Specifies whether parity checking is enabled. If this parameter is TRUE<code>, parity checking is performed and errors are reported. If <code>FALSE no parity checking is performed.

    BYTE Parity

    Specifies the parity scheme to be used. This member can be one of the following values:

    EVENPARITY
    MARKPARITY
    NOPARITY
    ODDPARITY
    SPACEPARITY
    BYTE StopBits

    Specifies the number of stop bits to be used. This member can be one of the following values:

    ONESTOPBIT
    ONE5STOPBITS
    TWOSTOPBITS
    NOTE

    The ConfigurePort() function is written on the assumption that the communication flow control is completely controlled on the basis of the protocol supported by the external device. It transmits and receives data without checking CTS/RTS and Xon/Xoff hardware flow control. You can modify this to your requirements by changing the values of the members of DCB which are responsible for it, in the implementation of ConfigurePort() in SerialComm.cpp.

    ConfigurePort(CBR_9600, 8, true, EVENPARITY , ONESTOPBIT )

    BOOL CSerialComm::SetCommunicationTimeouts(DWORD ReadIntervalTimeout,
    DWORD ReadTotalTimeoutMultiplier,
    DWORD ReadTotalTimeoutConstant,
    DWORD WriteTotalTimeoutMultiplier,
    DWORD WriteTotalTimeoutConstant)
    {
    if((m_bPortReady = GetCommTimeouts (m_hComm, &m_CommTimeouts))==0)
    {
    return FALSE;
    }

    m_CommTimeouts.ReadIntervalTimeout =ReadIntervalTimeout;
    m_CommTimeouts.ReadTotalTimeoutConstant =ReadTotalTimeoutConstant;
    m_CommTimeouts.ReadTotalTimeoutMultiplier =ReadTotalTimeoutMultiplier;
    m_CommTimeouts.WriteTotalTimeoutConstant = WriteTotalTimeoutConstant;
    m_CommTimeouts.WriteTotalTimeoutMultiplier =WriteTotalTimeoutMultiplier;
    m_bPortReady = SetCommTimeouts (m_hComm, &m_CommTimeouts);
    if(m_bPortReady ==0)
    {
    ::MessageBox(NULL,_T("SetCommTimeouts function failed"),_T("Com Port Error"),MB_OK | MB_ICONERROR);
    CloseHandle(m_hComm);
    return FALSE;
    }
    return TRUE;
    }

    The SetCommunicationTimeouts() member function sets the write and read timeouts for data transmission. The parameters to be passed to this function are given next.

    More Code Examples Articles
    More By Digvijay Chauhan


       · 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 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek