Note that there are some explanatory texts on larger screens.

plurals
  1. POSerial Comm using WriteFile/ReadFile
    text
    copied!<pre><code>//#include "StdAfx.h" #include &lt;stdio.h&gt; #include &lt;windows.h&gt; #include &lt;winbase.h&gt; #include &lt;iostream&gt; #include &lt;tchar.h&gt; using namespace std; int main() { int com = 'COM2'; string data = "\n 010400 \n"; char output[32]; //unsigned int length = 0; DCB config = {0}; bool abContinue = true; DWORD dwBytesWritten; DWORD dwBytesRead; int isRead = false; HANDLE m_hCommPort = ::CreateFile(L"COM2", GENERIC_READ|GENERIC_WRITE,//access ( read and write) 0, //(share) 0:cannot share the COM port 0, //security (None) OPEN_EXISTING,// creation : open_existing 0, // we dont want overlapped operation 0// no templates file for COM port... ); config.DCBlength = sizeof(config); if((GetCommState(m_hCommPort, &amp;config) == 0)) { printf("Get configuration port has a problem."); return FALSE; } config.BaudRate = 9600; config.StopBits = ONESTOPBIT; config.Parity = PARITY_NONE; config.ByteSize = DATABITS_8; config.fDtrControl = 0; config.fRtsControl = 0; if (!SetCommState(m_hCommPort, &amp;config)) { printf( "Failed to Set Comm State Reason: %d\n",GetLastError()); //return E_FAIL; } printf("Current Settings\n Baud Rate %d\n Parity %d\n Byte Size %d\n Stop Bits %d", config.BaudRate, config.Parity, config.ByteSize, config.StopBits); int isWritten = WriteFile(m_hCommPort, &amp;data,(DWORD) sizeof(data), &amp;dwBytesWritten, NULL); //memset(output, 0, sizeof(output)); while (abContinue) { isRead = ReadFile(m_hCommPort, output, sizeof(output), &amp;dwBytesRead, NULL); if(!isRead) { abContinue = false; break; } } cin.get(); } </code></pre> <p>I am having trouble reading from the com port. If I step through the code, it goes into "isRead = ReadFile(m_hCommPort, output, sizeof(output), &amp;dwBytesRead, NULL);" and doesn't come back out.... This is my first try at this with no success.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload