CDC Read Method for terminal input from PC

Stumped again! (you’d think Yoda would be smarter - guess I picked the wrong avatar) I’ve read everything I can find in the forum, but still need some help in using the virtual com port for user input from the PC.

Quite simply, I need a way for a user to update the time in the RTC on either a Panda II or Domino. One way would be for the user to enter a string such as mm/dd/yyyy hh:mm:ss using a terminal program connected to the VCOM port. I’ve coded in the example and can open the port and print hello world ad infinitum, but am having some difficulty understanding how to use the CDC.Read method to input a string. The examples I’ve studied for serial port input don’t appear to use the cdc.Read method.

I know I need to create an input buffer and sense when the user hits the return key, but being new to C# I’m not sure of the syntax. Here’s a snippet of what I have so far with “?” where I know I need advice.

        public static void Main()
        {
            // Check debug interface
            if (Configuration.DebugInterface.GetCurrent() == Configuration.DebugInterface.Port.USB1) throw new InvalidOperationException("Current debug interface is USB. It must be changed to something else before proceeding. Refer to your platform user manual to change the debug interface.");
            // Start CDC
            USBC_CDC cdc = USBClientController.StandardDevices.StartCDC();
            // Send "Hello world!" to PC. (Append a new line too)
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes("Please enter the correct time in mm/dd/yyyy hh:mm:ss format \r\n");
            byte[] inbytes = new Byte[100];
            while (true)
            {
                // Check if connected to PC
                if (USBClientController.GetState() != USBClientController.State.Running)
                {
                    Debug.Print("Waiting to connect to PC...");
                }
                else
                {
                    cdc.Write(bytes, 0, bytes.Length);
                    cdc.Read(inbytes, 0, bytes.Length???);
                }
            }

I’d also be interested in any advice for just setting the FEZ system to the PC clock anytime they are connected via USB.

Thanks in advance for any help.

Two projects come to mind for reference:

[url]http://code.tinyclr.com/project/191/telnet-type-class-for-netmf/[/url]

and

[url]http://wiki.tinyclr.com/index.php?title=FezTerm[/url]

Have a look there for some insight

Definitely FezTerm. You need ReadLine method inside FezTermHost class.

Thanks to you both. I’d seen these, but naively though there might be a less complex solution to just read in a time & date string. I have downloaded FezTerm and will get back to work.

Eric and Architect, Many thanks - Fez Term is slick. I thought it was when I first saw the video a month ago, but was too much of a newbie to figure out how to get it running. Your advice today was great. I also should be able to learn a lot from how you structured your code.

I did change the “StartCDC_WithDebugging()” to just “StartCDC()” since I’m using a serial shield for debug and this seems to work fine. I also had to do some housekeeping like setting the reference paths, but overall I was pleased with how easily it went together and ran.

Your help is appreciated.

Coolness :slight_smile: That has got more traction then I thought it would. Maybe I should try to sell it for “One million dollars”.

Kudos to you, William. FezTerm is a nice piece of work. I meant to say William’s code in the last post as I knew you were the author. By the way, keep the Avatar avatar - Mike Myers is cool, but not quite the same image.

+1. Thank you, William.

My avatar is avatar still (what else would I use? :-). Picture of mike was added to bottom of post. Cheers