<?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 Re: Has anyone managed to use KSDK CDC Example with Windows WriteFile? in Kinetis Software Development Kit</title>
    <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626261#M6616</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for that. &amp;nbsp;Is this code you have successfully used with the SDKD CDC?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Feb 2017 19:33:47 GMT</pubDate>
    <dc:creator>ashesman</dc:creator>
    <dc:date>2017-02-16T19:33:47Z</dc:date>
    <item>
      <title>Has anyone managed to use KSDK CDC Example with Windows WriteFile?</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626259#M6614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to use WriteFile to send a short string of eight characters from a Delphi program and c#. &amp;nbsp;Both of them lockup and writefile never returns . &amp;nbsp;However, using a terminal program (realterm), it works perfectly!&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A breakpoint on the CDC callback is never hit when writefile is called. &amp;nbsp;However, it is hit many times when the port is opened!&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone managed to use the KSDK CDC with a windows program that uses WriteFile? &amp;nbsp;Specifically I am using the Composite CDC and MSC example on K24. &amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HEEELLLLPPPP!!!!!!!!!&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ashley&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Feb 2017 04:46:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626259#M6614</guid>
      <dc:creator>ashesman</dc:creator>
      <dc:date>2017-02-13T04:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Has anyone managed to use KSDK CDC Example with Windows WriteFile?</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626260#M6615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;#region CDC Support&lt;BR /&gt;public class UsbDeviceMonitor&lt;BR /&gt; {&lt;BR /&gt; private ManagementEventWatcher plugInWatcher;&lt;BR /&gt; private ManagementEventWatcher unPlugWatcher;&lt;BR /&gt; private const string MyDeviceDescription = @"My Device Description";&lt;/P&gt;&lt;P&gt;~UsbDeviceMonitor()&lt;BR /&gt; {&lt;BR /&gt; Dispose();&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void Dispose()&lt;BR /&gt; {&lt;BR /&gt; if (plugInWatcher != null)&lt;BR /&gt; try&lt;BR /&gt; {&lt;BR /&gt; plugInWatcher.Dispose();&lt;BR /&gt; plugInWatcher = null;&lt;BR /&gt; }&lt;BR /&gt; catch (Exception) { }&lt;/P&gt;&lt;P&gt;if (unPlugWatcher == null) return;&lt;BR /&gt; try {&lt;BR /&gt; unPlugWatcher.Dispose();&lt;BR /&gt; unPlugWatcher = null;&lt;BR /&gt; }&lt;BR /&gt; catch (Exception) { }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void Start()&lt;BR /&gt; {&lt;BR /&gt; const string plugInSql = "SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_PnPEntity'";&lt;BR /&gt; const string unpluggedSql = "SELECT * FROM __InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_PnPEntity'";&lt;/P&gt;&lt;P&gt;var scope = new ManagementScope("root\\CIMV2") { Options = { EnablePrivileges = true } };&lt;/P&gt;&lt;P&gt;var pluggedInQuery = new WqlEventQuery(plugInSql);&lt;BR /&gt; plugInWatcher = new ManagementEventWatcher(scope, pluggedInQuery);&lt;BR /&gt; plugInWatcher.EventArrived += HandlePluggedInEvent;&lt;BR /&gt; plugInWatcher.Start();&lt;/P&gt;&lt;P&gt;var unPluggedQuery = new WqlEventQuery(unpluggedSql);&lt;BR /&gt; unPlugWatcher = new ManagementEventWatcher(scope, unPluggedQuery);&lt;BR /&gt; unPlugWatcher.EventArrived += HandleUnPluggedEvent;&lt;BR /&gt; unPlugWatcher.Start();&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private void HandleUnPluggedEvent(object sender, EventArrivedEventArgs e)&lt;BR /&gt; {&lt;BR /&gt; var description = GetDeviceDescription(e.NewEvent);&lt;BR /&gt; foreach (COMPortInfo comPort in COMPortInfo.GetCOMPortsInfo())&lt;BR /&gt; {&lt;BR /&gt; // comboBoxPort.Items.Add(string.Format("{0} – {1}", comPort.Name, comPort.Description));&lt;BR /&gt; // this.comboBoxPort.Items.Add(string.Format("{0}", comPort.Description));&lt;BR /&gt; }&lt;BR /&gt; if (description.Equals(MyDeviceDescription)) { &lt;BR /&gt; // Take actions here when the device is unplugged&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private void HandlePluggedInEvent(object sender, EventArrivedEventArgs e)&lt;BR /&gt; {&lt;BR /&gt; var description = GetDeviceDescription(e.NewEvent);&lt;BR /&gt; if (description.Equals(MyDeviceDescription)){&lt;BR /&gt; // Take actions here when the device is plugged in&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private static string GetDeviceDescription(ManagementBaseObject newEvent)&lt;BR /&gt; {&lt;BR /&gt; var targetInstanceData = newEvent.Properties["TargetInstance"];&lt;BR /&gt; var targetInstanceObject = (ManagementBaseObject)targetInstanceData.Value;&lt;BR /&gt; if (targetInstanceObject == null) return "";&lt;/P&gt;&lt;P&gt;var description = targetInstanceObject.Properties["Description"].Value.ToString();&lt;BR /&gt; return description;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;internal class ProcessConnection&lt;BR /&gt; {&lt;BR /&gt; public static ConnectionOptions ProcessConnectionOptions()&lt;BR /&gt; {&lt;BR /&gt; ConnectionOptions options = new ConnectionOptions();&lt;BR /&gt; options.Impersonation = ImpersonationLevel.Impersonate;&lt;BR /&gt; options.Authentication = AuthenticationLevel.Default;&lt;BR /&gt; options.EnablePrivileges = true;&lt;BR /&gt; return options;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public static ManagementScope ConnectionScope(string machineName, ConnectionOptions options, string path)&lt;BR /&gt; {&lt;BR /&gt; ManagementScope connectScope = new ManagementScope();&lt;BR /&gt; connectScope.Path = new ManagementPath(@"\\" + machineName + path);&lt;BR /&gt; connectScope.Options = options;&lt;BR /&gt; connectScope.Connect();&lt;BR /&gt; return connectScope;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;//===================================================&lt;BR /&gt; public class COMPortInfo&lt;BR /&gt; {&lt;BR /&gt; public string Name { get; set; }&lt;BR /&gt; public string Description { get; set; }&lt;/P&gt;&lt;P&gt;public COMPortInfo() { }&lt;/P&gt;&lt;P&gt;public static List&amp;lt;COMPortInfo&amp;gt; GetCOMPortsInfo()&lt;BR /&gt; {&lt;BR /&gt; List&amp;lt;COMPortInfo&amp;gt; comPortInfoList = new List&amp;lt;COMPortInfo&amp;gt;();&lt;/P&gt;&lt;P&gt;ConnectionOptions options = ProcessConnection.ProcessConnectionOptions();&lt;BR /&gt; ManagementScope connectionScope = ProcessConnection.ConnectionScope(Environment.MachineName, options, @"\root\CIMV2");&lt;/P&gt;&lt;P&gt;ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0");&lt;BR /&gt; ManagementObjectSearcher comPortSearcher = new ManagementObjectSearcher(connectionScope, objectQuery);&lt;/P&gt;&lt;P&gt;using (comPortSearcher)&lt;BR /&gt; {&lt;BR /&gt; string caption = null;&lt;BR /&gt; foreach (ManagementObject obj in comPortSearcher.Get())&lt;BR /&gt; {&lt;BR /&gt; if (obj != null)&lt;BR /&gt; {&lt;BR /&gt; object captionObj = obj["Caption"];&lt;BR /&gt; if (captionObj != null)&lt;BR /&gt; {&lt;BR /&gt; caption = captionObj.ToString();&lt;BR /&gt; if (caption.Contains("(COM"))&lt;BR /&gt; {&lt;BR /&gt; COMPortInfo comPortInfo = new COMPortInfo();&lt;BR /&gt; comPortInfo.Name = caption.Substring(caption.LastIndexOf("(COM")).Replace("(", string.Empty).Replace(")",&lt;BR /&gt; string.Empty);&lt;BR /&gt; comPortInfo.Description = caption;&lt;BR /&gt; comPortInfoList.Add(comPortInfo);&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; return comPortInfoList;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; &lt;BR /&gt; /*********************************************************************&lt;BR /&gt; *&amp;nbsp;Base Class&lt;BR /&gt; **********************************************************************/&lt;BR /&gt; public class MySerialPort : SerialPort&lt;BR /&gt; {&lt;BR /&gt; private const int DataSize = 256; // &lt;BR /&gt; private readonly byte[] _bufer = new byte[DataSize];&lt;BR /&gt; private int _stepIndex = 0;&lt;BR /&gt; /// &amp;lt;/summary&amp;gt;&lt;BR /&gt; public MySerialPort()&lt;BR /&gt; : base()&lt;BR /&gt; {&lt;/P&gt;&lt;P&gt;// Set parameter&lt;BR /&gt;base.BaudRate = 115200;&lt;BR /&gt; base.DataBits = 8;&lt;BR /&gt; base.StopBits = StopBits.One;&lt;BR /&gt; base.Parity = Parity.None;&lt;BR /&gt; base.ReadTimeout = 1000;&lt;BR /&gt; base.DtrEnable = true;&lt;/P&gt;&lt;P&gt;_stepIndex = 0;&lt;BR /&gt; if (base.IsOpen)&lt;BR /&gt; base.Close();&lt;/P&gt;&lt;P&gt;// Event Data&amp;nbsp;&lt;SPAN&gt;Received;&lt;/SPAN&gt;&lt;BR /&gt; base.DataReceived += SerialPort_DataReceived;&lt;BR /&gt; //&lt;SPAN&gt; Event Error&lt;/SPAN&gt;&lt;BR /&gt; base.ErrorReceived += SerialPort_ErrorReceived;&lt;BR /&gt; }&lt;BR /&gt; //=================================================================================== &lt;BR /&gt; void SerialPort_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)&lt;BR /&gt; {&lt;BR /&gt; // if(e.EventType == SerialError.TXFull).....&lt;BR /&gt; MessageBox.Show("Error recieved: " + e.EventType);&lt;BR /&gt; }&lt;BR /&gt; //&amp;nbsp;Open Port "com1"&lt;BR /&gt; public void Open(string portName)&lt;BR /&gt; {&lt;BR /&gt; try&lt;BR /&gt; {&lt;BR /&gt; if (base.IsOpen)&lt;BR /&gt; {&lt;BR /&gt; base.Close();&lt;BR /&gt; }&lt;BR /&gt; base.PortName = portName;&lt;BR /&gt; base.Open();&lt;BR /&gt; base.DiscardInBuffer();&lt;BR /&gt; _stepIndex = 0;&lt;BR /&gt; }&lt;BR /&gt; catch { }&lt;/P&gt;&lt;P&gt;_stepIndex = 0;&lt;BR /&gt; }&lt;BR /&gt; //------&amp;gt; Out Data &amp;lt;-------&lt;BR /&gt; public void Send_CmdData(byte[] buffer)&lt;BR /&gt; {&lt;/P&gt;&lt;P&gt;byte CS = 0;&lt;BR /&gt; try&lt;BR /&gt; {&lt;BR /&gt; for (byte i = 0; i &amp;lt; buffer[1] - 1; i++)&lt;BR /&gt; CS += buffer[i];&lt;/P&gt;&lt;P&gt;buffer[buffer[1] - 1] = (byte)(~CS + 1);&lt;BR /&gt; base.Write(buffer, 0, buffer[1]);&lt;BR /&gt; }&lt;BR /&gt; catch { }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// --Test Input Data&lt;BR /&gt; void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)&lt;BR /&gt; {&lt;BR /&gt; var port = (SerialPort)sender;&lt;BR /&gt; try&lt;BR /&gt; {&lt;BR /&gt; //&amp;nbsp;&lt;BR /&gt; int buferSize = port.BytesToRead;&lt;BR /&gt; for (int i = 0; i &amp;lt; buferSize; ++i)&lt;BR /&gt; {&lt;BR /&gt; //&amp;nbsp;&lt;BR /&gt; _bufer[_stepIndex++] = (byte)port.ReadByte();&lt;BR /&gt; if (_stepIndex == 1)&lt;BR /&gt; {&amp;nbsp;&lt;BR /&gt; if (0x05 != _bufer[0]) _stepIndex = 0;&lt;BR /&gt; else continue;&lt;BR /&gt; }&lt;BR /&gt; else&amp;nbsp;&lt;BR /&gt; if ((_stepIndex &amp;gt;= DataSize) || (_stepIndex == _bufer[1]))&lt;BR /&gt; {&lt;BR /&gt; byte CS = 0;&lt;BR /&gt; for (int j = 0; _stepIndex != 0; _stepIndex--)&lt;BR /&gt; CS += _bufer[j++];&lt;BR /&gt; if (CS == 0)&lt;BR /&gt; {&lt;BR /&gt; _stepIndex = 0; // ..&amp;nbsp;&lt;BR /&gt; Egor_Host.Egor.CallBackMy.callbackEventHandler(_bufer);&lt;BR /&gt; // Egor_Host.FreqStripStatus.Text += "+";&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt; catch { }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt; #endregion&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Feb 2017 09:15:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626260#M6615</guid>
      <dc:creator>PitOn</dc:creator>
      <dc:date>2017-02-16T09:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Has anyone managed to use KSDK CDC Example with Windows WriteFile?</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626261#M6616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for that. &amp;nbsp;Is this code you have successfully used with the SDKD CDC?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Feb 2017 19:33:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626261#M6616</guid>
      <dc:creator>ashesman</dc:creator>
      <dc:date>2017-02-16T19:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Has anyone managed to use KSDK CDC Example with Windows WriteFile?</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626262#M6617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes. Based&amp;nbsp;&lt;A href="https://community.nxp.com/thread/377609"&gt;https://community.nxp.com/thread/377609&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Feb 2017 12:43:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626262#M6617</guid>
      <dc:creator>PitOn</dc:creator>
      <dc:date>2017-02-17T12:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Has anyone managed to use KSDK CDC Example with Windows WriteFile?</title>
      <link>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626263#M6618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK. &amp;nbsp;thanks, will give it a go. &amp;nbsp;Note that the last person that posted in the forum you mention has the same problem I am having!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Feb 2017 19:36:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Software-Development-Kit/Has-anyone-managed-to-use-KSDK-CDC-Example-with-Windows/m-p/626263#M6618</guid>
      <dc:creator>ashesman</dc:creator>
      <dc:date>2017-02-19T19:36:08Z</dc:date>
    </item>
  </channel>
</rss>

