Recent

Author Topic: Synaser on macOS  (Read 1419 times)

lelebass

  • New Member
  • *
  • Posts: 41
Synaser on macOS
« on: March 24, 2022, 07:53:54 pm »
I am having trouble using Synaser under macOS. I am using Lazarus 2.2.0 x86_64 on Mojave, laz_synapse.lpk 40.1.0.0 installed using Online Package Manager. 

I am using the following code which runs without issues under Windows (with proper COM port name) to connect to an Arduino nano board:

Code: Pascal  [Select][+][-]
  1. Var
  2.   ser       : TBlockSerial;
  3.  
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. begin
  6.   Memo1.Clear;
  7.   ser:=TBlockSerial.Create;
  8.   ser.Connect('/dev/tty.usbserial-1410');
  9.   sleep(250);
  10.   ser.Config(115200, 8, 'N', SB1, False, False);
  11. [...]
  12.  
  13.  

On macOS the code crashes at ser.Connect. I've traced the error in the synaser guts, but got lost and could not understand what is going on. 

On macOS the device can be easily accessed from terminal using:

$ screen /dev/tty.usbserial-1410 115200

I am missing something? Is it sysaser supposed to work with macOS?

Thanks,
Daniele
« Last Edit: March 25, 2022, 09:36:55 am by lelebass »

sstvmaster

  • Sr. Member
  • ****
  • Posts: 299
Re: Synaser on macOS
« Reply #1 on: March 24, 2022, 10:20:13 pm »
I would do this in a button click, change the order of elements and do exception handling, like this.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   ser: TBlockSerial;
  4. begin
  5.   ser := TBlockSerial.Create;
  6.   try
  7.     try
  8.       ser.Config(115200, 8, 'N', SB1, False, False);
  9.       ser.Connect('/dev/tty.usbserial-1410');
  10.       sleep(250);
  11.     except
  12.       On E :Exception do
  13.         ShowMessage(E.Message);
  14.     end;
  15.   finally
  16.     ser.free;
  17.   end;
  18. end;
  19.  
greetings Maik

Windows 10,
- Lazarus 2.2.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 2.2.7 (fixes) + fpc 3.3.1 (main/trunk)

tetrastes

  • Sr. Member
  • ****
  • Posts: 481
Re: Synaser on macOS
« Reply #2 on: March 24, 2022, 11:02:02 pm »
I would do this in a button click, change the order of elements and do exception handling, like this.
Code: Pascal  [Select][+][-]
  1.       ser.Config(115200, 8, 'N', SB1, False, False);
  2.       ser.Connect('/dev/tty.usbserial-1410');
  3.  

How you suppose this can work?  ;D

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Synaser on macOS
« Reply #3 on: March 25, 2022, 01:16:32 am »
Hello,
I am having trouble using Synaser under macOS. I am using Lazarus 2.2.0 x86_64 on Mojave, laz_synapse.lpk 40.1.0.0 installed using Online Package Manager. 
it seems that you have the blocking open/connect bug with synaser on MacOS.
i have modified the TLazSerial component for that :
Quote
new in v0.6 version (03/2022)
 Fixes for OS-X (thanks to rphoover), SynSer(synaser) properties now persistent, v0.3 of GPS simulator
 On OS-X you must set the new property  SynSer/NonBlock to True  in the properties of TLazserial component.
TLazSerial use a modified version of synaser (lazsynaser).

it seems now OK on OS-X (see Capture of GPS Simulator (demo program of TLazserial) on OS-X in Attachment). Checked on OS-X Catalina 10.15 Lazarus 2.0.10 with FTDI USB serial adapter.

You can download the new package on my Github repository  (master is 0.6) (Code/Clone or Download Zip).
If it is OK the new version will go to the OPM.

Friendly, J.P

Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

lelebass

  • New Member
  • *
  • Posts: 41
Re: Synaser on macOS
« Reply #4 on: March 25, 2022, 10:23:11 am »
Thanks JP,
using your modified lazsynaser.pas and the following code it looks like I can get it working:

Code: Pascal  [Select][+][-]
  1. var
  2.   ser: TBlockSerial;
  3. begin
  4.   ser:=TBlockSerial.Create;
  5.   ser.LinuxLock:=False;
  6.   ser.NonBlock:=True;
  7.   ser.Connect('/dev/tty.usbserial-1410');
  8.   sleep(1000);
  9.   ser.Config(115200, 8, 'N', SB1, False, False);  
  10.  

I did not completely understood why I need also to set LinuxLock to False, I blindlessy cloned your LazSerial Connect call code. Am I missing something here?

Ciao,
Daniele 
« Last Edit: March 25, 2022, 12:07:47 pm by lelebass »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Synaser on macOS
« Reply #5 on: March 25, 2022, 11:25:56 pm »
I did not completely understood why I need also to set LinuxLock to False,

Because macOS is BSD-based and has very little similarity to Linux maybe?

lelebass

  • New Member
  • *
  • Posts: 41
Re: Synaser on macOS
« Reply #6 on: September 02, 2022, 12:52:11 pm »
I am using LazSynaSer without issues since my last post. I use it to connect several Arduino boards in OS X/macOS. Many of these boards are using the CH340 chip. I found out that with recent macOS the device is directly recognized by the OS and enumerated as /dev/tty.usbserial* whilst with older macOS versions the device needs to install a specific device driver and is seen as /dev/tty.wchusbserial*.
Thus the function GetSerialPortNames in LazSynaSer should be modified as such:

   {$IFDEF DARWIN}
    ScanForPorts( '/dev/tty.usbserial*',false); // RPH 14May2016, for FTDI driver
    ScanForPorts( '/dev/tty.UC-232*',false);    // RPH 15May2016, for Prolific driver 
    ScanForPorts( '/dev/tty.wchusbserial*',false); // for WCH driver
   {$ELSE}

In this way also old versions of OS X are able to connect through LazSynaSer.

Daniele

 

TinyPortal © 2005-2018