Forum > Packages and Libraries

SdpoSerial modified - Serial component for Linux Windows and Mac

(1/5) > >>

wtechnologies.fr:
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: ---uses SdpoSerial, Synaser;

--- End code ---

Declare the procedure packet event and the serial port COM

--- Code: --- ......
 public
    { public declarations }
    procedure OnPacketReceive(Sender : TObject);
  end;

var
  Form1: TForm1;
  PortCOM : TSdpoSerial;
                         

--- End code ---

On Form create, create dynamically the COM port and fill the combobox with port number (UNIX and Windows)

--- Code: ---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; 

--- End code ---


--- Code: ---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;

--- End code ---


--- Code: ---procedure TForm1.btnCloseClick(Sender: TObject);
begin
  PortCom.Close;
end;   

--- End code ---

To write a data on the serial port

--- Code: ---   Portcom.WriteData(txtSendData.text+#13#10);

--- End code ---

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: ---procedure TForm1.OnPacketReceive(sender: Tobject);
begin
  Memo1.Lines.add(PortCom.ReadPacket);
end;   

--- End code ---

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:
Thank you very much!

exdatis:
Thank you very much for your effort!
Regards

Paul Breneman:
Thank you very much!  I also use Synapse in this new code I just released:
  http://www.ctrlterm.com/

BigChimp:
@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....

Navigation

[0] Message Index

[#] Next page

Go to full version