<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic can not access Virtual Com Port in Windows  in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/can-not-access-Virtual-Com-Port-in-Windows/m-p/781722#M47602</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, All&lt;/P&gt;&lt;P&gt;I meet a big problem, I don't have any idea to fix it.&lt;/P&gt;&lt;P&gt;sdk path: SDK_2.3.0_MAPS-KS22\boards\mapsks22\usb_examples\usb_device_cdc_vcom\bm&lt;/P&gt;&lt;P&gt;PC OS: window 7 64bit, MCU: mks22,&lt;/P&gt;&lt;P&gt;I use &lt;SPAN&gt;usb_device_cdc_vcom&lt;/SPAN&gt; to&amp;nbsp;&lt;SPAN style="color: #000000; background-color: #ffffff; font-size: 13px;"&gt;develop&lt;/SPAN&gt; ks22 .&lt;/P&gt;&lt;P&gt;I want use my PC&amp;nbsp; to access virtual com port, so I write a sample code through WINDOWS API.&lt;/P&gt;&lt;P&gt;here is my source code on windows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void &lt;STRONG&gt;setConfig&lt;/STRONG&gt;() {&lt;BR /&gt; DCB dcbSerialParams = { 0 }; // Initializing DCB structure&lt;BR /&gt; COMMTIMEOUTS timeouts = { 0 };&lt;BR /&gt; dcbSerialParams.DCBlength = sizeof(dcbSerialParams);&lt;BR /&gt; GetCommState(hComm, &amp;amp;dcbSerialParams);&lt;BR /&gt; dcbSerialParams.BaudRate = CBR_9600; // Setting BaudRate = 9600&lt;BR /&gt; dcbSerialParams.ByteSize = 8; // Setting ByteSize = 8&lt;BR /&gt; dcbSerialParams.StopBits = ONESTOPBIT;// Setting StopBits = 1&lt;BR /&gt; dcbSerialParams.Parity = NOPARITY; // Setting Parity = None&lt;BR /&gt; //dcbSerialParams.fInX = 1;&lt;BR /&gt; //sdcbSerialParams.fOutX=1;&lt;BR /&gt; if (!SetCommState(hComm, &amp;amp;dcbSerialParams))&lt;BR /&gt; printf("SetCommState fail!\n");&lt;/P&gt;&lt;P&gt;GetCommTimeouts(hComm, &amp;amp;timeouts);&lt;BR /&gt; timeouts.ReadIntervalTimeout = 0; // in milliseconds&lt;BR /&gt; timeouts.ReadTotalTimeoutConstant = 500; // in milliseconds&lt;BR /&gt; timeouts.ReadTotalTimeoutMultiplier = 0; // in milliseconds&lt;BR /&gt; timeouts.WriteTotalTimeoutConstant = 500; // in milliseconds&lt;BR /&gt; timeouts.WriteTotalTimeoutMultiplier = 0; // in milliseconds&lt;BR /&gt; if(!SetCommTimeouts(hComm, &amp;amp;timeouts))&lt;BR /&gt; printf("SetCommTimeouts fail!\n");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int &lt;STRONG&gt;OpenCom()&lt;/STRONG&gt; {&lt;BR /&gt; hComm = CreateFile("\\\\.\\COM12", // for COM1OM9 only use COM1&lt;BR /&gt; GENERIC_READ | GENERIC_WRITE, //Read/Write&lt;BR /&gt; 0, // No Sharing&lt;BR /&gt; NULL, // No Security&lt;BR /&gt; CREATE_ALWAYS,// Open existing port only&lt;BR /&gt; 0, // Non Overlapped I/O&lt;BR /&gt; NULL); // Null for Comm Devices&lt;/P&gt;&lt;P&gt;if (hComm == INVALID_HANDLE_VALUE) {&lt;BR /&gt; printf("Error in opening serial port\n");&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; printf("opening serial port successful\n");&lt;/P&gt;&lt;P&gt;setConfig();&lt;BR /&gt; return 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void &lt;STRONG&gt;ComIO&lt;/STRONG&gt;(PACKET_INFO packet_info) {&lt;BR /&gt; unsigned char pBuffer[7];&lt;BR /&gt; printf(" usize:%d\n", uBufSize);&lt;BR /&gt; memcpy(pBuffer, &amp;amp;packet_info, uBufSize);&lt;BR /&gt; for (int i = 0; i &amp;lt; uBufSize; i++)&lt;BR /&gt; printf("ComIO buffer %u is %d:\n", i, pBuffer[i]);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DWORD dNoOFBytestoWrite; // No of bytes to write into the port&lt;BR /&gt; DWORD dNoOfBytesWritten = 0; // No of bytes written to the port&lt;BR /&gt; dNoOFBytestoWrite = uBufSize;&lt;BR /&gt; printf("size of dNoOFBytestoWrite: %d\n", dNoOFBytestoWrite);&lt;BR /&gt; BOOL bRet = WriteFile(hComm, // Handle to the Serial port&lt;BR /&gt; pBuffer, // Data to be written to the port&lt;BR /&gt; dNoOFBytestoWrite, //No of bytes to write&lt;BR /&gt; &amp;amp;dNoOfBytesWritten, //Bytes written&lt;BR /&gt; NULL);&lt;BR /&gt; if (dNoOfBytesWritten &amp;gt; 0)&lt;BR /&gt; printf("write successful\n");&lt;BR /&gt; else&lt;BR /&gt; printf("write fail\n");&lt;BR /&gt; if (bRet)&lt;BR /&gt; {&lt;BR /&gt; printf("write good!\n");&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; &lt;BR /&gt; DWORD dwError = GetLastError();&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; printf("error: %d\n", dwError);&lt;BR /&gt; &lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int main(){&lt;/P&gt;&lt;P&gt;&amp;nbsp; XXXX // give&amp;nbsp;&lt;SPAN&gt;packet_info some value in here&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;OpenCom()&lt;/STRONG&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;ComIO&lt;/STRONG&gt;&lt;SPAN&gt;(packet_info);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is when I use my sample code to access port,&lt;/P&gt;&lt;P&gt;open com and write com is successful, but KS22(MCU) can not receive my send data.&lt;/P&gt;&lt;P&gt;but I use PUTTY to access port first,&amp;nbsp; KS22 can receive my send data. after that I run my sample code, it works too.&lt;/P&gt;&lt;P&gt;ks22 can receive my send data through my sample code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it seems like I need use PUTTY to open port and send data first, after that I can use my sample code to access port.&lt;/P&gt;&lt;P&gt;it seems like PUTTY do some communicate, that my sample code didn't do.&lt;/P&gt;&lt;P&gt;how can I modify my sample code, makes it work.(don't need to use PUTTY access port first)&lt;/P&gt;&lt;P&gt;I don't have any idea, who can help me please~&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THX&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Nancy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Jul 2018 02:47:48 GMT</pubDate>
    <dc:creator>chinagkuanyi</dc:creator>
    <dc:date>2018-07-05T02:47:48Z</dc:date>
    <item>
      <title>can not access Virtual Com Port in Windows</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/can-not-access-Virtual-Com-Port-in-Windows/m-p/781722#M47602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, All&lt;/P&gt;&lt;P&gt;I meet a big problem, I don't have any idea to fix it.&lt;/P&gt;&lt;P&gt;sdk path: SDK_2.3.0_MAPS-KS22\boards\mapsks22\usb_examples\usb_device_cdc_vcom\bm&lt;/P&gt;&lt;P&gt;PC OS: window 7 64bit, MCU: mks22,&lt;/P&gt;&lt;P&gt;I use &lt;SPAN&gt;usb_device_cdc_vcom&lt;/SPAN&gt; to&amp;nbsp;&lt;SPAN style="color: #000000; background-color: #ffffff; font-size: 13px;"&gt;develop&lt;/SPAN&gt; ks22 .&lt;/P&gt;&lt;P&gt;I want use my PC&amp;nbsp; to access virtual com port, so I write a sample code through WINDOWS API.&lt;/P&gt;&lt;P&gt;here is my source code on windows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void &lt;STRONG&gt;setConfig&lt;/STRONG&gt;() {&lt;BR /&gt; DCB dcbSerialParams = { 0 }; // Initializing DCB structure&lt;BR /&gt; COMMTIMEOUTS timeouts = { 0 };&lt;BR /&gt; dcbSerialParams.DCBlength = sizeof(dcbSerialParams);&lt;BR /&gt; GetCommState(hComm, &amp;amp;dcbSerialParams);&lt;BR /&gt; dcbSerialParams.BaudRate = CBR_9600; // Setting BaudRate = 9600&lt;BR /&gt; dcbSerialParams.ByteSize = 8; // Setting ByteSize = 8&lt;BR /&gt; dcbSerialParams.StopBits = ONESTOPBIT;// Setting StopBits = 1&lt;BR /&gt; dcbSerialParams.Parity = NOPARITY; // Setting Parity = None&lt;BR /&gt; //dcbSerialParams.fInX = 1;&lt;BR /&gt; //sdcbSerialParams.fOutX=1;&lt;BR /&gt; if (!SetCommState(hComm, &amp;amp;dcbSerialParams))&lt;BR /&gt; printf("SetCommState fail!\n");&lt;/P&gt;&lt;P&gt;GetCommTimeouts(hComm, &amp;amp;timeouts);&lt;BR /&gt; timeouts.ReadIntervalTimeout = 0; // in milliseconds&lt;BR /&gt; timeouts.ReadTotalTimeoutConstant = 500; // in milliseconds&lt;BR /&gt; timeouts.ReadTotalTimeoutMultiplier = 0; // in milliseconds&lt;BR /&gt; timeouts.WriteTotalTimeoutConstant = 500; // in milliseconds&lt;BR /&gt; timeouts.WriteTotalTimeoutMultiplier = 0; // in milliseconds&lt;BR /&gt; if(!SetCommTimeouts(hComm, &amp;amp;timeouts))&lt;BR /&gt; printf("SetCommTimeouts fail!\n");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int &lt;STRONG&gt;OpenCom()&lt;/STRONG&gt; {&lt;BR /&gt; hComm = CreateFile("\\\\.\\COM12", // for COM1OM9 only use COM1&lt;BR /&gt; GENERIC_READ | GENERIC_WRITE, //Read/Write&lt;BR /&gt; 0, // No Sharing&lt;BR /&gt; NULL, // No Security&lt;BR /&gt; CREATE_ALWAYS,// Open existing port only&lt;BR /&gt; 0, // Non Overlapped I/O&lt;BR /&gt; NULL); // Null for Comm Devices&lt;/P&gt;&lt;P&gt;if (hComm == INVALID_HANDLE_VALUE) {&lt;BR /&gt; printf("Error in opening serial port\n");&lt;BR /&gt; return -1;&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; printf("opening serial port successful\n");&lt;/P&gt;&lt;P&gt;setConfig();&lt;BR /&gt; return 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;void &lt;STRONG&gt;ComIO&lt;/STRONG&gt;(PACKET_INFO packet_info) {&lt;BR /&gt; unsigned char pBuffer[7];&lt;BR /&gt; printf(" usize:%d\n", uBufSize);&lt;BR /&gt; memcpy(pBuffer, &amp;amp;packet_info, uBufSize);&lt;BR /&gt; for (int i = 0; i &amp;lt; uBufSize; i++)&lt;BR /&gt; printf("ComIO buffer %u is %d:\n", i, pBuffer[i]);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DWORD dNoOFBytestoWrite; // No of bytes to write into the port&lt;BR /&gt; DWORD dNoOfBytesWritten = 0; // No of bytes written to the port&lt;BR /&gt; dNoOFBytestoWrite = uBufSize;&lt;BR /&gt; printf("size of dNoOFBytestoWrite: %d\n", dNoOFBytestoWrite);&lt;BR /&gt; BOOL bRet = WriteFile(hComm, // Handle to the Serial port&lt;BR /&gt; pBuffer, // Data to be written to the port&lt;BR /&gt; dNoOFBytestoWrite, //No of bytes to write&lt;BR /&gt; &amp;amp;dNoOfBytesWritten, //Bytes written&lt;BR /&gt; NULL);&lt;BR /&gt; if (dNoOfBytesWritten &amp;gt; 0)&lt;BR /&gt; printf("write successful\n");&lt;BR /&gt; else&lt;BR /&gt; printf("write fail\n");&lt;BR /&gt; if (bRet)&lt;BR /&gt; {&lt;BR /&gt; printf("write good!\n");&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; &lt;BR /&gt; DWORD dwError = GetLastError();&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; printf("error: %d\n", dwError);&lt;BR /&gt; &lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int main(){&lt;/P&gt;&lt;P&gt;&amp;nbsp; XXXX // give&amp;nbsp;&lt;SPAN&gt;packet_info some value in here&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;OpenCom()&lt;/STRONG&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;ComIO&lt;/STRONG&gt;&lt;SPAN&gt;(packet_info);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is when I use my sample code to access port,&lt;/P&gt;&lt;P&gt;open com and write com is successful, but KS22(MCU) can not receive my send data.&lt;/P&gt;&lt;P&gt;but I use PUTTY to access port first,&amp;nbsp; KS22 can receive my send data. after that I run my sample code, it works too.&lt;/P&gt;&lt;P&gt;ks22 can receive my send data through my sample code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it seems like I need use PUTTY to open port and send data first, after that I can use my sample code to access port.&lt;/P&gt;&lt;P&gt;it seems like PUTTY do some communicate, that my sample code didn't do.&lt;/P&gt;&lt;P&gt;how can I modify my sample code, makes it work.(don't need to use PUTTY access port first)&lt;/P&gt;&lt;P&gt;I don't have any idea, who can help me please~&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THX&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Nancy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2018 02:47:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/can-not-access-Virtual-Com-Port-in-Windows/m-p/781722#M47602</guid>
      <dc:creator>chinagkuanyi</dc:creator>
      <dc:date>2018-07-05T02:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: can not access Virtual Com Port in Windows</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/can-not-access-Virtual-Com-Port-in-Windows/m-p/781723#M47603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nancy:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PuTTY is open source software, I would suggest you download the PuTTY and check how PuTTY access com port.&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://www.putty.org/" title="https://www.putty.org/"&gt;Download PuTTY - a free SSH and telnet client for Windows&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jul 2018 05:48:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/can-not-access-Virtual-Com-Port-in-Windows/m-p/781723#M47603</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2018-07-30T05:48:48Z</dc:date>
    </item>
  </channel>
</rss>

