LazSerial error lazarus / 62-General ---------------------------------------------------------------------- HatForCat · 2017-01-30 21:46 Just started getting this error when trying to Close the Serial Port. Project SerialData raised exception class 'External: SIGSEGV'.  In file 'gconv_close.c' at line 35 I thought I had fixed it by using "Ser1.Active:=False;" instead of "Ser1.Close;" but I am just getting the error less often, not fixed. Anyone have thoughts on how to actually fix this? Code: [Select]procedure TfrmMain.btnCommOpenClick(Sender: TObject); begin   if Comm1.Active then Exit;   try     Comm1.Device:=edSerial.Text;     Comm1.Open;     CommStrRaw:=Comm1.ReadData;  // Clear anything in the Buffer     CommStrRaw:='';     memoSerial.Clear;     if Comm1.Active then     begin       pnlSerial.Color:=clLime;       memoSerial.Lines.Add('OPENED '+Comm1.Device);     end;   except     ShowMessage('FAILED to OPEN '+Comm1.Device);     memoSerial.Lines.Add('FAILED OPEN'+Comm1.Device);   end; end; procedure TfrmMain.btnCommCloseClick(Sender: TObject); begin   if not(Comm1.Active) then Exit;   Comm1.Active:=False;  // <--- This used to be Comm1.Close;   pnlSerial.Color:=clRed;   memoSerial.Lines.Add('CLOSED '+Comm1.Device); end; ---------------------------------------------------------------------- Jurassic Pork · 2017-01-31 05:44 hello, strange, because the close procedure of TLazserial is : 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 procedure TLazSerial.Close;begin  Active:=false;end; i have no problem to open and close port with the sertest example  of TLazserial on Ubuntu 14.04 LTS 64 bits Lazarus 1.6 FPC 1.3.  Have you the problem with this example ? What are you doing in your program ? Have you tried the flush and purge methods before closing the port ? : Quoteprocedure Flush; virtual; Waits until all data to is sent and buffers are emptied. Warning: On Windows systems is this method returns when all buffers are flushed to the serial port controller, before the last byte is sent! =========================================================== Public    procedure Purge; virtual; Unconditionally empty all buffers. It is good when you need to interrupt communication and for cleanups. flush is used in the deviceclose  procedure (called when you put active to false ) : 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 procedure TLazSerial.DeviceClose;begin  // flush device  if FSynSer.Handle<>INVALID_HANDLE_VALUE then begin    FSynSer.Flush;    FSynSer.CloseSocket; //   FSynSer.Purge;  end;    // stop capture thread  if ReadThread<>nil then begin    ReadThread.FreeOnTerminate:=false;    ReadThread.MustDie:= true;    while not ReadThread.Terminated do begin      Application.ProcessMessages;    end;    ReadThread.Free;    ReadThread:=nil;  end;   // close device  if FSynSer.Handle<>INVALID_HANDLE_VALUE then begin    FSynSer.Flush;    FSynSer.CloseSocket;  end;end;           Friendly, J.P Edit : TlazSerial is now in Github here with a 0.2 version : QuoteV 0.2  01/2017 : BaudRates for UNIX fixed - synaser files units renamed (with laz prefix) to avoid conflict with the original synaser files.                  scan port for linux improved ---------------------------------------------------------------------- Thaddy · 2017-01-31 07:53 I have no problems either. Can you adapt your exception handling a bit and report back which exception there actually is? 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 // NOT thisShowMessage('FAILED to OPEN '+Comm1.Device);//But THIS at a minimum:on e:Exception do  // needs sysutils, of course  ShowMessage(e.message,'|','FAILED to OPEN '+Comm1.Device); That will give you more meaningful exception information. ---------------------------------------------------------------------- HatForCat · 2017-01-31 20:31 Thanks for the replies, bit nothing works. It bombs before it gets to handle the exception. I have put Try/except in everything associated with the Comm1 and still it gives the " In file 'gconv_close.c' at line 35" error. Never triggering an exception. I can't seem to trap it with stepping through either. It appears to be right after the Comm1.close; statement but before the very next line of code is processed. It never gets to change the Panel color or to the "except". {edit} Just saw a "Run Error 216" flash by. What is that? {/edit} Code: [Select]    try       Comm1.Close;       pnlSerial.Color:=clRed;       memoSerial.Lines.Add('CLOSED '+Comm1.Device);     except       on e:Exception do  // needs sysutils, of course         ShowMessage(e.message+'|'+'FAILED to CLOSE '+Comm1.Device);     end; ---------------------------------------------------------------------- molly · 2017-01-31 21:07 Quote from: HatForCat on January 31, 2017, 09:31:29 pmIt appears to be right after the Comm1.close; statement but before the very next line of code is processed. Put up some showmessage between the lines, just as you did for the exception. It is annoying to click away those messageboxes but will tell you which line exactly bails out. Quote{edit} Just saw a "Run Error 216" flash by. What is that? {/edit} Runtime errors: Quote216 General Protection fault The application tried to access invalid memory space. This can be caused by several problems: 1 Dereferencing a nil pointer. 2 Trying to access memory which is out of bounds (for example, calling move with an invalid length). Meaning you are accessing something that isn't there anymore (or never wasn't). ---------------------------------------------------------------------- HatForCat · 2017-01-31 22:25 Nothing to do with LazSerial a such. It was Lazarus not handling an array being passed-by-reference. It worked fine normally when data was streaming in and out. But it seems that **sometimes,** when the Serial was closed abruptly, the array was caught part way through an iteration of indexes. I put in a "delay(300);" after each time the array was being passed and solved the problem. I changed the array to Global so it didn't need passing and it all went away. I did not want to leave the Delay-kludge in place. A bit of a weird Lazarus-bug I suspect, but have no inclination to delve into why/where/how. ---------------------------------------------------------------------- Thaddy · 2017-02-01 05:53 What we would do is pass the array as const, not declare it global. ---------------------------------------------------------------------- HatForCat · 2017-02-01 16:47 Quote from: Thaddy on February 01, 2017, 06:53:50 amWhat we would do is pass the array as const, not declare it global. OK, thanks, but Global was actually the way I had back in Delphi, I should have left it as was and not try to "fix" it with some streamlining when I moved to Ubuntu and Lazarus