CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2003
    Location
    The Netherlands
    Posts
    586

    serial port communication problem

    Hi guys, i have a problem with the serial port communication. I am trying to read from the serial port, but it appears that only 14 bytes can be read at once. This is probably the size of the serial port receive buffer.
    I have a serial extension card in my pc which adds 2 serial ports. With a null modem cable i can send data from one serial port to the other.

    Code:
    m_SerialPort.SetCommMask(EV_RXCHAR);
    
    	if(m_SerialPort.WaitCommEvent(&dwEventMask, NULL))
    	{
    		unsigned char szBuf;
    		DWORD dwIncomingReadSize;
    		DWORD dwSize = 0;
    		int iByteCount = 0;
    
    		do
    		{
    			if(m_SerialPort.ReadData(&szBuf, 1, &dwIncomingReadSize) != 0)
    			{
    				if(dwIncomingReadSize > 0)
    				{
    					dwSize += dwIncomingReadSize;
    					m_pReceiveBuf[iByteCount] = szBuf;
    					iByteCount++;
    				}
    			}
    			else
    			{
    				// Handle error condition
    			}
    		}while( (dwIncomingReadSize > 0) && (iByteCount < RECEIVE_BUF_SIZE) );
    
    		*dwReceivedBytes = iByteCount;
    	}
    If i send 20 bytes i want to read 20 bytes at the other side. Does anybody have a solution for this problem?
    Time is fun when you're having flies

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: serial port communication problem

    It is completely unclear what m_SerialPort is and where and how you are using your code snippet.

    You may want take a look at "Serial Communications in Win32" article and MTTTY sample in MSDN and J.Newcomer's essay Serial Port I/O

  3. #3
    Join Date
    Mar 2003
    Location
    The Netherlands
    Posts
    586

    Re: serial port communication problem

    Thanks for the link Victor, i am studying it. I am running into a little problem here. How is a shutdown event created? It is passed as one of the parameters to the thread and i cannot figure out where it is coming from.
    Time is fun when you're having flies

  4. #4
    Join Date
    May 2005
    Posts
    364

    Re: serial port communication problem

    What serial port r u using RS232 or RS422? or the one which is present in all systems (COM)
    Dan

  5. #5
    Join Date
    Feb 2005
    Location
    Pune (India)
    Posts
    644

    Thumbs up Re: serial port communication problem

    Hi,

    have you checked with another side , i.e How many bytes sent actually ?


    -Anant
    "Devise the simplest possible solution that solves the problems"

  6. #6
    Join Date
    Mar 2003
    Location
    The Netherlands
    Posts
    586

    Re: serial port communication problem

    Thanks for the link Victor, i am studying it. I am running into a little problem here. How is a shutdown event created? It is passed as one of the parameters to the thread and i cannot figure out where it is coming from.
    Time is fun when you're having flies

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured