I can send commands and print data to a USB barcode printer (Sanei SK1-21) using code like this:
fs := TFileStream.Create('/dev/usb/lp0', fmCreate);
fs.WriteBuffer(something[1], Length(something));
fs.Free;
and it works without a problem.
When I want to check printer status (waiting, error, near end, paper empty...) I send matching command using the code above, then free the FileStream, open it for reading like this:
fs := TFilestream.Create('/dev/usb/lp0', fmOpenRead, fmShareDenyNone);
fs.ReadBuffer(buf, SizeOf(buf));
fs.Free;
and get a response (for example: R000) and use it as wanted.
But, from time to time, it happens that there is nothing to be read in '/dev/usb/lp0' (same happens if I don't send request for status first, before trying to read it) and that's also OK. The only thing that troubles me is - when there is nothing to be read in '/dev/usb/lp0', this line:
fs.ReadBuffer(buf, SizeOf(buf)); hangs forever and I can't do anything anymore with '/dev/usb/lp0' because it's locked. I don't even get any error message, it's just stuck.
Is there some kind of TimeOut setting or something for TFileStream.ReadBuffer or other way to deal with this issue?