thanks for ur answer sir
i use this code on a button but port which is in bold does not work
so please tell me what port number i should use
CAsyncSocket m_sListener, m_sConnected;
AfxMessageBox("Unable to Listen on that port,please try another port");
Guy, if you don't know the port number of the service you're trying to connect to on the server, we're not going to be able to tell you. After all, you haven't said anything about this service so we don't know what it is you're trying to connect to!
I was having some troubles with the use of COM ports on an embedded device (Pocket PC with windows mobile 5). I already opened a discussion here[^].
I finally decided to use WaitCommEvent to monitor incoming data but this doesn't seem to work as expected. The port that I'm working with is a virtual COM port which is provided by a Bluetooth stack when a Bluetooth connection is established. Here is the code:
int CSerialDriver::ReadData(char* szData, int MaxLenght)
DWORD dwMask = 0;
if (dwMask & EV_RXCHAR)
DWORD dwRead = 0;
int Count = 0;
Count = MaxLenght - BytesRead;
BytesRead += dwRead;
} while ( dwRead && (BytesRead<MaxLenght) );
The comm mask is set when the port is opened:
The problem that I encounter is that the WaitCommEvent doesn't work as expected: when I receive data, WaitCommEvent exit as expected but sometimes, all the data has not been received yet (which is logical). That's not a problem because my function will get called until all data has been received. The problem comes when I enter the function a second time and call WaitCommEvent, at this time it doesn't exit even if bytes have been received in between. Having read this article[^], WaitCommEvent should exit if bytes have been received in between.
Would it be possible that it is a bug in the driver supplied by the company that produce the Bluetooth stack ? Or did I do something wrong ?
Another question: it is stated in MSDN: Only one WaitCommEvent can be used for each open COM port handle. This means that if you have three threads in your application and each thread needs to wait on a specific comm event, each thread needs to open the COM port and then use the assigned port handle for their respective WaitCommEvent calls. (see here[^])
So, that would mean that your application could open the COM port several time. I tried that on win32 but that doesn't work at all (each time I receive an invalid handle value and the GetLastError code is "Access is denied"). I tried with different access:
Use RegCreateKeyEx for creating the path in the registry, the second parameter is where you'll set the path that you said. You can create the values in your registry by using RegSetValueEx. RegCloseKey will close the registry item that you opened.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture