Click here to Skip to main content
15,917,709 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralHTML syntax highlighting concepts Pin
mcguile25710-Sep-03 5:26
mcguile25710-Sep-03 5:26 
GeneralRe: HTML syntax highlighting concepts Pin
Phil Hamer10-Sep-03 9:20
Phil Hamer10-Sep-03 9:20 
GeneralPaiting inside a control Pin
JensB10-Sep-03 5:24
JensB10-Sep-03 5:24 
QuestionCListCtrl, how to iterate through all items? Pin
Anonymous10-Sep-03 5:21
Anonymous10-Sep-03 5:21 
AnswerRe: CListCtrl, how to iterate through all items? Pin
vcplusplus10-Sep-03 5:35
vcplusplus10-Sep-03 5:35 
AnswerRe: CListCtrl, how to iterate through all items? Pin
David Crow10-Sep-03 6:16
David Crow10-Sep-03 6:16 
GeneralRe: CListCtrl, how to iterate through all items? Pin
Anonymous10-Sep-03 6:40
Anonymous10-Sep-03 6:40 
GeneralXP Serial communication Pin
Arthur Westerman10-Sep-03 4:54
Arthur Westerman10-Sep-03 4:54 
I'm trying to achieve overlapped communication with a device, using a virtual serial port. Basic command-response, where \r\n (CRLF, #013#010) ends both command and response. Multiple commands/responses are chained with ';', no response is given if either the command sets up the device, or the command is invalid.
Ie:
"COMMAND1?\r\n" -> "RESP_TO_1\r\n"
"COMMAND2\r\n" -> no response through serial, but flashes a led on the external device
"COMMAND3;COMMAND4?\r\n" -> "RESP_TO_4\r\n"
"COMMAND5?;COMMAND6?\r\n"-> "RESP_TO_5;RESP_TO_6\r\n"


On W98, using latest VCOM drivers, it works perfect. On XP, WriteFile writes nothing, and GetLastError always returns 997..
997 Overlapped I/O operation is in progress. ERROR_IO_PENDING

I looped the code to check all COM ports, and even the unused IR and VCOM ports are showing up ERROR_IO_PENDING...

I changed timeouts, dcb fields, anything, but 997 keeps haunting me.

So, if anyone using XP, virtual com-ports and OVERLAPPED communication could give me a hand?

I included a piece of sample code. (I left out the part where response is read, since WriteFile never writes anything to respond to anyway)

bool CSerial4::OpenPort(int port)<br />
{<br />
	if(port<1) <br />
	{<br />
		m_sError=_T("Illegal port number");<br />
		m_iPort=0;<br />
		return false;<br />
	}<br />
	if(m_hPort!=INVALID_HANDLE_VALUE)<br />
	{<br />
		return true;<br />
	}<br />
	else<br />
	{<br />
		char strPort[15];<br />
		sprintf(strPort,"\\\\.\\COM%d",port);<br />
		m_hPort = ::CreateFile(strPort,<br />
			GENERIC_READ|GENERIC_WRITE,//access ( read and write)<br />
			0,    //(share) 0:cannot share the COM port                        <br />
			0,    //security  (None)                <br />
			OPEN_EXISTING,// creation : open_existing<br />
			FILE_FLAG_OVERLAPPED,// we want overlapped operation<br />
			0// no templates file for COM port...<br />
			);<br />
		if(m_hPort==INVALID_HANDLE_VALUE )<br />
		{<br />
			m_sError.Format("CommError(%d)",GetLastError());<br />
			return false;<br />
		}<br />
		DCB dcb = {0};<br />
		dcb.DCBlength = sizeof(DCB);<br />
<br />
		if (!::GetCommState (m_hPort,&dcb))<br />
		{<br />
			m_sError.Format("GetCommState: CommError(%d)",GetLastError());<br />
			return false;<br />
		}<br />
<br />
		dcb.fRtsControl	= RTS_CONTROL_ENABLE;<br />
		dcb.fDtrControl	= DTR_CONTROL_ENABLE;<br />
		dcb.BaudRate    = CBR_9600;<br />
		dcb.ByteSize    = 8;<br />
		dcb.Parity      = NOPARITY;<br />
		dcb.StopBits    = ONESTOPBIT;// ONESTOPBIT/ONE5STOPBITS/TWOSTOPBITS 0/1/2<br />
		dcb.EvtChar		= 10;<br />
		dcb.XoffChar	= 19;<br />
		dcb.XoffLim		= 512;<br />
		dcb.XonChar		= 17;<br />
		dcb.XonLim		= 2048;<br />
<br />
<br />
		if (!::SetCommState (m_hPort,&dcb))<br />
		{<br />
			m_sError.Format("SetCommState: CommError(%d)", GetLastError());<br />
			return false;<br />
		}<br />
<br />
		COMMTIMEOUTS timeouts;<br />
		timeouts.ReadIntervalTimeout		= MAXDWORD; <br />
		timeouts.ReadTotalTimeoutMultiplier	= 0;<br />
		timeouts.ReadTotalTimeoutConstant	= 0;<br />
		timeouts.WriteTotalTimeoutMultiplier= 0;<br />
		timeouts.WriteTotalTimeoutConstant	= 0;<br />
<br />
		if (!SetCommTimeouts(m_hPort, &timeouts))<br />
		{<br />
			m_sError.Format("SetCommTimeouts: CommError(%d)",GetLastError());<br />
			return false;<br />
		}<br />
<br />
		DWORD flags=0;<br />
		flags|=EV_RXFLAG;//EV_TXEMPTY|<br />
		if (!::SetCommMask(m_hPort,flags))<br />
		{<br />
			m_sError.Format("SetCommMask: CommError(%d)",GetLastError());<br />
			return false;<br />
		}<br />
<br />
		return true;		//return true;<br />
	}<br />
}<br />
<br />
<br />
bool CSerial4::Request(CString in, CString &out)<br />
{<br />
	DWORD dwSize=in.GetLength();<br />
	DWORD dwBytesWritten=0;<br />
	DWORD dwRead;<br />
	DWORD dwMask;<br />
	char *psp=m_data;<br />
	psp[0]=0;<br />
<br />
	OVERLAPPED ovRead;	<br />
    memset(&ovRead,0,sizeof(OVERLAPPED));<br />
	ovRead.hEvent=::CreateEvent(0,1,0,0); <br />
<br />
	OVERLAPPED ovWrite;	<br />
    memset(&ovWrite,0,sizeof(OVERLAPPED));<br />
//	ovWrite.hEvent=::CreateEvent(0,1,0,0); <br />
<br />
	char* pin=new char[dwSize+1];<br />
	strcpy(pin,in);<br />
	::PurgeComm(m_hPort,PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);<br />
	if(!::WriteFile (m_hPort,pin,dwSize,&dwBytesWritten ,&ovWrite))<br />
	{<br />
		m_sError.Format("Write Failed: CommError(%d)",GetLastError());<br />
//		m_sError.Format("Write Failed: CommError(%d)",GetLastError());<br />
//		m_debugError.Format("0x%8.8x %d %d %d %d",ov.hEvent,ov.Internal,ov.InternalHigh,ov.Offset,ov.OffsetHigh);<br />
		::CloseHandle(ovWrite.hEvent);<br />
		return false;<br />
	}<br />
...<br />
..<br />
.<br />

GeneralcreateProcess questions Pin
ns10-Sep-03 4:46
ns10-Sep-03 4:46 
GeneralRe: createProcess questions Pin
Magnus Westin10-Sep-03 4:58
Magnus Westin10-Sep-03 4:58 
Generalerror Pin
ranjjj10-Sep-03 4:24
ranjjj10-Sep-03 4:24 
GeneralRe: error Pin
David Crow10-Sep-03 6:22
David Crow10-Sep-03 6:22 
GeneralWeird problem with FindFirstChangeNotification Pin
Magnus Westin10-Sep-03 3:16
Magnus Westin10-Sep-03 3:16 
GeneralHHeelp Pin
Member 42425910-Sep-03 3:13
Member 42425910-Sep-03 3:13 
GeneralRe: HHeelp Pin
valikac10-Sep-03 9:24
valikac10-Sep-03 9:24 
GeneralRe: HHeelp Pin
Member 42425910-Sep-03 19:12
Member 42425910-Sep-03 19:12 
GeneralRe: HHeelp Pin
valikac11-Sep-03 11:41
valikac11-Sep-03 11:41 
GeneralRe: HHeelp Pin
Phil Hamer10-Sep-03 9:25
Phil Hamer10-Sep-03 9:25 
GeneralRe: HHeelp Pin
Member 42425910-Sep-03 19:09
Member 42425910-Sep-03 19:09 
QuestionShape file source code ?? Pin
David Chamberlain10-Sep-03 2:31
David Chamberlain10-Sep-03 2:31 
AnswerRe: Shape file source code ?? Pin
JWood10-Sep-03 4:15
JWood10-Sep-03 4:15 
GeneralICM Problem Pin
CodeBrain10-Sep-03 2:14
CodeBrain10-Sep-03 2:14 
GeneralCScrollView Help Pin
VanHlebar10-Sep-03 1:26
VanHlebar10-Sep-03 1:26 
GeneralRe: CScrollView Help Pin
Ryan Binns10-Sep-03 3:13
Ryan Binns10-Sep-03 3:13 
GeneralRe: CScrollView Help Pin
VanHlebar10-Sep-03 8:32
VanHlebar10-Sep-03 8:32 

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.