Thread: clear serial port??

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

    clear serial port??

    Hi guys:

    Sometimes when I transmmit the data from one com port to the other. And there are always "something" left in the com port even after I closed the program. I've to restart the computer then. It is kinda of strange, So is there function or way to clear the serial port after the program closed?

    I would appreciate for any 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
    Check out the code I attached in this thread, SFile.zip.
    Use the object if you like, otherwise, just take a look at the PurgeComm() method.

    gg

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Hi Codeplug
    When I was runing the program, I got such error:

    Compiling...
    SFile.cpp
    Linking...
    LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
    Debug/SFile.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    Creating browse info file...

    SFile.exe - 2 error(s), 0 warning(s)

    What shall I do? Thanks
    Don't laugh at me,I am just a SuperNewbie.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    SFile.zip only contains the SFile class. There is no main() or WinMain() that actually uses it.

    gg

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Thanks, but BTW: in

    BOOL ReadFile(
    HANDLE hFile, // handle to file
    LPVOID lpBuffer, // data buffer
    DWORD nNumberOfBytesToRead, // number of bytes to read
    LPDWORD lpNumberOfBytesRead, // number of bytes read
    LPOVERLAPPED lpOverlapped // overlapped buffer
    )

    is it always nNumberOfBytesToRead = lpNumberOfBytesRead??

    for example if I set ReadFile() to read 10 bytes at a time from input buffer of COM1, so lpNumberOfBytesRead is 10 bytes too?
    Am I right??

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

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    *lpNumberOfBytesRead is an output parameter and gets set to 0 first thing by ReadFile().
    When ReadFile() returns, *lpNumberOfBytesRead will be 10 only if it read 10 bytes.

    gg

  7. #7
    Registered User
    Join Date
    Apr 2011
    Posts
    1
    Hey I was jsut wondering where you got this class from? Or did you write it yourself?

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. need guidance to connect to serial port
    By gnychis in forum Linux Programming
    Replies: 1
    Last Post: 06-02-2005, 10:10 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