Rudolf Harney rudolf.harney at web.de
Sun Aug 10 18:35:36 CEST 2003

Thank You, Marco, for Your immidiate response!
> >I wrote a freePascal program under Linux (Free Pascal Compiler
> > version 1.0.10 [2003/06/26] for i386), which reads information from serial
> > ports and sends information to serial ports and does some calculations.
> > There are no pointers, involved. After the program had run successfully
> > for 15 hours, it terminated with the following error message. An
> > unhandled exception occurred at 0x08051DC3 : EACCESSVIOLATION : Access
> > violation
> > 0x08051DC3
> > 0x0806ABC0
> > 0x080522D8
> > 0x080524B8
> > 0x08052DE0
> > 0x0806F98B
> > 0x08130A84
> > 0xF2B3E800
> > Any idea, what that means?
> Access violation. Do you use IOPERM to get access to the ports?
> If not, look up ioperm in the manual (under the "linux" unit)
No, I don't use ioperm - and I fear, I don't really understand the description in the manual. But it says there, the
program has to be run by root - and I am not happy with that: I don't want to give root privileges to my
measurement programs ... .
For port access, I use a routine, that was originally written by Brad Campbell (I got it with one of the older
freepascal versions), see below. Is there a reason, better to use IOPerm, ReadPort and WritePort procedures, as
stated in the manual? Or is thre just a bug in my port-reading-routine?
The error occured (very probably), wile the following routine was in action:

function SerialPort_obj.GetLine(Port : String; BaudRate : LongInt; DataBits : Byte;
Parity : Char; StopBits: Byte; FlowControl : String; var TheLine : String) : ShortInt;
{Given : - sensorPort, a string with the portname, e.g. '/dev/ttyS1'
- BaudRate, e.g. 9600, compare list of possible values in function SetParameters
- DataBits : 5, 6, 7 or 8
- Parity : 'e', 'o' or 'n' (even, odd or none)
- StopBits : 1 or 2
- FlowControl : 'none' or 'RTSCTS' (Hardware)
- Outstring : String to write to serial port
Task : read line of input from port, referenced by Fd and return it
Return : The line of input from Fd.
0 if o.k.
-1 if error occured

InStr : String[80];
ResStr : String[80];
Quit : Boolean;
InLen, Loop : Integer;
FDs : FDSet;
Is_Error : ShortInt;
Fd : F_Handle;

Is_Error := 0;
ResStr := '';
Quit := False;
Fd := RS232Open(Port); {open port}
if Fd > 0 then Begin
{set the port parameters:}

FD_Zero (FDs); {Clear File Descriptors Array}
FD_SET (Fd,FDs); {Input from Serial Port}

Repeat { line of input }
Select(Fd+1, at FDS,nil,nil, nil);

If FD_ISSET(Fd,FDS) then {Have we data waiting in UART ? }
InLen := fdRead(Fd,InStr[1],80);
If InLen > 0 then
For Loop := 1 to Inlen do begin
if ord(InStr[Loop])=13 then quit:=true; {line ended with LF}
if not quit then ResStr := ResStr + InStr[Loop];
else begin
writeLn('fatal error in getLine: no line of input from port!');
quit := true;
Is_Error := -1;
Until quit; {Were Outa Here}
FLock(Fd,LOCK_UN); {Unlock Port}
fdClose(Fd); {Close Port}
end { if Fd > 0 }
else begin
writeLn('error, opening port ', port);
quit := true;
Is_error := -1;
TheLine := ResStr;
GetLine := Is_Error;
end;{function GetLine}

(I'm not a very experienced programmer, so forgive me bad style, if there is ...). Thanks for hints ...
Rudolf Harney
rudolf.harney at web.de

Die sicherste Form der Kommunikation: E-Mails verschluesseln, Spam-Filter,
Adressverifizierung, digitale Unterschrift: http://freemail.web.de

More information about the fpc-pascal mailing list