AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Cross-Platform-Entwicklung Komponente Android Daten USB senden/empfangen
Thema durchsuchen
Ansicht
Themen-Optionen

Komponente Android Daten USB senden/empfangen

Ein Thema von Bierwut-Tom · begonnen am 8. Jan 2016 · letzter Beitrag vom 24. Mär 2016
Antwort Antwort
Seite 3 von 4     123 4      
wschrabi

Registriert seit: 16. Jan 2005
448 Beiträge
 
#21

AW: Komponente Android Daten USB senden/empfangen

  Alt 23. Mär 2016, 09:36
Yep. It will need (a lot) more work to implement reports.
And if that is the case, you will have to have a little patience.
Sorry for that. I will report back.
thanks don, I am not soo sophisticated than you are, and now it is clear that I need not to break my minds.
But generally, it could be implementated with Android API to make REPORTs, right?
If so, I need someone how makes it.

Moreover, I have done the firmware for my device. Its like a mouse. Maybe it is easier to change the
mouse firmware (which is not interruped) into a HID with interupes.
Do you know what I have generally to change ? The mouse firmware I have done step by step according a how-to manual. It transfers only 12 BYTES when I hit one DIP switch.

In My WIN Prg I poll by getting reports the device and get the 12 Bytes which are interpreted than.

If it would be done by interuppes, I just could use the OnData Handler and it would be quite easy with
the JVCL Lib.

Thanks for help
Walter
  Mit Zitat antworten Zitat
wschrabi

Registriert seit: 16. Jan 2005
448 Beiträge
 
#22

AW: Komponente Android Daten USB senden/empfangen

  Alt 23. Mär 2016, 09:38
I just had a quick look on how to send/get a report.
You need to do a controltransfer.
I you look at: function TJvHidDevice.GetDeviceString(Idx: Byte): string;
You will find an example on how to do a controltransfer.
It could give you a start.
thanks , that is a help. I will investigate.
I would be thankful if I can ask you (many) more.
thanks

PS: One more question:
Would this be a way to make the prg debugable?
My Device is connected to the ANdroid usb OTG. So I can not debug via Delphi and the device is connected.
So My idea:
Wo make the same way with WIN API with the control transfer, as my device can be connected to WINDOWS and so
I can debug the prg too.
When It works on win I copy it to my Android program.
Would this a way to start the investigation?

I tried: But I do not get an aquivalent function in the WIN API (Hid.dll) for
Code:
 FUsbDeviceConnection.controlTransfer
.
How can I make a controltransfer with win api wihtout using the ready made GEt_Report.
Any ideas?

Thanks

Geändert von wschrabi (23. Mär 2016 um 10:02 Uhr)
  Mit Zitat antworten Zitat
DonAlfredo

Registriert seit: 13. Mai 2010
19 Beiträge
 
#23

AW: Komponente Android Daten USB senden/empfangen

  Alt 23. Mär 2016, 10:09
Ok.
I have added a quick and dirty feature report (see GitHub).
Not tested. Just use it as a start. Adapt for your needs.
Now I have to go back to normal business.
Alfred
  Mit Zitat antworten Zitat
wschrabi

Registriert seit: 16. Jan 2005
448 Beiträge
 
#24

AW: Komponente Android Daten USB senden/empfangen

  Alt 23. Mär 2016, 10:40
I have tried it this way.
Code:
function TJvHidDevice.GetFeatureReport: string;
const
  STD_USB_REQUEST_RECIPIENT = $01; // Interface
  STD_USB_REQUEST_GET_REPORT = $01; //HID GET_REPORT
  STD_USB_REQUEST_SET_REPORT = $09; //HID SET_REPORT
  LIBUSB_FEATURE_REPORT = $0301; //Feature report ($0300), ID = 1 ($01)
  LIBUSB_FEATURE_REPORT_LENGTH = $FF;

  (* my try
  //STD_USB_REQUEST_GET_DESCRIPTOR = $06;
  STD_USB_REQUEST_GET_REPORT = $01;
  STD_USB_REQUEST_TYPE_GET_REPORT = $A1;  
  STD_USB_REQUEST_VALUE_GET_REPORT = $100;  
  LIBUSB_DT_STRING = $03;
  *)
 
var
  i,rdo:integer;
  buffer : TJavaArray<Byte>;
  S : String;
begin

  if Openfile then
  begin

    buffer := TJavaArray<Byte>.Create(255);

    rdo := FUsbDeviceConnection.controlTransfer(
           (TJUsbConstantsUSB_DIR_IN OR TJUsbConstantsUSB_TYPE_CLASS OR STD_USB_REQUEST_RECIPIENT),
           STD_USB_REQUEST_GET_REPORT,
           LIBUSB_FEATURE_REPORT,
           0,
           buffer,
           LIBUSB_FEATURE_REPORT_LENGTH,
           2000);
    (* my try
    rdo := FUsbDeviceConnection.controlTransfer(
           STD_USB_REQUEST_TYPE_GET_REPORT,
           STD_USB_REQUEST_GET_REPORT,
           STD_USB_REQUEST_VALUE_GET_REPORT,  
           0,
           buffer,
           $0B,
           0);
    *)
           

    if rdo<0 then
    begin
      buffer.Free;
      result:='';
      exit;
    end;

    if rdo>255 then rdo:=255;

    S:='';
    for i:=0 to rdo do
    begin
      S:=S+Char(buffer.Items[i]);
    end;
    result:=S;
    buffer.Free;
  end
  else result:='';
end;
Accoring to my sniffer snappshot of my working windows prg.
(See attached screeshoot)
Miniaturansicht angehängter Grafiken
getreport.jpg  

Geändert von wschrabi (23. Mär 2016 um 10:49 Uhr) Grund: just got the try from Don - similar to my try
  Mit Zitat antworten Zitat
wschrabi

Registriert seit: 16. Jan 2005
448 Beiträge
 
#25

AW: Komponente Android Daten USB senden/empfangen

  Alt 23. Mär 2016, 10:41
Ok.
I have added a quick and dirty feature report (see GitHub).
Not tested. Just use it as a start. Adapt for your needs.
Now I have to go back to normal business.
Thanks, I will try your solution:

The ShardeActivity... is not recognized in your file.

In the new Github file, you forgot this file in the uses clauses.
Code:
  FMX.Helpers.Android

Geändert von wschrabi (23. Mär 2016 um 10:57 Uhr)
  Mit Zitat antworten Zitat
wschrabi

Registriert seit: 16. Jan 2005
448 Beiträge
 
#26

AW: Komponente Android Daten USB senden/empfangen

  Alt 23. Mär 2016, 11:49
Dear Don,
one furhter question:

My Firmware has no Serial Number. COuld this be a problem, that I can not open a file.
As If OpenFile is always false.

I can re_flash my firmware with a serial number, but how can I enumerate the usb device
without one.

Thanks
walter
  Mit Zitat antworten Zitat
DonAlfredo

Registriert seit: 13. Mai 2010
19 Beiträge
 
#27

AW: Komponente Android Daten USB senden/empfangen

  Alt 23. Mär 2016, 13:43
I think you are referring to usb.pas ?!

If so, this usb.pas is tailor made for my application.

It is a measurement system with sometimes over 25 mcu's. All connected by USB.
All mcu's have a serial, so that the app can distinguisch them.
On initial connect, a serial is generated by the main system, and stored in firmware of the mcu.

If you do not connect multiple identical USB HID devices onto a single system, then you do not need the whole serial selection protocol.

Just use:
Code:
HidCtl.OnArrival:= DeviceArrival;
HidCtl.OnRemoval:= DeviceRemoval;
Also adjust
Code:
TReport = packed record
  ReportID: byte;
  Data:   array [0..15] of byte; // adjust 15 to fit your datapacket lenghth (often 64 bits so 63 is a good guess!!)
end;
Alfred
  Mit Zitat antworten Zitat
wschrabi

Registriert seit: 16. Jan 2005
448 Beiträge
 
#28

AW: Komponente Android Daten USB senden/empfangen

  Alt 23. Mär 2016, 13:50
On initial connect, a serial is generated by the main system, and stored in firmware of the mcu.

If you do not connect multiple identical USB HID devices onto a single system, then you do not need the whole serial selection protocol.

Just use:
Code:
HidCtl.OnArrival:= DeviceArrival;
HidCtl.OnRemoval:= DeviceRemoval;
Also adjust
Code:
TReport = packed record
  ReportID: byte;
  Data:   array [0..15] of byte; // adjust 15 to fit your datapacket lenghth (often 64 bits so 63 is a good guess!!)
end;
thanks Don, I only have one USB Device, but no EP-OUT defined in the Firmware, so writing a serial to the device is not possible.
I have only one IN EP, like a mouse.

BTW: For what is that:
{.$define WITHPERMISSION}

I see that you use this here:
Code:
...
    {$ifdef WITHPERMISSION}
    FPermissionIntent : JPendingIntent;
    {$endif}
...
        {$ifdef WITHPERMISSION}
        FMyController.UsbManager.requestPermission(FUsbDevice,FMyController.PermissionIntent);
        {$endif}
Do I need that on my Tablet?

One more I think to change:
I have a NON INterupted HID Device and in your code there is:
Code:
 // Get HID endpoint 1
      if FUsbInterface.getEndpointCount>1 then
      begin
        FUsbEP := FUsbInterface.getEndpoint(1);
        if FUsbEP.getType=TJUsbConstantsUSB_ENDPOINT_XFER_INT then
        begin
          if FUsbEP.getDirection = TJUsbConstantsUSB_DIR_OUT then
          begin
            FEpOut := FUsbEP;
          end
          else if FUsbEP.getDirection = TJUsbConstantsUSB_DIR_IN then
          begin
            FEpIn := FUsbEP;
          end;
        end;
      end;
I think the TJUsbConstantsUSB_ENDPOINT_XFER_INT must also change. RIght?

Thank you very much!

Geändert von wschrabi (23. Mär 2016 um 14:28 Uhr)
  Mit Zitat antworten Zitat
DonAlfredo

Registriert seit: 13. Mai 2010
19 Beiträge
 
#29

AW: Komponente Android Daten USB senden/empfangen

  Alt 23. Mär 2016, 16:02
I think you do not need the permission part.
As long as you apply the device filter (device_filter.xml ; with your values).

AFAIK, you do not use the interrupt endpoints, so they are not important for your programme.
Alfred
  Mit Zitat antworten Zitat
wschrabi

Registriert seit: 16. Jan 2005
448 Beiträge
 
#30

AW: Komponente Android Daten USB senden/empfangen

  Alt 23. Mär 2016, 18:26
Alfred, yes that was an issue, I need the permission define.
Now I can get my 12 Bytes from the Device by GET_REPORT Request.
Thank you very very much for your help.
Best regards
Walter
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 3 von 4     123 4      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:05 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz