Hi
I am trying to get a usb barcode reader to read successfully on a Fez Spider. I am using VS2010 in vb.net and SDK 4.2. The problem i have is the barcode reader connects fine and it is seen as a keyboard. when the event is fired all i get back from the controller is 255, 255,255 which i can take it from the help is that the data is not recognized as valid keys. if i plug a standard usb keyboard in its place i get exactly the key i pressed returned. I have plugged the barcode scanner into a PC usb port and get the barcode I am reading displayed in a text editor, so I know that the Barcode scanner is working as it should. I thought that maybe it was something to do with VB but i built a test app using C# ( which i am not proficient in) both give me the same result.
So either i am missing something in setting up the test. I have posted both my VB and C# code to show my workings.
Any help would be appreciated
Regards
Steve
VB Code
Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports GHI.Premium.USBHost
Imports GHI.Premium.System
Namespace UsbHostVBKeyboard
Partial Public Class Program
Dim WithEvents barReader As GHI.Premium.USBHost.USBH_Keyboard
Public Sub ProgramStarted()
Debug.Print(“Program Started”)
End Sub
Private Sub usbHost_KeyboardConnected(sender As Gadgeteer.Modules.GHIElectronics.UsbHost, Keyboard As GHI.Premium.USBHost.USBH_Keyboard) Handles usbHost.KeyboardConnected
barReader = New GHI.Premium.USBHost.USBH_Keyboard(Keyboard)
Debug.Print(“Keyboard/Reader Connected”)
End Sub
Private Sub barReader_CharDown(sender As GHI.Premium.USBHost.USBH_Keyboard, args As GHI.Premium.USBHost.USBH_KeyboardEventArgs) Handles barReader.CharDown
Debug.Print("CharDown: " & args.KeyAscii.ToString)
End Sub
Private Sub barReader_KeyDown(sender As GHI.Premium.USBHost.USBH_Keyboard, args As GHI.Premium.USBHost.USBH_KeyboardEventArgs) Handles barReader.KeyDown
Debug.Print("KeyDown: " & args.Key.ToString)
End Sub
End Class
End Namespace
C# Code
using System;
using System.Threading;
using Microsoft.SPOT;
using GHI.Premium.USBHost;
using GHI.Premium.System;
namespace Test
{
public class Program
{
static USBH_Keyboard kb;
public static void Main()
{
// Subscribe to USBH event.
USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
// Sleep forever
Thread.Sleep(Timeout.Infinite);
}
static void DeviceConnectedEvent(USBH_Device device)
{
if (device.TYPE == USBH_DeviceType.Keyboard)
{
Debug.Print("Keyboard Connected");
kb = new USBH_Keyboard(device);
kb.CharDown += CharDown;
kb.KeyDown += KeyDown;
}
}
static void CharDown(USBH_Keyboard sender, USBH_KeyboardEventArgs args)
{
// Display the pressed key
Debug.Print(args.KeyAscii.ToString());
}
static void KeyDown(USBH_Keyboard sender, USBH_KeyboardEventArgs args)
{
// Display the pressed key
Debug.Print("Key: " + args.Key.ToString());
}
}
}