If you’ve set up a virtual COM port with cdc and specified a cdc.ReadTimeout = 20,000 what happens when the timeout is reached? For example in the following code snippet where will the program go if the user hasn’t entered any characters and the timeout is reached?
cdc.ReadTimeout = 20000;
// Simple loop that reads single chars until delim byte
ArrayList line = new ArrayList();
byte[] buf = new byte[1];
int count = 0;
while ((count = cdc.Read(buf, 0, 1)) > 0)
{
if (buf[0] == delim)
{
cdc.Write(buf, 0, buf.Length); // echo to term
buf[0] = lf;
cdc.Write(buf, 0, buf.Length);
goto convert;
}
line.Add(buf[0]);
cdc.Write(buf, 0, buf.Length);
// byte echo = buf[0];
}
// Convert ArrayList to char[] using UTF8 encoding.
convert:
Maybe the bigger question to ask is how would you get your system to automatically switch to a mass storage device if a user doesn’t connect to a virtual com port within a specified period of time. I’m trying to find a way to give the user a chance to input data without losing the automatic startup of the SD card as a mass storage device. I’d also like the program to switch to a data logging mode when there is no USB connection and the power is applied through Vin on the Panda II, but I know I can do that by checking the USBClientController.State.
I know I could force the user to open the COM port and then choose between data input or mass storage, but I’d like to know if there are any neat alternatives.