Recent

Author Topic: program code from linux to windows  (Read 900 times)

Fixik2022

  • Newbie
  • Posts: 3
program code from linux to windows
« on: March 25, 2023, 07:33:31 am »
Hi. need help reading data from usb
Code: Pascal  [Select][+][-]
  1. TFileStream.Create('/dev/usb/lp0',fmOpenReadWrite);

MarkMLl

  • Hero Member
  • *****
  • Posts: 8030
Re: program code from linux to windows
« Reply #1 on: March 25, 2023, 07:47:12 am »
libusb, and generally speaking trying to treat it like a stream won't work.

Broadly speaking, the data coming from (or expected by) a USB device is highly-device-specific: unless it's one of the standard classes, and in that case I'd expect it to be at e.g. /dev/lp0 rather than /dev/usb/lp0 or somewhere on the /dev/bus/usb tree.

If you were actually trying to read /dev/lp0 you could probably get at that via the kernel; same applies to network devices (i.e. USB-connected Ethernet) etc. However for just about anything else you'll find few alternatives to going via libusb, even if somebody's written a higher-level library.

MarkMLl
« Last Edit: March 25, 2023, 08:13:08 am by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Fixik2022

  • Newbie
  • Posts: 3
Re: program code from linux to windows
« Reply #2 on: March 25, 2023, 08:25:59 am »
Code: [Select]
FUsb:TFileStream;
Code: [Select]
function TForm1.OpenUsb:boolean;
begin
  result:=false;
  try
    FUsb:=TFileStream.Create('/dev/lp0',fmOpenReadWrite);
    result:=true;
  except
    on e:exception do
    begin
      log(e.message);
    end;
  end;
end;   

does not work on windows

Thaddy

  • Hero Member
  • *****
  • Posts: 16183
  • Censorship about opinions does not belong here.
Re: program code from linux to windows
« Reply #3 on: March 25, 2023, 09:00:29 am »
Of course not!
'/dev/lp0' is unix specific and is a pseudo file. There is no direct Windows equivalent.
If I smell bad code it usually is bad code and that includes my own code.

Fixik2022

  • Newbie
  • Posts: 3
Re: program code from linux to windows
« Reply #4 on: March 25, 2023, 09:03:14 am »
how can i do it for windows

Thaddy

  • Hero Member
  • *****
  • Posts: 16183
  • Censorship about opinions does not belong here.
Re: program code from linux to windows
« Reply #5 on: March 25, 2023, 09:59:40 am »
libusb.dll is available for Windows, as Mark implicitly wrote.
FPC comes with bindings for it.
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018