Recent

Author Topic: SdpoSerial modified - Serial component for Linux Windows and Mac  (Read 19779 times)

wtechnologies.fr

  • Newbie
  • Posts: 4
Hi guys,
   I've modified the SdpoSerial component to be integrated without errors on differents platform and CPU.
(you can find attached the SdpoSerial.pas and depencies)

The SdpoSerial is based on synaser component http://synapse.ararat.cz/doku.php
For this
 - I have removed the lpk package of SdpoSerial. now just copy the directory, just add it on your project.
 - fix an error on linux ARM devices (invalid baudrate)
 - fix an error on detecting serial port on Linux
 - add a useful contribution from another developper : StartString, StopString, PacketSize

This new component has been tested succesfully on Linux i386, Linux x86_64, Linux ARM, Win32, Win64.

You can find an example  source code :

Add uses on header form.
Code: [Select]
uses SdpoSerial, Synaser;

Declare the procedure packet event and the serial port COM
Code: [Select]
......
 public
    { public declarations }
    procedure OnPacketReceive(Sender : TObject);
  end;

var
  Form1: TForm1;
  PortCOM : TSdpoSerial;
                         

On Form create, create dynamically the COM port and fill the combobox with port number (UNIX and Windows)
Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
var arrPort : TStringList;
    i : integer;
begin
     PortCom := TSdpoSerial.Create(nil);
     arrPort := TStringList.Create;
     arrPort.DelimitedText:=' ';
     arrPort.CommaText:= GetSerialPortNames;
     cmbPort.Items := arrPort;
end; 

Code: [Select]
procedure TForm1.btnOpenClick(Sender: TObject);
begin
     PortCom.BaudRate:= br_38400;
     PortCom.OnPacket:=@OnPacketReceive;
     PortCOm.StopString:=#13#10;
     {$IFDEF UNIX}
             Portcom.Device:='/dev/'+cmbPort.Text;
     {$ENDIF}
     {$IFDEF MSWINDOWS}
             Portcom.Device:=cmbPort.Text;
     {$ENDIF}
     PortCom.Open;
end;

Code: [Select]
procedure TForm1.btnCloseClick(Sender: TObject);
begin
  PortCom.Close;
end;   

To write a data on the serial port
Code: [Select]
   Portcom.WriteData(txtSendData.text+#13#10);

when a packet arrived on the serial port with a defined StopString, the event occurs
In this case, display the receive string on a memo
Code: [Select]
procedure TForm1.OnPacketReceive(sender: Tobject);
begin
  Memo1.Lines.add(PortCom.ReadPacket);
end;   

The source code is attached with this topic...
This component is very useful to do simple cross-platform application using serial port .

Regards Malek  ;D

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #1 on: May 10, 2013, 04:50:27 am »
Thank you very much!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #2 on: May 10, 2013, 07:38:09 am »
Thank you very much for your effort!
Regards

Paul Breneman

  • Sr. Member
  • ****
  • Posts: 290
    • Control Pascal
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #3 on: May 20, 2013, 03:45:15 am »
Thank you very much!  I also use Synapse in this new code I just released:
  http://www.ctrlterm.com/
Regards,
Paul Breneman
www.ControlPascal.com

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #4 on: May 20, 2013, 07:34:17 am »
@Paul Breneman: have you considered starting your own post in the third party announcement thread? That may get you more attention, and keep feedback centralized....
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #5 on: August 03, 2013, 01:59:51 pm »
When trying your example code, I get the following error on running the program:
"Semaphore init failed (possibly too many concurrent threads)". If I ignore it, no data comes from the device on ttyUSB0 (a 4800Bd gps)

I am using a Raspi with fpc 2.7.1 and Lazarus 1.1

Why am I getting this and how do I cure it please?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #6 on: August 03, 2013, 05:41:00 pm »
Quote
"Semaphore init failed (possibly too many concurrent threads)"
What if you put that in the forum's search box? ;)

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #7 on: August 03, 2013, 06:57:58 pm »
Thanks for that. I had searched but not far enough down the list! I didn't even know I had an lpk file! That cures the thread error but I still get no data! Back to the drawing board!

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #8 on: August 03, 2013, 10:51:41 pm »
Hi SdpoSerial now opens ttyUSB0 with 4800 N,8,1, but the OnPacketReceive function isn't seeing anything (I have a memo which lines of data should be added to. The gps has a fix and is producing data if you run gpsmon. I have googled to see if I need to senda code to get it outputting data but haven't found a clear answer.

Has anyone managed to read gps data in Lazarus?

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #9 on: August 05, 2013, 05:22:21 am »
hello,
BLL what is wrong with install of tlazserial in Raspi ? because inside the package there is an example which is a gps nmea frames reader and also simulator  :P  ( see screenshots) .
« Last Edit: August 05, 2013, 05:23:56 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #10 on: August 05, 2013, 01:20:47 pm »
I will look at it. I had given up with TLazSerial as it wouldn't install in Lazarus 0.98. Now I am on Lazarus 1.1, it should! Thanks for the info.

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #11 on: August 05, 2013, 01:46:24 pm »
I am afraid that TLazSerial is a non-starter. It relies on a version of Sdpo which the author admits won't work under linux. As he rightly says, it can't open the serial port. His later Sdpo, which is not a component works fine on the RasPi, but not v0.1.x. Indeed, TLazSerial will only install if I remove the baud rates which are in the ifdef UNIX section. After that it will install, but if you try and use it, in my case with ttyUSB0 (which does exist and Sdpo v0.2.0 will open), when you try to set active true, it just seizes everything up and you have to exit Lazarus and restart it!!

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #12 on: August 05, 2013, 02:04:57 pm »
Quote
It relies on a version of Sdpo which the author admits won't work under linux

Strange because Tlazserial works on linux Ubuntu. 

What are your properties  for TLazserial component particulary the device property ?
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #13 on: August 05, 2013, 03:29:15 pm »
Hi, The problem is definitely with Sdpo. I simply drop  a TLazSerial component on the form of my application, set the baudrate to 4800, no parity, 8 databits and 1 stop bit. I set the port as ttyUSB0, which I know is working and then try to set active to true and Lazarus seizes completely. You then need to try and close it, on which you get a completely blank dialog box, but clicking it does close Lazarus! Sdpo 0.2.0 code works fine and will open the port, but it's not a component. As I say, I also had to prevent the baudrates under the IFDEF UNIX, as each came as unknown. I presume the RasPi's wheezy doesn't support them?

fpc 2.7.1, Lazarus 1.1, RasPi with raspbian wheezy.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: SdpoSerial modified - Serial component for Linux Windows and Mac
« Reply #14 on: August 05, 2013, 03:52:09 pm »
with  tlazserial component you MUST put the /dev prefix for the Device property ( ex : /dev/ttyUSB0 )

Have you tried the sertest demo project ?  click on ports settings button. In the window opened click on the combo  of device property . You must see your serial port ( automatic scan) . This works on ubuntu with a usb serial port ( i don't know if it is ok on raspi).
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

 

TinyPortal © 2005-2018