Recent

Author Topic: tcsetattr - Access violation  (Read 5824 times)

elektronist

  • Newbie
  • Posts: 6
tcsetattr - Access violation
« on: May 20, 2004, 10:04:48 am »
Hi

Can't use tcsetattr function. Lazarus compiles but raises runtime error 'Access violation' after some error messages. Same code has no problem with Kylix3oe.

Here is my unit, simplified to be clear. Use '/dev/ttyS0' as PortName.

Code: [Select]
unit tcom;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LibC;

var
  CommId : integer;

function InitCom(PortName: string): boolean;

implementation

function InitCom(PortName: string):boolean;
var
  ATermios : TTermios;
begin
  Result := false;

  CommID := FileOpen(PortName, O_RDWR or O_NOCTTY or O_NDELAY);

  fcntl(CommID, F_SETFL, 0);
  tcgetattr(CommID, ATermios);

  tcsetattr(CommID, TCSANOW, ATermios);
  Result := true;
end;

end.


Problem is on tcsetattr line.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
tcsetattr - Access violation
« Reply #1 on: May 20, 2004, 10:21:27 am »
This code example has no code maintained by the lazarus team. If you think there is a bug in the used units, commit a bug report at the FPC http://www.freepascal.org/bugs/add.php3.

If you just want other peoples input on your problem, writing to the fpc-pascal mailing list (http://www.freepascal.org/maillist.html) might help you further. Or talk to FPC developers on IRC (http://www.freepascal.org/moreinfo.html).

elektronist

  • Newbie
  • Posts: 6
tcsetattr - Access violation
« Reply #2 on: May 20, 2004, 02:33:22 pm »
Vincent thanks for your fast response.

elektronist

  • Newbie
  • Posts: 6
tcsetattr - Access violation
« Reply #3 on: May 22, 2004, 11:23:08 am »
Problem solved.

In LibC interface of fpc, tcsetattr function has two kind of use. The one called Delphi compatible uses 3rd parameter as const and other one as pointer. Allthough TTermios's type is record in both fpc and Kylix, and Kylix uses 3rd parameter as const, this does not work with fpc.

tcsetattr(CommID, TCSANOW, @ATermios);

works.

 

TinyPortal © 2005-2018