Thread: serial port??

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    serial port??

    Hi:

    If I use COM1(hCom1) write data and COM2(hCom2) to receive data, so:

    Code:
    #define input_Buffer 2 //for hCom2 input buffer
    //#define output_Buffer 10
    
    char valRead[20]={0};
    
    SetupComm(hCom2, input_Buffer, output_Buffer)
    
    /* hCom2 only can have only 2 bytes receved at time, right??*/
    
    /*assume that there are 100 bytes already in hCom1 and I use one cable to connect COM1 and COM2 with each other*/
    
    /*now I start reading from COM2*/
    
    ReadFile(hCom2, &valRead, 10, &dwRead, NULL);
    the problem now is:

    I think there must be only 2 bytes in buffer valRead cause the maximum input buffer in hCom2 is 2 bytes only. But always there are 10 bytes in valRead, Why??? and it still is not working with

    dcb.ByteSize= 2;

    .
    Thanks for help.
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Don't call SetupComm(). The device driver will use setup appropriate default values for you.

    You don't want to limit the receive buffer for your port. Just read 2 bytes at a time if that's what you're trying to accomplish.

    Use the SFile object I showed you in your other thread, or use is as a reference for Win32 serial communications.

    gg

  3. #3

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. serial port to poll on request
    By infineonintern in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 06:52 AM
  2. Can't Read From Serial Port
    By HalNineThousand in forum Linux Programming
    Replies: 14
    Last Post: 03-20-2008, 05:56 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Reading and writing to a serial port
    By SwarfEye in forum C Programming
    Replies: 2
    Last Post: 08-18-2006, 12:28 AM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM