Using the CDC example in the manual works flawlessly, however when I attempt to implement my own copy, such as:
public static void Execute()
{
// Create serial endpoint
SerialPort serial = new SerialPort("COM4",57600);
// Open serial port
serial.Open();
try {
// Remap serial port
RemapSerialPort(serial);
// Create buffer to read into
byte[] buffer = new byte[512];
// Update text
LCDDriver.Line1.Text = "GPS to USB";
LCDDriver.Line1.ScrollInterval = 0;
LCDDriver.Line2.Text = "Select to Cancel";
LCDDriver.Line2.ScrollInterval = 0;
// 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 usb = USBClientController.StandardDevices.StartCDC();
try {
// Set key down
bool key_down = false;
while (true) {
// Get key
LCDDriver.Key key = LCDDriver.CurrentKey;
// Process key
switch (key) {
case LCDDriver.Key.None: {
// Reset key down
key_down = false;
// Break
break;
}
case LCDDriver.Key.Select: {
// If key is not down
if (!key_down) {
// Return
return;
// Flag key down
//key_down = true;
}
// Break
break;
}
}
if (serial.IsOpen && serial.BytesToRead > 0) {
// Read in buffer from serial
int num_read = serial.Read(buffer,0,buffer.Length);
// Write out buffer to USB
if (num_read > 0 && USBClientController.GetState() == USBClientController.State.Running) usb.Write(buffer,0,num_read);
}
// Sleep for a bit
Thread.Sleep(10);
}
} finally {
// Stop CDC
USBClientController.Stop();
}
} finally {
// Close serial port
serial.Close();
}
}
I get an error thrown on the StartCDC() call:
And I’m unsure why, am I missing something?