Go Down

Topic: USB_Host_Shield_2.0 lib  (Read 82 times) previous topic - next topic

RdeB

hello,

i have a project with a Keyes  USB_Host_Shield,  Arduino Uno and a USB barcode scanner.

i downloaded from gridhub and some other sits a code and it is working at home fine. but at work it will not work i tested it on 3 computers form windos 8 to 10. But all 3 compurters at work it will not work.
a copyed the libarys ( USB_Host_Shield_2.0-master and USBHID)  from my home computer to the work computers bus still same error.

the error is:
cannot declare Variable 'Prs' to be of abstract type'KbdRptParser'

first i was thinking it is a fault in a libary but i can not find it.
does anyone has an idea where to look?

this is te code:

/*
 
Portable barcode scanner. Uses USB HID barcode scanner, Arduino Board, USB Host Shield
 
*/
#include <hid.h>
#include <hiduniversal.h>
#include <avr/pgmspace.h>
#include <Usb.h>
#include <usbhub.h>
#include <hidboot.h>

USB     Usb;
USBHub     Hub(&Usb);
HIDUniversal    Hid(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);
 
class KbdRptParser : public KeyboardReportParser
{
         void PrintKey(uint8_t mod, uint8_t key);
protected:
  virtual void OnKeyDown  (uint8_t mod, uint8_t key);
  virtual void OnKeyPressed(uint8_t key);
};
 
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) 
{
    uint8_t c = OemToAscii(mod, key);
 
    if (c)
        OnKeyPressed(c);
}
 
/* what to do when symbol arrives */
void KbdRptParser::OnKeyPressed(uint8_t key) 
{
static uint32_t next_time = 0;      //watchdog
static uint8_t current_cursor = 0;  //tracks current cursor position 
 
    if( millis() > next_time ) {
     Serial.print(" - start - ");
      //Serial.println(" - Finished");
           
    }//if( millis() > next_time ...
 
    next_time = millis() + 200;  //reset watchdog
   
    Serial.print( (char)key );
       
};

KbdRptParser Prs;
 
void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");
 
    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }
 
    delay( 200 );
 
    Hid.SetReportParser(0, (HIDReportParser*)&Prs);
   
   
    delay( 200 );
}
 
void loop()
{
  Usb.Task();
}

PaulS

Code: [Select]
class KbdRptParser : public KeyboardReportParser
{
         void PrintKey(uint8_t mod, uint8_t key);
protected:
  virtual void OnKeyDown  (uint8_t mod, uint8_t key);
  virtual void OnKeyPressed(uint8_t key);
};

The KbdRptParser class has virtual functions. They are not pure virtual functions, which would mean that a derived class was needed, and that that class must implement the methods. It would also mean that the KbdRptParser class was an abstract class that can not be instantiated.

So, it appears that the compiler is wrong. But, there could be pure virtual methods defined in KeyboardReportParser, which the KbdRptParser doesn't implement, which would mean that the compiler is right.

Without a link to the location where you got the code, no one can say what the real problem is.
The art of getting good answers lies in asking good questions.

RdeB

Hello,

Thanks for the feedback.

 
I got the link from:

https://www.circuitsathome.com/mcu/connecting-barcode-scanner-arduino-usb-host-shield/

then I looked at this Youtube link.

https://www.youtube.com/watch?v=t5gkg645xGE

it is a code from Oleg Mazurov

and at last I deleted the liquidCrystal display I do not need a display.

gbafamily

Try the USB keyboard example included with the library.

https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino

RdeB

Hello

Thanks for the feedback.

The USBHIDBootKbd.Ino is working fine for a Keyboard. but for triggering a Barcode scanner it dit not work.

But i have solved it, (sort of).  I deleted the Libary USB_Host_Shield_2.0-master and replaced it with a older version of USB_Host shield lib

now it is works at home as well as at the office.
At least it works for me and the hardware i am working with.

Hardwere:
Arduino uno  + Keyew USB shield + USB Kercan 1D/2D barcode scanner.

software :
arduino 1.8.9

Code: [Select]
/*
 
Portable barcode scanner. Uses USB HID barcode scanner, Arduino Board, USB Host Shield
 
*/
#include <hid.h>
#include <hiduniversal.h>
#include <avr/pgmspace.h>
#include <Usb.h>
#include <usbhub.h>
#include <hidboot.h>

USB     Usb;
USBHub     Hub(&Usb);
HIDUniversal    Hid(&Usb);
HIDBoot<HID_PROTOCOL_KEYBOARD>    Keyboard(&Usb);
 
class KbdRptParser : public KeyboardReportParser
{
         void PrintKey(uint8_t mod, uint8_t key);
protected:
  virtual void OnKeyDown  (uint8_t mod, uint8_t key);
  virtual void OnKeyPressed(uint8_t key);
};
 
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) 
{
    uint8_t c = OemToAscii(mod, key);
 
    if (c)
        OnKeyPressed(c);
}
 
/* what to do when symbol arrives */
void KbdRptParser::OnKeyPressed(uint8_t key) 
{
static uint32_t next_time = 0;      //watchdog
static uint8_t current_cursor = 0;  //tracks current cursor position 
 
    if( millis() > next_time ) {
     Serial.print(" - start - ");
      //Serial.println(" - Finished");
           
    }//if( millis() > next_time ...
 
    next_time = millis() + 200;  //reset watchdog
   
    Serial.print( (char)key );
       
};

KbdRptParser Prs;
 
void setup()
{
    Serial.begin( 115200 );
    Serial.println("Start");
 
    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }
 
    delay( 200 );
 
    Hid.SetReportParser(0, (HIDReportParser*)&Prs);
   
   
    delay( 200 );
}
 
void loop()
{
  Usb.Task();
}

Go Up