Due + barcode scanner

barcode scannerHi everybody
I tried to connect the barcode scanner to Arduino DUE. I googled but all the examples I found used a USB host shield. I tried to connect the scanner to native USB port and use the USBHost library.
I used Keyboard Controller example. Just to see if there is any response in Serial.
here is the link for barcode scanner data sheet.


#include <KeyboardController.h>

// Initialize USB Controller

USBHost usb;

// Attach keyboard controller to USB

KeyboardController keyboard(usb);

// This function intercepts key press
void keyPressed() {

  Serial.print("Pressed:  ");

  printKey();
}

// This function intercepts key release
void keyReleased() {

  Serial.print("Released: ");

  printKey();
}

void printKey() {

  // getOemKey() returns the OEM-code associated with the key

  Serial.print(" key:");

  Serial.print(keyboard.getOemKey());

  // getModifiers() returns a bits field with the modifiers-keys

  int mod = keyboard.getModifiers();

  Serial.print(" mod:");

  Serial.print(mod);

  Serial.print(" => ");

  if (mod & LeftCtrl)

    Serial.print("L-Ctrl ");

  if (mod & LeftShift)

    Serial.print("L-Shift ");

  if (mod & Alt)

    Serial.print("Alt ");

  if (mod & LeftCmd)

    Serial.print("L-Cmd ");

  if (mod & RightCtrl)

    Serial.print("R-Ctrl ");

  if (mod & RightShift)

    Serial.print("R-Shift ");

  if (mod & AltGr)

    Serial.print("AltGr ");

  if (mod & RightCmd)

    Serial.print("R-Cmd ");

  // getKey() returns the ASCII translation of OEM key

  // combined with modifiers.

  Serial.write(keyboard.getKey());

  Serial.println();
}

void setup()
{

  Serial.begin(115200);

  Serial.println("Program started");

  delay(200);
}

void loop()
{

  // Process USB tasks

  usb.Task();
}

this code working properly witch usb keyboard but not witch barcode scanner .please suggest what to do.

Your scanner supports serial and keyboard modes. How did you check that it uses the correct mode? If it's in keyboard and above sketch works for a keyboard but not for the scanner, then there is an automatic mode switch that occurs if the scanner doesn't detect a PC with an operating system (although I have found nothing about that in the docs).

thanks for support .

sir cheek it by open in Notepad and scan barcode it working in usb mode. But i still have same condition . it not working with usb hot Keyboard control library .

There is no USB mode. It has a keyboard emulation mode and a serial emulation mode.

It's interesting, that this code works with a keyboard as this code does nothing.

Sir I tried it with note pad , in note pade barcode scanner working properly.

Sure, that runs on a full-fledged OS which know how USB HID works.

For your sketch you have copied most of the KeyboardController example. Why did you eliminate the code that detects the device changes?
The scanner may react differently from a standard keyboard and therefor doesn't get detected by the code. Without having the device this is hard to tell. Try to find details of the USB device on your PC. I can tell you how to do that on Linux but I have no clue what tools you need on Windows for that.

Thank you for your valuable support.