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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 81
    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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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

    - Handling Animations and Bitmaps Using GDI+ f...
    - Download a Web Page using the WebClient
    - Creating a Chart using Data from a Database ...
    - The Basics of Charting with the MS Chart Con...
    - Searching Body Text with textRange: Enter th...
    - Searching Body Text with textRange: Building...
    - Searching Body Text with textRange, part 1: ...
    - First Steps in Programming
    - Programming in C
    - Quick Introduction to ASF,ASX, and Networkin...
    - SatView: Pointer Perfect, Part 2: Constructi...
    - SatView: Pointer Perfect, Part 1
    - Style Case Studies: Construction Unions
    - Creating an Engine for Games for Windows
    - Style Case Studies: Generic Callbacks





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway