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.