Click here to Skip to main content
15,913,487 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: files displayed on the CFileDialog Pin
Hamid_RT27-Jul-06 23:32
Hamid_RT27-Jul-06 23:32 
GeneralRe: files displayed on the CFileDialog Pin
Naveen27-Jul-06 23:37
Naveen27-Jul-06 23:37 
GeneralRe: files displayed on the CFileDialog Pin
toxcct27-Jul-06 23:56
toxcct27-Jul-06 23:56 
GeneralRe: files displayed on the CFileDialog Pin
see me27-Jul-06 23:51
see me27-Jul-06 23:51 
GeneralRe: files displayed on the CFileDialog Pin
toxcct27-Jul-06 23:55
toxcct27-Jul-06 23:55 
GeneralRe: files displayed on the CFileDialog Pin
see me28-Jul-06 0:27
see me28-Jul-06 0:27 
GeneralRe: files displayed on the CFileDialog Pin
see me27-Jul-06 23:47
see me27-Jul-06 23:47 
QuestionRS232 - Sending Data - Only 16Bytes allowed?! Pin
Kreatief27-Jul-06 21:36
Kreatief27-Jul-06 21:36 
Hello,

I am having troubles with sending data through RS232. I am using the class from Ramon de Klein:

http://www.codeproject.com/system/serial.asp

There I am working with the simple Serial Class (Overlapped).

My problem is that I can only send 16 Byte all together. If I try to send more than 16 Byte, its sending an empty message and I get a NAK from the other side ( I monitored this with a monitoring tool).


This is what the Overlapped structure is set to after sending data:

<br />
	Internal	258	        unsigned long<br />
	InternalHigh	16	        unsigned long<br />
	Offset	        0	        unsigned long<br />
	OffsetHigh	0	        unsigned long<br />
	Pointer	        0x00000000	void *<br />
	hEvent	        0x00000780	void *<br />



As you can see, InternalHigh is set to 16. I dont know why. I cant figure out why I am only allowed to send 16 Byte. The dwInQueue as well as the dwOutQueue is big enough to hold more data.

The problem is that I absolutely have no clue where to search for that problem.

Is there anything that restricts the number of bytes to send?

Which codepart can be relevant for you?

This the write method:


<br />
LONG CSerial::Write (const void* pData, size_t iLen, DWORD* pdwWritten, LPOVERLAPPED lpOverlapped, DWORD dwTimeout)<br />
{<br />
	// Check if time-outs are supported<br />
	CheckRequirements(lpOverlapped,dwTimeout);<br />
<br />
	// Overlapped operation should specify the pdwWritten variable<br />
	_ASSERTE(!lpOverlapped || pdwWritten);<br />
<br />
	// Reset error state<br />
	m_lLastError = ERROR_SUCCESS;<br />
<br />
	// Use our own variable for read count<br />
	DWORD dwWritten;<br />
	if (pdwWritten == 0)<br />
	{<br />
		pdwWritten = &dwWritten;<br />
	}<br />
<br />
	// Reset the number of bytes written<br />
	*pdwWritten = 0;<br />
<br />
	// Check if the device is open<br />
	if (m_hFile == 0)<br />
	{<br />
		// Set the internal error code<br />
		m_lLastError = ERROR_INVALID_HANDLE;<br />
<br />
		// Issue an error and quit<br />
		_RPTF0(_CRT_WARN,"CSerial::Write - Device is not opened\n");<br />
		return m_lLastError;<br />
	}<br />
<br />
#ifndef SERIAL_NO_OVERLAPPED<br />
<br />
	// Check if an overlapped structure has been specified<br />
	if (!m_hevtOverlapped && (lpOverlapped || (dwTimeout != INFINITE)))<br />
	{<br />
		// Set the internal error code<br />
		m_lLastError = ERROR_INVALID_FUNCTION;<br />
<br />
		// Issue an error and quit<br />
		_RPTF0(_CRT_WARN,"CSerial::Write - Overlapped I/O is disabled, specified parameters are illegal.\n");<br />
		return m_lLastError;<br />
	}<br />
<br />
	// Wait for the event to happen<br />
	OVERLAPPED ovInternal;<br />
	if (!lpOverlapped && m_hevtOverlapped)<br />
	{<br />
		// Setup our own overlapped structure<br />
		memset(&ovInternal,0,sizeof(ovInternal));<br />
		ovInternal.hEvent = m_hevtOverlapped;<br />
<br />
		// Use our internal overlapped structure<br />
		lpOverlapped = &ovInternal;<br />
	}<br />
<br />
	// Make sure the overlapped structure isn't busy<br />
	_ASSERTE(!m_hevtOverlapped || HasOverlappedIoCompleted(lpOverlapped));<br />
<br />
	char bla[255] = {0x0};<br />
	strcpy(bla, (char*)pData);<br />
<br />
	if( bla[iLen-1] == 0x03 )<br />
		iLen++;<br />
<br />
	// Write the data<br />
	if (!::WriteFile(m_hFile,pData,iLen,pdwWritten,lpOverlapped))<br />
	{<br />
		// Set the internal error code<br />
		long lLastError = ::GetLastError();<br />
<br />
		// Overlapped operation in progress is not an actual error<br />
		if (lLastError != ERROR_IO_PENDING)<br />
		{<br />
			// Save the error<br />
			m_lLastError = lLastError;<br />
<br />
			// Issue an error and quit<br />
			_RPTF0(_CRT_WARN,"CSerial::Write - Unable to write the data\n");<br />
			return m_lLastError;<br />
		}<br />
<br />
		// We need to block if the client didn't specify an overlapped structure<br />
		if (lpOverlapped == &ovInternal)<br />
		{<br />
			// Wait for the overlapped operation to complete<br />
			switch (::WaitForSingleObject(lpOverlapped->hEvent,dwTimeout))<br />
			{<br />
			case WAIT_OBJECT_0:<br />
				// The overlapped operation has completed<br />
				if (!::GetOverlappedResult(m_hFile,lpOverlapped,pdwWritten,FALSE))<br />
				{<br />
					// Set the internal error code<br />
					m_lLastError = ::GetLastError();<br />
<br />
					_RPTF0(_CRT_WARN,"CSerial::Write - Overlapped completed without result\n");<br />
					return m_lLastError;<br />
				}<br />
				break;<br />
<br />
			case WAIT_TIMEOUT:<br />
				// Cancel the I/O operation<br />
				CancelCommIo();<br />
<br />
				// The operation timed out. Set the internal error code and quit<br />
				m_lLastError = ERROR_TIMEOUT;<br />
				return m_lLastError;<br />
<br />
			default:<br />
				// Set the internal error code<br />
				m_lLastError = ::GetLastError();<br />
<br />
				// Issue an error and quit<br />
				_RPTF0(_CRT_WARN,"CSerial::Write - Unable to wait until data has been sent\n");<br />
				return m_lLastError;<br />
			}<br />
		}<br />
	}<br />
	else<br />
	{<br />
		// The operation completed immediatly. Just to be sure<br />
		// we'll set the overlapped structure's event handle.<br />
		if (lpOverlapped)<br />
			::SetEvent(lpOverlapped->hEvent);<br />
	}<br />
<br />
#else<br />
<br />
	// Write the data<br />
	if (!::WriteFile(m_hFile,pData,iLen,pdwWritten,0))<br />
	{<br />
		// Set the internal error code<br />
		m_lLastError = ::GetLastError();<br />
<br />
		// Issue an error and quit<br />
		_RPTF0(_CRT_WARN,"CSerial::Write - Unable to write the data\n");<br />
		return m_lLastError;<br />
	}<br />
<br />
#endif<br />
<br />
	// Return successfully<br />
	return m_lLastError;<br />
}<br />



This is how I initialize the com port:

<br />
	// Attempt to open the serial port (COM1)<br />
    lLastError = rfi->serial.Open(_T("COM1"),10000,10000,true);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to open COM-port"));<br />
<br />
    // Setup the serial port (9600,8N1, which is the default setting)<br />
    lLastError = rfi->serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port setting"));<br />
<br />
	// Setup handshaking (default is no handshaking)<br />
    //lLastError = serial.SetupHandshaking(CSerial::EHandshakeHardware);<br />
	lLastError = rfi->serial.SetupHandshaking(CSerial::EHandshakeOff);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port handshaking"));<br />
<br />
    // Register only for the receive event<br />
    lLastError = rfi->serial.SetMask(CSerial::EEventBreak |<br />
								CSerial::EEventCTS   |<br />
								CSerial::EEventDSR   |<br />
								CSerial::EEventError |<br />
								CSerial::EEventRing  |<br />
								CSerial::EEventRLSD  |<br />
								CSerial::EEventRecv);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port event mask"));<br />
<br />
	// Use 'non-blocking' reads, because we don't know how many bytes<br />
	// will be received. This is normally the most convenient mode<br />
	// (and also the default mode for reading data).<br />
    lLastError = rfi->serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to set COM-port read timeout."));<br />
<br />
	// Create a handle for the overlapped operations<br />
	HANDLE hevtOverlapped = ::CreateEvent(0,TRUE,FALSE,0);;<br />
	if (hevtOverlapped == 0)<br />
		rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to create manual-reset event for overlapped I/O."));<br />
<br />
	// Setup the overlapped structure<br />
	OVERLAPPED ov = {0};<br />
	ov.hEvent = hevtOverlapped;<br />
<br />
	// Open the "STOP" handle<br />
	HANDLE hevtStop = ::CreateEvent(0,TRUE,FALSE,_T("Overlapped_Stop_Event"));<br />
	if (hevtStop == 0)<br />
		rfi->ShowError(rfi->serial.GetLastError(), _T("Unable to create manual-reset event for stop event."));<br />



I am searching for a solution for some days now, and it would be really really great to get some help, at least getting a starting point where to look at.


DKT
AnswerRe: RS232 - Sending Data - Only 16Bytes allowed?! Pin
KarstenK27-Jul-06 23:21
mveKarstenK27-Jul-06 23:21 
GeneralRe: RS232 - Sending Data - Only 16Bytes allowed?! Pin
Kreatief28-Jul-06 0:34
Kreatief28-Jul-06 0:34 
GeneralRe: RS232 - Sending Data - Only 16Bytes allowed?! Pin
KarstenK28-Jul-06 0:49
mveKarstenK28-Jul-06 0:49 
QuestionMemory limit? Pin
AJoker27-Jul-06 21:14
AJoker27-Jul-06 21:14 
AnswerRe: Memory limit? Pin
Jonathan [Darka]27-Jul-06 23:03
professionalJonathan [Darka]27-Jul-06 23:03 
Questionservice dependancy/un stopable services Pin
_tasleem27-Jul-06 20:54
_tasleem27-Jul-06 20:54 
AnswerRe: service dependancy/un stopable services [modified] Pin
Jonathan [Darka]27-Jul-06 23:07
professionalJonathan [Darka]27-Jul-06 23:07 
GeneralRe: service dependancy/un stopable services Pin
_tasleem28-Jul-06 0:00
_tasleem28-Jul-06 0:00 
GeneralRe: service dependancy/un stopable services Pin
_tasleem28-Jul-06 4:12
_tasleem28-Jul-06 4:12 
GeneralRe: service dependancy/un stopable services Pin
Jonathan [Darka]28-Jul-06 7:09
professionalJonathan [Darka]28-Jul-06 7:09 
QuestionCRichEditCtrl getting word from point? Pin
harsha_123427-Jul-06 20:25
harsha_123427-Jul-06 20:25 
AnswerRe: CRichEditCtrl getting word from point? Pin
Naveen27-Jul-06 20:32
Naveen27-Jul-06 20:32 
AnswerRe: CRichEditCtrl getting word from point? Pin
_AnsHUMAN_ 27-Jul-06 20:38
_AnsHUMAN_ 27-Jul-06 20:38 
GeneralRe: CRichEditCtrl getting word from point? Pin
harsha_123427-Jul-06 20:49
harsha_123427-Jul-06 20:49 
GeneralRe: CRichEditCtrl getting word from point? Pin
_AnsHUMAN_ 27-Jul-06 20:53
_AnsHUMAN_ 27-Jul-06 20:53 
GeneralRe: CRichEditCtrl getting word from point? Pin
harsha_123427-Jul-06 21:15
harsha_123427-Jul-06 21:15 
GeneralRe: CRichEditCtrl getting word from point? Pin
Hamid_RT27-Jul-06 21:00
Hamid_RT27-Jul-06 21:00 

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.