Post Reply 
Reading USBRecv Problem
10-12-2023, 08:53 PM (This post was last modified: 10-12-2023 09:04 PM by toml_12953.)
Post: #1
Reading USBRecv Problem
I'm trying to read the data from a USB keyboard continuously.
Using the program below, I get

USBKBD Error: Bad
argument type

The same USB commands work on the Home screen just fine. All I want to do is stay in the loop until a key is pressed on the keyboard then print the HID data. What am I doing wrong?

Code:
EXPORT USBKBD()
BEGIN
LOCAL A:={0,0,0,0,0,0,0,0};

USBOpen(1084,8467);

WHILE A=={0,0,0,0,0,0,0,0} DO
  A:=USBRecv;
END;

PRINT(A);
END

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
10-12-2023, 09:25 PM
Post: #2
RE: Reading USBRecv Problem
USBRecv() returns an (empty) list.
Don't stick that in 'A'

ie A:={1,2,3} won't work well..
Find all posts by this user
Quote this message in a reply
10-12-2023, 09:52 PM (This post was last modified: 10-12-2023 10:20 PM by toml_12953.)
Post: #3
RE: Reading USBRecv Problem
(10-12-2023 09:25 PM)gehakte_bits Wrote:  USBRecv() returns an (empty) list.
Don't stick that in 'A'

ie A:={1,2,3} won't work well..

I got the following working. Now all I need to do is make a lookup table to print the character typed rather than the HID list. This code will work no matter what keyboard you use. My first draft would only work with one brand/model.

Code:
EXPORT USBKBD()
BEGIN
LOCAL A:={}, B:={};

PRINT();

B:=USBOpen();

USBOpen(B(1,1),B(1,2));

WHILE 1 DO
  REPEAT
    A:=USBRecv;
  UNTIL length(A)>0 AND A(3)≠0
  PRINT(A);
END;

END;

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
10-13-2023, 12:01 PM (This post was last modified: 10-13-2023 01:55 PM by toml_12953.)
Post: #4
RE: Reading USBRecv Problem
OK, here's the latest version. It correctly handles A-Z and a-z but no special characters and no Caps Lock.

Code:
EXPORT USBKBD()
BEGIN

  LOCAL A:={};

  PRINT();

  A:=USBOpen();

  USBOpen(A(1,1),A(1,2));

  WHILE 1 DO
    REPEAT
      A:=USBRecv;
    UNTIL length(A)>0 AND A(3)≠0
    //PRINT(A);
    IF A(1)==2 OR A(1)==32 THEN
      PRINT(CHAR(A(3)+61));
    ELSE
      PRINT(CHAR(A(3)+93));
    END;
  END;
END;

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 4 Guest(s)