Click here to Skip to main content
15,920,468 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralPutting shortcut to my app in startup folder Pin
BlackDice21-Sep-04 6:59
BlackDice21-Sep-04 6:59 
GeneralRe: Putting shortcut to my app in startup folder Pin
David Crow21-Sep-04 8:46
David Crow21-Sep-04 8:46 
GeneralWatermarking Visual C++ Code Pin
Garth T21-Sep-04 5:45
Garth T21-Sep-04 5:45 
GeneralRe: Watermarking Visual C++ Code Pin
Alexander M.,21-Sep-04 9:49
Alexander M.,21-Sep-04 9:49 
GeneralRe: Watermarking Visual C++ Code Pin
David Crow21-Sep-04 10:31
David Crow21-Sep-04 10:31 
GeneralRe: Watermarking Visual C++ Code Pin
Maximilien21-Sep-04 10:33
Maximilien21-Sep-04 10:33 
GeneralRe: Watermarking Visual C++ Code Pin
David Crow21-Sep-04 10:43
David Crow21-Sep-04 10:43 
Generalserial communication with WIN XP Pin
MMJJ21-Sep-04 5:42
MMJJ21-Sep-04 5:42 
Hello,

I want to receive characters from the serial com with 115200baud. In general my code works but
it has a small bug and I don't know why. Maybe someone can help me.

My problem is: Sending >820bytes by a commercial program to my code, my code receives just 820
bytes only. After the 820bytes WaitCommEvent() doen't recognize any incomming characters any more.

Here is my code:
================

* Open com port:

	m_hPort = CreateFile(sFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);<br />
<br />
	m_DCB.DCBlength = sizeof(DCB);<br />
	GetCommState(m_hPort, &m_DCB);<br />
	<br />
	// Define the serial port characteristics<br />
	m_DCB.BaudRate = m_stCalibration.BaudRate;<br />
	m_DCB.ByteSize = m_stCalibration.ByteSize;<br />
	m_DCB.Parity = m_stCalibration.Parity;<br />
	m_DCB.StopBits = m_stCalibration.StopBits;<br />
	m_DCB.fDtrControl = DTR_CONTROL_DISABLE;<br />
	m_DCB.fRtsControl = RTS_CONTROL_DISABLE;<br />
	SetCommState(m_hPort, &m_DCB);<br />
	SetCommMask(m_hPort, EV_CTS | EV_DSR | EV_ERR | EV_RXCHAR | EV_TXEMPTY);<br />
<br />
	// Create the port listener thread<br />
	m_pListenerThread = AfxBeginThread(listener, this, THREAD_PRIORITY_HIGHEST, 0, CREATE_SUSPENDED, NULL);<br />
<br />
	// Thread created successfully. AutoDelete can only be set, if thread is not running<br />
	m_pListenerThread->m_bAutoDelete = FALSE;<br />
	m_pListenerThread->ResumeThread();


* Read thread function:

listener (void)<br />
{<br />
	DWORD     dwBytesRead;<br />
	DWORD     dwBytesWritten;<br />
	DWORD     dwEventMask;<br />
	BYTE      szBuffer[MSGFRAME_MAX_LEN];<br />
	DWORD     dwOverlappedResult;<br />
	DWORD     dwLastError;<br />
	BOOL      bResult;<br />
	DWORD     dwDontCare;<br />
<br />
	memset(szBuffer, 0, MSGFRAME_MAX_LEN);<br />
<br />
	SetCommMask(m_hPort, EV_RXCHAR);<br />
	WaitCommEvent(m_hPort, &dwEventMask, &m_stReadOver);<br />
	while(1)<br />
	{<br />
		// Wait for incoming bytes<br />
		if(WaitForSingleObject(m_stReadOver.hEvent, 1000) == WAIT_TIMEOUT)<br />
		{<br />
			// No data available on port -> Check if port configuration is to be changed<br />
			checkCalibration();<br />
			continue;<br />
		}<br />
<br />
		dwOverlappedResult = GetOverlappedResult(m_hPort, &m_stReadOver, &dwDontCare, FALSE);<br />
		if (dwOverlappedResult != FALSE)<br />
		{<br />
			// Character(s) received<br />
			bResult = ReadFile(m_hPort, szBuffer, 1, &dwBytesRead, &m_stReadOver);<br />
			if(bResult != FALSE && dwBytesRead == 1)<br />
			{<br />
				// Interface received unformatted data to be forwarded to ring buffer<br />
				m_stRingBuffer.RingBuffer[m_stRingBuffer.dwEnd].yChar = *szBuffer;<br />
				m_stRingBuffer.dwEnd = m_stRingBuffer.RingBuffer[m_stRingBuffer.dwEnd].dwNext;<br />
				m_pRingBufferFilled->SetEvent();<br />
<br />
			}<br />
			else if (bResult == FALSE && GetLastError() != ERROR_IO_PENDING)<br />
			{<br />
				// ReadFile returns error<br />
			}<br />
<br />
			// Reset event and wait for new incomming events/characters<br />
			ResetEvent(m_stReadOver.hEvent);<br />
			WaitCommEvent(m_hPort, &dwEventMask, &m_stReadOver);<br />
		}<br />
	}<br />
	return;<br />
}



Thanks in advance Smile | :) )
Michael
QuestionHow to get the target file for shortcut? Pin
baskarchinnu21-Sep-04 5:32
baskarchinnu21-Sep-04 5:32 
AnswerRe: How to get the target file for shortcut? Pin
David Crow21-Sep-04 8:49
David Crow21-Sep-04 8:49 
GeneralRe: How to get the target file for shortcut? Pin
baskarchinnu23-Sep-04 0:19
baskarchinnu23-Sep-04 0:19 
GeneralRe: How to get the target file for shortcut? Pin
David Crow23-Sep-04 2:27
David Crow23-Sep-04 2:27 
Generaldisplaying an image Pin
jethind21-Sep-04 5:07
jethind21-Sep-04 5:07 
GeneralRe: displaying an image Pin
ThatsAlok23-Sep-04 3:32
ThatsAlok23-Sep-04 3:32 
Question[DLL]: Can I declare a global variable in a DLL? Pin
Behzad Ebrahimi21-Sep-04 4:54
Behzad Ebrahimi21-Sep-04 4:54 
AnswerRe: [DLL]: Can I declare a global variable in a DLL? Pin
David Crow21-Sep-04 5:33
David Crow21-Sep-04 5:33 
GeneralRe: [DLL]: Can I declare a global variable in a DLL? Pin
ThatsAlok23-Sep-04 3:37
ThatsAlok23-Sep-04 3:37 
GeneralRe: [DLL]: Can I declare a global variable in a DLL? Pin
David Crow23-Sep-04 3:46
David Crow23-Sep-04 3:46 
GeneralTCP/IP: set push bit Pin
probst21-Sep-04 4:46
probst21-Sep-04 4:46 
GeneralRe: TCP/IP: set push bit Pin
Alexander M.,21-Sep-04 9:42
Alexander M.,21-Sep-04 9:42 
GeneralCFileDialog stops me writing to log file Pin
ChrisBidmead21-Sep-04 4:36
ChrisBidmead21-Sep-04 4:36 
GeneralRe: CFileDialog stops me writing to log file Pin
David Crow21-Sep-04 5:45
David Crow21-Sep-04 5:45 
GeneralRe: CFileDialog stops me writing to log file Pin
ChrisBidmead21-Sep-04 6:21
ChrisBidmead21-Sep-04 6:21 
GeneralRe: CFileDialog stops me writing to log file Pin
David Crow21-Sep-04 8:34
David Crow21-Sep-04 8:34 
GeneralRe: CFileDialog stops me writing to log file Pin
ChrisBidmead21-Sep-04 10:20
ChrisBidmead21-Sep-04 10:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.