PascalSCADA COM Port lazarus / 11-Options ---------------------------------------------------------------------- anugrahs · 2024-08-13 05:56 Hi everyone, I'm currently working on a project in Lazarus where I'm utilizing the PascalSCADA library to manage serial communication. My goal is to create a user-friendly interface that allows the selection of a COM port through a combo box in the application. Problem: I’ve implemented the UI for COM port selection, but I’m facing an issue where the available COM ports do not appear in the combo box as expected. I’ve followed the standard procedure for listing COM ports using PascalSCADA, but no ports show up when I run the application. What I've Tried: I’ve ensured that the PascalSCADA library is correctly installed and configured in my Lazarus environment. I’ve reviewed the documentation for PascalSCADA and tried initializing the COM port settings in different parts of the application ( i used form initialization, 2 button , Combobox, and Serial Port Driver). I’ve also confirmed that the COM ports are working properly on my machine by testing them with other applications. **Code Snippet:** unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, SerialPort, commtypes; type   { TForm1 }   TForm1 = class(TForm)     BClose: TButton;     BOpen: TButton;     ComboBox1: TComboBox;     SerialPortDriver1: TSerialPortDriver;     procedure FormCreate(Sender: TObject);     procedure BOpenClick(Sender: TObject);     procedure BCloseClick(Sender: TObject);     procedure SerialPortDriver1CommErrorReading(Error: TIOResult);     procedure SerialPortDriver1CommPortOpened(Sender: TObject);     procedure SerialPortDriver1CommPortClosed(Sender: TObject);   private     procedure SetupPortSettings;     procedure PopulateSerialPorts;   public   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.SetupPortSettings; begin   if ComboBox1.ItemIndex <> -1 then   begin     SerialPortDriver1.COMPort := ComboBox1.Text; // Mengatur port yang dipilih     SerialPortDriver1.BaudRate := br9600;     // Contoh: Mengatur BaudRate ke 9600     SerialPortDriver1.DataBits := db8;        // Contoh: Mengatur DataBits ke 8     SerialPortDriver1.Paridade := spNone;       // Contoh: Mengatur Parity ke None     SerialPortDriver1.StopBits := sb1;        // Contoh: Mengatur StopBits ke 1   end   else     ShowMessage('Please select a port from the ComboBox.'); end; procedure TForm1.PopulateSerialPorts; begin   ComboBox1.Items.Clear;   ComboBox1.Items.AddStrings(SerialPortDriver1.COMPort);   if ComboBox1.Items.Count > 0 then     ComboBox1.ItemIndex := 0; end; procedure TForm1.FormCreate(Sender: TObject); begin   PopulateSerialPorts; end; procedure TForm1.BOpenClick(Sender: TObject); begin   SetupPortSettings;   try     SerialPortDriver1.Active := True;  // Open the port   except     on E: Exception do       ShowMessage('Failed to open port: ' + E.Message);   end; end; procedure TForm1.BCloseClick(Sender: TObject); begin   try     if SerialPortDriver1.Active then   SerialPortDriver1.Active := False;   except     on E: Exception do       ShowMessage('Failed to close port: ' + E.Message);   end; end; procedure TForm1.SerialPortDriver1CommErrorReading(Error: TIOResult); begin end; // Event handler ketika port dibuka procedure TForm1.SerialPortDriver1CommPortOpened(Sender: TObject); begin   ShowMessage('Port opened successfully.'); end; // Event handler ketika port ditutup procedure TForm1.SerialPortDriver1CommPortClosed(Sender: TObject); begin   ShowMessage('Port closed successfully.'); end; end. Thank you in advance for your help! Best regards,  Anugrah ---------------------------------------------------------------------- TRon · 2024-08-13 06:20 Quote from: anugrahs on August 13, 2024, 07:56:40 amI’ve implemented the UI for COM port selection, but I’m facing an issue where the available COM ports do not appear in the combo box as expected. I’ve followed the standard procedure for listing COM ports using PascalSCADA, but no ports show up when I run the application. The standard procedure for listing com ports using pascalSCADA ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SerialPortDriver1.COMPort := ComboBox1.Text; // Mengatur port yang dipilih...ComboBox1.Items.AddStrings(SerialPortDriver1.COMPort); I hope you got the gist that besides the need to obtain the name of the port yourself that this self-provided-point-to-the-other loop is not going to work ? ---------------------------------------------------------------------- bpranoto · 2024-08-13 06:25 The problem is in ComboBox1.Items.AddStrings(SerialPortDriver1.COMPort); Assuming you have the source of the library, you can try to debug SerialPortDriver1.COMPort If you in linux/freebsd make sure the logged user has the correct permission to access the serial port devices. Semoga membantu. ---------------------------------------------------------------------- anugrahs · 2024-08-13 09:26 Quote from: bpranoto on August 13, 2024, 08:25:02 amThe problem is in ComboBox1.Items.AddStrings(SerialPortDriver1.COMPort); Assuming you have the source of the library, you can try to debug SerialPortDriver1.COMPort If you in linux/freebsd make sure the logged user has the correct permission to access the serial port devices. Semoga membantu. are u indonesian too ?. I use windows for the OS, honestly im amateur for lazarus software then i'm so confused what to do for how to edit this code.... can u help me.. ---------------------------------------------------------------------- tetrastes · 2024-08-13 10:06 Go to https://github.com/geby/synapse, get function GetSerialPortNames from synaser.pas (it is at the end of file), then Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ComboBox1.Items.CommaText := GetSerialPortNames; ---------------------------------------------------------------------- anugrahs · 2024-08-13 12:01 Quote from: tetrastes on August 13, 2024, 12:06:51 pmGo to https://github.com/geby/synapse, get function GetSerialPortNames from synaser.pas (it is at the end of file), then Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ComboBox1.Items.CommaText := GetSerialPortNames; thank you for the reply, right now i'm so confused if i should modify the code that i made with the new one. Can help me make the simple code about com port selection and use combobox, button, etc... ---------------------------------------------------------------------- TRon · 2024-08-13 12:17 It is not rocket science  The component does not provide a list of serial devices (at least not that i am aware of in the version I skimmed through) so you have to add them yourself to the combobox in order to be able to select one from it. tetrates suggested to use synapse to retrieve a list of serial ports (I presume on/for any given platform) but for testing purposes you can manually assign a name for the port (assuming that you know the name of the port to test). ---------------------------------------------------------------------- PascalDragon · 2024-08-13 19:23 Quote from: anugrahs on August 13, 2024, 07:56:40 am**Code Snippet:** Please use [code=pascal][/code] to avoid the forum software possibly interpreting your code and to make it better readable. ---------------------------------------------------------------------- anugrahs · 2024-08-16 02:06 Quote from: anugrahs on August 13, 2024, 07:56:40 amHi everyone, I'm currently working on a project in Lazarus where I'm utilizing the PascalSCADA library to manage serial communication. My goal is to create a user-friendly interface that allows the selection of a COM port through a combo box in the application. Problem: I’ve implemented the UI for COM port selection, but I’m facing an issue where the available COM ports do not appear in the combo box as expected. I’ve followed the standard procedure for listing COM ports using PascalSCADA, but no ports show up when I run the application. What I've Tried: I’ve ensured that the PascalSCADA library is correctly installed and configured in my Lazarus environment. I’ve reviewed the documentation for PascalSCADA and tried initializing the COM port settings in different parts of the application ( i used form initialization, 2 button , Combobox, and Serial Port Driver). I’ve also confirmed that the COM ports are working properly on my machine by testing them with other applications. **Code Snippet:** unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, SerialPort, commtypes; type   { TForm1 }   TForm1 = class(TForm)     BClose: TButton;     BOpen: TButton;     ComboBox1: TComboBox;     SerialPortDriver1: TSerialPortDriver;     procedure FormCreate(Sender: TObject);     procedure BOpenClick(Sender: TObject);     procedure BCloseClick(Sender: TObject);     procedure SerialPortDriver1CommErrorReading(Error: TIOResult);     procedure SerialPortDriver1CommPortOpened(Sender: TObject);     procedure SerialPortDriver1CommPortClosed(Sender: TObject);   private     procedure SetupPortSettings;     procedure PopulateSerialPorts;   public   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.SetupPortSettings; begin   if ComboBox1.ItemIndex <> -1 then   begin     SerialPortDriver1.COMPort := ComboBox1.Text; // Mengatur port yang dipilih     SerialPortDriver1.BaudRate := br9600;     // Contoh: Mengatur BaudRate ke 9600     SerialPortDriver1.DataBits := db8;        // Contoh: Mengatur DataBits ke 8     SerialPortDriver1.Paridade := spNone;       // Contoh: Mengatur Parity ke None     SerialPortDriver1.StopBits := sb1;        // Contoh: Mengatur StopBits ke 1   end   else     ShowMessage('Please select a port from the ComboBox.'); end; procedure TForm1.PopulateSerialPorts; begin   ComboBox1.Items.Clear;   ComboBox1.Items.AddStrings(SerialPortDriver1.COMPort);   if ComboBox1.Items.Count > 0 then     ComboBox1.ItemIndex := 0; end; procedure TForm1.FormCreate(Sender: TObject); begin   PopulateSerialPorts; end; procedure TForm1.BOpenClick(Sender: TObject); begin   SetupPortSettings;   try     SerialPortDriver1.Active := True;  // Open the port   except     on E: Exception do       ShowMessage('Failed to open port: ' + E.Message);   end; end; procedure TForm1.BCloseClick(Sender: TObject); begin   try     if SerialPortDriver1.Active then   SerialPortDriver1.Active := False;   except     on E: Exception do       ShowMessage('Failed to close port: ' + E.Message);   end; end; procedure TForm1.SerialPortDriver1CommErrorReading(Error: TIOResult); begin end; // Event handler ketika port dibuka procedure TForm1.SerialPortDriver1CommPortOpened(Sender: TObject); begin   ShowMessage('Port opened successfully.'); end; // Event handler ketika port ditutup procedure TForm1.SerialPortDriver1CommPortClosed(Sender: TObject); begin   ShowMessage('Port closed successfully.'); end; end. Thank you in advance for your help! Best regards,  Anugrah Thank you for all the support, i can finished this PascalSCADA COM Port