How to get a list of tty devices on mac? lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- vonskie · 2014-03-18 02:39 the below does not work. any other way? var   comport: integer;   Info: TSearchRec;   Count: longint; begin   Count := 0;   // if we have found a file...   if FindFirst('/dev/tty.*', faAnyFile and faDirectory and faSysFile, Info) = 0 then   begin     try       repeat         // we increase the count so that we can show it later         Inc(Count);         // we do stuff with the file entry we found         with Info do         begin                   comboboxcomport.items.add(info.Name);         end;       until FindNext(info) <> 0;     finally       FindClose(Info);     end;   end; ---------------------------------------------------------------------- vonskie · 2014-03-18 04:19 figured this one out. if FindFirst('/dev/tty.*', $FFFFFFFF, Info) = 0 then   begin     try       repeat         // we increase the count so that we can show it later         Inc(Count);         // we do stuff with the file entry we found         with Info do         begin           //If (Attr and faDirectory) = faDirectory then           // Write('Dir : ');           comboboxcomport.items.add('/dev/'+info.Name);         end;       until FindNext(info) <> 0;     finally       FindClose(Info);     end;   end; ---------------------------------------------------------------------- engkin · 2014-03-18 06:04 It seems that the main difference is in the attributes of FindFirst. It did not work the first time because your used And: Code: [Select]if FindFirst('/dev/tty.*', faAnyFile and faDirectory and faSysFile, Info) = 0 then Since:   faSysFile   = $00000004;   faDirectory = $00000010;   faAnyFile   = $0000003f; the result of:  faAnyFile and faDirectory and faSysFile is zero. According to the documentation: QuoteAttr is an or-ed combination of the following constants: So this is the correct usage, I believe: Code: [Select]if FindFirst('/dev/tty.*', faAnyFile or faDirectory or faSysFile, Info) = 0 then ---------------------------------------------------------------------- vonskie · 2014-03-18 13:55 Quote from: engkin on March 18, 2014, 07:04:54 amIt seems that the main difference is in the attributes of FindFirst. It did not work the first time because your used And: Code: [Select]if FindFirst('/dev/tty.*', faAnyFile and faDirectory and faSysFile, Info) = 0 then Since:   faSysFile   = $00000004;   faDirectory = $00000010;   faAnyFile   = $0000003f; the result of:  faAnyFile and faDirectory and faSysFile is zero. According to the documentation: QuoteAttr is an or-ed combination of the following constants: So this is the correct usage, I believe: Code: [Select]if FindFirst('/dev/tty.*', faAnyFile or faDirectory or faSysFile, Info) = 0 then This was the fix if FindFirst('/dev/tty.*', $FFFFFFFF, Info) = 0 then ---------------------------------------------------------------------- engkin · 2014-03-18 14:59 Quote from: vonskie on March 18, 2014, 02:55:22 pmThis was the fix if FindFirst('/dev/tty.*', $FFFFFFFF, Info) = 0 then Thank you!. Can you explain the $FFFFFFFF in your code? ---------------------------------------------------------------------- vonskie · 2014-03-18 15:07 Quote from: engkin on March 18, 2014, 03:59:08 pmQuote from: vonskie on March 18, 2014, 02:55:22 pmThis was the fix if FindFirst('/dev/tty.*', $FFFFFFFF, Info) = 0 then Thank you!. Can you explain the $FFFFFFFF in your code? I found the $FFFFFFFF in the synaser.pas module as they were also listing serial devices using the same method. Where they got it from I have no clue, guess it is documented somewhere. ---------------------------------------------------------------------- engkin · 2014-03-18 15:21 Quote from: vonskie on March 18, 2014, 04:07:20 pmI found the $FFFFFFFF in the synaser.pas module as they were also listing serial devices using the same method. Where they got it from I have no clue, guess it is documented somewhere. Thank you again for explaining it to me. If it is used this way in synaser.pas then may be it is correct. I'll wait and see if other members have anything to say about it. ---------------------------------------------------------------------- vonskie · 2014-03-18 15:26 Quote from: engkin on March 18, 2014, 04:21:59 pmQuote from: vonskie on March 18, 2014, 04:07:20 pmI found the $FFFFFFFF in the synaser.pas module as they were also listing serial devices using the same method. Where they got it from I have no clue, guess it is documented somewhere. Thank you again for explaining it to me. If it is used this way in synaser.pas then may be it is correct. I'll wait and see if other members have anything to say about it. maybe $FFFFFFFF means anything all types ---------------------------------------------------------------------- zeljko · 2014-03-18 18:42 AFAIR that $FFFFFFFF in synapse produces range check error on 64bit. ---------------------------------------------------------------------- vonskie · 2014-03-18 19:42 Quote from: zeljko on March 18, 2014, 07:42:21 pmAFAIR that $FFFFFFFF in synapse produces range check error on 64bit. I am compiling for 32 bit carbon 386 and it runs just fine like that on my 64 bit mac. Are you saying if I compile for 64 bit and run on a 64 bit machine it will cause an error.? ---------------------------------------------------------------------- zeljko · 2014-03-18 20:01 Yes ---------------------------------------------------------------------- vonskie · 2014-03-18 20:08 So what is the best solution? ---------------------------------------------------------------------- dieselnutjob · 2014-04-15 13:16 thanks for the above, I have adapted it and used it myself this code works for OSX and Linux for usb to serial adapters Code: [Select]//for MacOSX if FindFirst('/dev/tty.*',  faAnyFile, Info) = 0 then   begin     try       repeat         with Info do         begin           comboboxcomport.items.add('/dev/'+info.Name);         end;       until FindNext(info) <> 0;     finally       FindClose(Info);     end;   end;  //for Linux if FindFirst('/dev/ttyUSB*',  faAnyFile, Info) = 0 then   begin     try       repeat         with Info do         begin           if  fpAccess('/dev/'+info.Name,W_OK)=0 then comboboxcomport.items.add('/dev/'+info.Name)            else            begin              //some code here to tell user he has wrong              //permissions i.e. not in dialout group            end;         end;       until FindNext(info) <> 0;     finally       FindClose(Info);     end;   end;