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.
uses SdpoSerial, Synaser;
Declare the procedure packet event and the serial port COM
......
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)
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;
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;
procedure TForm1.btnCloseClick(Sender: TObject);
begin
PortCom.Close;
end;
To write a data on the serial port
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
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