@Johann: Is the Readme.rst at https://github.com/hansiglaser/pas-libusb
up to date ?
It states that only the legacy version 0.1 of libusb is supported, but
the binary package for Windows on libusb.info is in version 1.0.22.
You can get source code for old versions of libusb on github but it
seems at first glance that there are no release of windows version
before 1.0.20 (14 sep 2015) (
https://github.com/libusb/libusb/releases?after=v1.0.21-rc4 ).
I tried to compile TestFirmware.pas on windows, I made a few
modifications. I join the diff files.
In ezusb.pas I replaced the dependency to Errors unit by a quick and
dirty rewrite of StrError function, just to allow compilation.
In paslibusbutils.pas I replace the call to fpGetTimeOfDay by a call to
DateTimeToUnix(Now), I'm not sure may be the result of DateTimeToUnix
is truncated to seconds where fpGetTimeOfDay gives a result in microseconds.
In usb.pas I duplicated some constant definitions from errno.inc
included in unit BaseUnix: ESysETIMEDOUT, ESysEAGAIN...
I also replaced the call to fpSelect(0,Nil,Nil,Nil,100) by Sleep(100)
which should do the same thing, waiting for 100 milliseconds.
@James: Now, I just get the two final errors "Import library not found
for c" and "Import library not found for usb".
For now I haven't found which library to use for c.
I'm preparing another mail for this.
src/ezusb.pas | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/ezusb.pas b/src/ezusb.pas
index cf515fa..79947c0 100644
--- a/src/ezusb.pas
+++ b/src/ezusb.pas
@@ -43,7 +43,9 @@ Const ANCHOR_LOAD_INTERNAL = $A0; { Vendor specific request code for Anchor
CPUCS_8051RESET = $01; { 1: reset 8051, 0: run }
Implementation
-Uses SysUtils,Errors;
+Uses
+ //Errors,
+ SysUtils;
Const
EZUSBUnconfiguredConfiguration = 1;
@@ -94,6 +96,10 @@ Begin
End;
Function TUSBDeviceEZUSB.LoadMem(HexRecord:PIntelHexRecord):LongInt;
+ function StrError(err:integer): String;
+ begin
+ Result:= 'Error #'+IntToStr(err);
+ end;
Begin
While (HexRecord <> Nil) and (HexRecord^.TheType = 0) do
Begin
src/paslibusbutils.pas | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/paslibusbutils.pas b/src/paslibusbutils.pas
index 743746e..206eada 100644
--- a/src/paslibusbutils.pas
+++ b/src/paslibusbutils.pas
@@ -2,7 +2,14 @@
Unit PasLibUsbUtils;
Interface
-Uses SysUtils,StrUtils,Classes,BaseUnix,Unix;
+Uses
+ SysUtils,
+ //BaseUnix,
+ //Unix,
+ {$IFDEF MSWINDOWS}
+ dateutils,
+ {$ENDIF}
+ StrUtils,Classes;
Const HexChars = '0123456789ABCDEF';
@@ -25,10 +32,16 @@ Begin
End;
Function GetUSec : UInt64;
+{$IFDEF MSWINDOWS}
+begin
+ Result:= DateTimeToUnix( Now);
+end;
+{$ELSE}
Var TZ : TimeVal;
Begin
fpGetTimeOfDay(@TZ,Nil);
Result := TZ.tv_usec + TZ.tv_sec*1000000;
End;
+{$ENDIF}
End.
src/usb.pas | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/usb.pas b/src/usb.pas
index 62d2db3..1a81f6d 100644
--- a/src/usb.pas
+++ b/src/usb.pas
@@ -28,7 +28,9 @@ Unit USB;
Interface
Uses
- Classes, SysUtils, Baseunix, LibUSB;
+ Classes, SysUtils,
+ //Baseunix,
+ LibUSB;
(*****************************************************************************)
(** Procedural Interface ***************************************************)
@@ -241,6 +243,8 @@ Uses PasLibUsbUtils,Math;
Type TUSBExceptionType = Class of Exception;
Function USBException(Proc:String;Ret:LongInt) : Exception;
+//duplicated from errno.inc included in unit BaseUnix
+const ESysETIMEDOUT= 110;
Var Ex : TUSBExceptionType;
Begin
Case -Ret of
@@ -515,6 +519,7 @@ Begin
End;
Function USB_Send(Hnd:PUSBDevHandle;EP:LongInt;Const Buf;Length,Timeout:LongInt):LongInt;
+const ESysEAGAIN=11;
Var Loops : Integer;
Sent : LongInt;
ToSend : LongInt;
@@ -540,7 +545,8 @@ WriteLn('Problem with usb_bulk_write: Result = ',Result,', usb_error_errno = ',u
if (Loops > 0) and (usb_error_errno = ESysEAGAIN) then
Begin
Again := True;
- fpSelect(0,Nil,Nil,Nil,100);
+ //fpSelect(0,Nil,Nil,Nil,100);
+ Sleep(100);
End;
End
else
@@ -573,6 +579,7 @@ Begin
End;
Function USBGetDriver(Handle:PUSBDevHandle;Intf:Integer):String;
+const ESysENODATA= 61;
Var R : Integer;
Const MaxLen = 100;
Begin
@@ -656,6 +663,7 @@ Begin
usb_close(Handle);
End;
+const ESysEBUSY=16;
Procedure TUSBDevice.Open;
Var R : Integer;
I : Integer;
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal