MKR1010+USB CDC how is it work ?

Hello,

I’m some problem with new barcode reader Zebra DS9908.

my last post : Topic about USB host and barcode reader

to find another way, I set my barcode reader to “USB CDC”. That works with a Serial Terminal on my PC.

I found that MKR can use USB CDC : Serial reference

I write those code form an example :

  • I assume Serial is the USB CDC and Serial1 is for monitoring.
String inputString = "";         // a String to hold incoming data
bool stringComplete = false;  // whether the string is complete

#define SERIAL_PORT_MONITOR Serial1

void setup() {
  // initialize serial:
  Serial.begin(9600);
  Serial1.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
  while (!SERIAL_PORT_MONITOR); 
  Serial1.println("Program started...");
}

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial1.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the hardware serial RX. This
  routine is run between each time loop() runs, so using delay inside loop can
  delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

But like my previous post, my reader is not wake up even if the tension is 5V with an power 1A/5V.

My question about USB CDC :

  • is my code is good ?
  • is it possible to use two COM serial on MKRWIFI1010 ?

best regards

I changed a little with logs.
"Program started" is shown but not the second "USB CDC initialized".

My barcode reader does not wakeup and can't answer to the board.

  Serial1.begin(9600); 
  while (!SERIAL_PORT_MONITOR); 
  Serial1.println("Program started...");
  
  Serial.begin(9600);
  while (!Serial);
  Serial1.println("USB CDC initialized");