EMX SDK 4.2.9: CDC stalls

[edit]: changes done according to Gus Comments[\edit]

Hi Everyone

Our application need to exchange data between EMX custom board and a computer. The problem is that the CDC seems to stall after a while. To investigate, I have created a test code that send a xml file to the computer:

using System;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;
using GHI.Premium.Hardware;
using GHI.Premium.USBClient;
using GHI.Premium.IO;

namespace EMX_Application1
{
    public class Program
    {


        // Hold a static reference in case the GC kicks in and disposes it automatically, note that we only support one in this example!
        static PersistentStorage ps;

        public static void Main()
        {

            // Subscribe to RemovableMedia events
            RemovableMedia.Insert += RemovableMedia_Insert;
            RemovableMedia.Eject += RemovableMedia_Eject;

            // Assume SD card is inserted
            // Create a new storage device
            ps = new PersistentStorage("SD");
            ps.MountFileSystem();

          
            Debug.Print(Resources.GetString(Resources.StringResources.String1));

            // Start CDC
            USBC_CDC cdc = USBClientController.StandardDevices.StartCDC();

         
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes("Hello world!\r\n");
            int iter = 0;
            while(true)
            {
                iter++;
                // Check if connected to PC
                if(USBClientController.GetState() !=
                    USBClientController.State.Running)
                {
                    Debug.Print("Waiting to connect to PC...");

                }
                else
                {
                    Debug.Print("Iter number" + iter);
                    Thread.Sleep(1000);

                    cdc.Write(bytes,0,bytes.Length);
                    FileStream f = new FileStream("\\SD\\yourfile.txt",FileMode.Open,FileAccess.Read,FileShare.None,8);
                    long bytesRemaining;
                    int bytesRead;
                    byte[] data;
                    bytesRemaining = f.Length;
                    Thread.Sleep(1);

                    while(bytesRemaining > 0)
                    {
                        data = new byte[(bytesRemaining > 64) ? 64 : bytesRemaining];
                        bytesRead = f.Read(data,0,data.Length);
                        cdc.Write(data,0,data.Length);
                        bytesRemaining -= bytesRead;
                    }
                    f.Close();
                    f.Dispose();
                }
                Thread.Sleep(1);
            }
        }


        static void RemovableMedia_Eject(object sender,MediaEventArgs e)
        {
            Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is ejected.");
        }
        static void RemovableMedia_Insert(object sender,MediaEventArgs e)
        {
            Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is inserted.");
            Debug.Print("Getting files and folders:");
            if(e.Volume.IsFormatted)
            {
                string[] files = Directory.GetFiles(e.Volume.RootDirectory);
                string[] folders = Directory.GetDirectories(e.Volume.RootDirectory);

                Debug.Print("Files available on " + e.Volume.RootDirectory + ":");
                for(int i = 0;i < files.Length;i++)
                    Debug.Print(files[i]);

                Debug.Print("Folders available on " + e.Volume.RootDirectory + ":");
                for(int i = 0;i < folders.Length;i++)
                    Debug.Print(folders[i]);

            }
            else
            {
                Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
            }


        }
    }
} 

Does anyone can help in finding a solution to this problem?

Can you please take anything not related out of the test code? (XML or anything else)

We will run the test but the simpler the program the faster we progress.

xml is just the extension of the file, there’s nothing related with xml especially it could be txt or dat file…

Hi Gus. It seems better when I use a length of 1024 for the buffer (better but still need to test more)

We will test this once the SDK coming out this week is done.

4.2.10.0 fixed it.

may we have 4.2.10 available for VS2010? I only have vista and VS2012 can not be installed…

There’s something also very strange. Since the 4.2.9 sdk, we can not use the serial port from .net (winforms) to connect to the CDC. The port is seen System.IO.Ports.SerialPort.GetPortNames(); returns properly the good list of com ports but the open fails. The same thing happens with docklight. However it works with Terraterm… Any idea?

@ leforban - VS2010 is and was always available. We only recommended VS2012 in the future.

Hi Gus.

The SDK that I found in: Support > Net Micro Framework, is labelled as 4.2.9 whereas Dat talks about a 4.2.10 (is it a beta of 4.3 ?). Is it the famous 25th april sdk?

Lets keep this clear and wait couple hours :slight_smile: I think the SDK will be up soon and all will be cleared up in the news post.

And then? does the 4.2.10 is the one that we found in the April 25th SDK post?

@ GUS sorry you send your message while I was writing mine. I started to try to find solution to cdc bug (and others) a week ago and did not succeed to get something stable in a week… my company need results faster… if CDC is still unreliable, we need to move now on other solutions (like ethernet). I can wait but really need to know sdk due date in order to organize internal works.

Give us few minutes please. It is almost up…

Here is the release notes for it http://www.ghielectronics.com/docs/40/netmf-4.2-developer

Firmware version is listed there as well.

wow I hope I will be abble to test it tomorrow morning!!! Thanks for your replies

@ andre.m - done

Is it normal that EMX updater disappear with 4.2.10?

yes, mentioned elsewhere. Will be available via download link in original post by Josh tomorrow.

edit see http://www.ghielectronics.com/community/forum/topic?id=11849&page=1#msg120778