[fpc-devel] serial under linux, SerOpen blocks

Armin Diehl ad at ardiehl.de
Thu Aug 18 14:01:35 CEST 2011


yes, that is better

function SerOpen(const DeviceName: String): TSerialHandle;
var
   flags : cint;
begin
   Result := fpopen(DeviceName, O_RDWR or O_NOCTTY or O_NONBLOCK);
   if result > -1 then
   begin
     flags := fpfcntl(Result,F_GetFl);
     fpfcntl(Result,F_SETFL,flags and (not O_NONBLOCK));
   end;
end;

results in
open("/dev/ttyUSB0", O_RDWR|O_NOCTTY|O_NONBLOCK|O_LARGEFILE) = 10
fcntl(10, F_GETFL)                      = 0x8802 (flags 
O_RDWR|O_NONBLOCK|O_LARGEFILE)
fcntl(10, F_SETFL, O_RDWR|O_LARGEFILE)  = 0


i think this should be changed in serial.pp


On 08/18/2011 01:18 PM, Henry Vermaak wrote:
> On 18/08/11 12:00, Armin Diehl wrote:
>> Hi Marco,
>>
>> minicom calls open with O_NONBLOCK and resets O_NONBLOCK directly after
>> the open call:
>>
>> open("/dev/ttyUSB0", O_RDWR|O_NOCTTY|O_NONBLOCK) = 3
>> fcntl(3, F_GETFL) = 0x8802 (flags O_RDWR|O_NONBLOCK|O_LARGEFILE)
>> fcntl(3, F_SETFL, O_RDWR|O_LARGEFILE) = 0
>>
>> doing the same in serial.pp should not change the blocking behaviour of
>> serial.pp.
>>
>> function SerOpen(const DeviceName: String): TSerialHandle;
>> begin
>> Result := fpopen(DeviceName, O_RDWR or O_NOCTTY or O_NONBLOCK); // AD:
>> O_NONBLOCK was missing
>> if result > -1 then
>> fpfcntl(Result,F_SETFL,O_RDWR or O_NOCTTY); //AD: non blocking off again
>
> Better use F_GETFL first, then flags &= ~O_NONBLOCK, like minicom does.
>
> Henry
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel




More information about the fpc-devel mailing list