Forum > Packages and Libraries
TLazSerial : serial port component for Lazarus (windows and linux).
CM630:
--- Quote from: tetrastes on December 06, 2024, 10:20:10 pm ---Your image looks weird to me. You confused with terminology. F.e., DTR_CONTROL is the name of line (signal). It can be set to one of three states: DTR_CONTROL_DISABLE (0), DTR_CONTROL_ENABLE (1), and DTR_CONTROL_HANDSHAKE (auto switching). You have to read about RS232 control lines and flow controls, and this https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-dcb.
--- End quote ---
That is what the sniffer shows. My cunning plan is to make those routines once and forget about them. Anyway, here https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddser/ns-ntddser-_serial_handflow the listed values are SERIAL_DTR_CONTROL and SERIAL_DTR_HANDSHAKE. But I assume SERIAL_DTR_CONTROL and SERIAL_DTR_HANDSHAKE cannot both be equal to zero at the same time.
Your help worked, I have now:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure SetHandFlow(HandFlow: THandFlow; var aLazSerial: TLazSerial);begin with aLazSerial.SynSer.DCB do begin Flags := dcb_Binary; //$00000001; case HandFlow of hfNone : Flags := Flags and not dcb_RtsControlEnable; hfXonXoff : begin Flags := Flags or dcb_OutX or dcb_InX; Flags := Flags or dcb_DtrControlEnable; end; hfDTR_DSR : Flags := Flags or dcb_DtrControlEnable; hfRTS_CTS : Flags := Flags or dcb_OutxCtsFlow or dcb_RtsControlHandshake; //aka Hardware hfXonXoff_and_RTS_CTS : begin Flags := Flags or dcb_OutX or dcb_InX; Flags := Flags or dcb_DtrControlEnable; Flags := Flags or dcb_OutxCtsFlow or dcb_RtsControlHandshake; end; hfXonXoff_and_DTR_DSR : begin Flags := Flags or dcb_DtrControlHandshake or dcb_OutxDsrFlow or dcb_OutX or dcb_InX or dcb_RtsControlToggle; Flags := Flags and not dcb_RtsControlHandshake; end; end; //case end; //with aLazSerial.SynSer.SetCommState;end;
But it seems that everyone has a different idea about what DTR/DSR shall be.
I sniffed several terminal apps, two of them set it as:
SERIAL_DTR_HANDSHAKE = 1; SERIAL_DSR_HANDSHAKE =1; SERIAL_RTS_CONTROL = 1; everything else = 0.
One of them sets different values each time.
And another one sets SERIAL_DTR_CONTROL = 1; SERIAL_CTS_HANDSHAKE = 1; everything else = 0.
In order to connect to the multimeter I need SERIAL_DTR_CONTROL = 1; SERIAL_CTS_HANDSHAKE = *; everything else = 0;
Most terminal apps do not have this mode (once is named DTR/DSR, once is RS485, the multimeter is actually a regular RS232 on 9V).
tetrastes:
--- Quote from: CM630 on December 09, 2024, 12:39:36 pm ---Anyway, here https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddser/ns-ntddser-_serial_handflow the listed values are SERIAL_DTR_CONTROL and SERIAL_DTR_HANDSHAKE.
--- End quote ---
This link is for drivers writers. Synaser doesn't use this. But the sense of fields is the same. If you want to use this, you are on your own. First of all you have to understand how RS-232 lines work.
--- Quote ---But I assume SERIAL_DTR_CONTROL and SERIAL_DTR_HANDSHAKE cannot both be equal to zero at the same time.
--- End quote ---
Of course they can, because the whole member ControlHandShake can be zero: "This member is set to zero or to the bitwise-OR or one or more of the following flags." from your link.
--- Quote ---But it seems that everyone has a different idea about what DTR/DSR shall be.
I sniffed several terminal apps, two of them set it as:
SERIAL_DTR_HANDSHAKE = 1; SERIAL_DSR_HANDSHAKE =1; SERIAL_RTS_CONTROL = 1; everything else = 0.
--- End quote ---
This is what I have written you.
--- Quote ---And another one sets SERIAL_DTR_CONTROL = 1; SERIAL_CTS_HANDSHAKE = 1; everything else = 0.
--- End quote ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---port.Config(baud, bits, parity, stop, false, false); // RTS and DTR are set at this momentport.RTS := false; // as everything else = 0 port.GetCommState;port.dcb.Flags := port.dcb.Flags and not dcb_RtsControlEnable; // as everything else = 0port.dcb.Flags := port.dcb.Flags or dcb_OutxCtsFlow; port.SetCommState; This is something not standard, and of course it is not DTR/DSR handshaking.
--- Quote ---In order to connect to the multimeter I need SERIAL_DTR_CONTROL = 1; SERIAL_CTS_HANDSHAKE = *; everything else = 0;
--- End quote ---
Are you sure that RTS must be OFF? If not, and "*" means "do not care", simply
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---port.Config(baud, bits, parity, stop, false, false);otherwise use the above.
CM630:
--- Quote from: tetrastes on December 09, 2024, 03:12:30 pm ---...
--- Quote ---But I assume SERIAL_DTR_CONTROL and SERIAL_DTR_HANDSHAKE cannot both be equal to zero at the same time.
--- End quote ---
Of course they can, because the whole member ControlHandShake can be zero: "This member is set to zero or to the bitwise-OR or one or more of the following flags." from your link.
...
--- End quote ---
Ooops, I meant 1, but wrote 0. %)
CM630:
I am trying to build a Windows app to Linux (Mint Mate).
First I did a very simple app and it works (gets data from the serial port).
But the other app throws an error "Threads not supported" on LazSerial.pas:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure TLazSerial.DeviceOpen;begin... ReadThread := TComPortReadThread.Create(true); ...end;
Any idea what might be wrong?
Note: Atfter plugging the serial device into USB I type sudo chmod -R 777 /dev/ttyUSB0 in the console.
This is the app that works:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LazSerial,lazsynaser; type { TForm1 } TForm1 = class(TForm) Button2: TButton; LazSerial1: TLazSerial; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure LazSerial1RxData(Sender: TObject); private public end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } //sudo chmod -R 777 /dev/ttyUSB0 procedure TForm1.Button1Click(Sender: TObject);begin end; procedure TForm1.Button2Click(Sender: TObject);begin //LazSerial1.ShowSetupDialog; LazSerial1.Active := True;end; procedure TForm1.FormCreate(Sender: TObject);begin memo1.Clear ; memo1.Append ( GetSerialPortNames);end; function decodestring(aValue: String): string;var i: integer;begin if avalue = '' then exit(''); for i:= 1 to length(avalue) do Result := Result + ( IntToHex(ord(aValue[i]))) + ' ';end; procedure TForm1.LazSerial1RxData(Sender: TObject);var recdata: string;begin recdata := LazSerial1.ReadData; memo1.Append (decodestring(recdata)); memo1.SelStart := Length(memo1.Text); Application.ProcessMessages;end; end.
Both apps use the same settings of the serial connection.
I think the app that I am trying to build in Linux does not use multi threading, a least the word "Thread" does not occur in the source code.
cdbc:
Hi
The problem might lie in your *.lpr file...
On Linux & Unix, it's necessary to compile in the 'cthreads' unit as one of the first ref'ed units...
Something like this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses {$IFDEF UNIX} cthreads, {$ENDIF} classes, ....It's usually present in the auto-generated files from Lazarus...
Regards Benny
Navigation
[0] Message Index
[#] Next page
[*] Previous page