Menu

#1 win98 crashes when attempting to open a port in use

Components
open
nobody
None
5
2003-01-17
2003-01-17
No

Using Win98, Delphi 5 w/ Update Pack.

I am writing a program which communicates with a
hardware module over a serial connection (which,
incidentally, is intended to monitor serial data
transmitted between two OTHER devices).

Here is the code where the problem is occuring:

procedure TSerialMonitor.Connect;
var
HANDLE: THandle;
begin
if not Connected then
begin
SerCom.ComNumber := COMMPort;

{ Test whether the COMM port is available. }
HANDLE := CreateFile(PChar('COM'+IntToStr
(SerCom.ComNumber)),
GENERIC_READ or GENERIC_WRITE, 0, nil,
OPEN_EXISTING, 0, 0);
if HANDLE = INVALID_HANDLE_VALUE then
begin
if GetLastError = ERROR_FILE_NOT_FOUND then
raise Exception.Create(
'No such port: COM' + IntToStr
(SerCom.ComNumber) + '.')
else
raise Exception.Create(
'Unable to open COM' + IntToStr
(SerCom.ComNumber) +
' because it is currently in use.');
end
else
CloseHandle(HANDLE);

SerCom.Open; <---- Win98 crashes when this
instruction executes.

FConnected := true;

SetBaudRate(FBaudRate);
SetBits(FBits);
SetParity(FParity);
end;
end;

I adapted the code which is *supposed* to detect an
unavailable port from the GetDeviceState method in unit
AfControls. Neither of them appear to work correctly on
my system.

To reproduce this error, just call TAfCom.Open while the
port is in use by another application. I have Hotsync
Manager configured on COM1, so when the program
tries to open COM1 through the Connect method
(above), my machine crashes. I'm not talking a system
halt or anything like that; my CPU soft-resets instantly.
The screen goes blank and in a moment I see the
familiar BIOS messages, etc.

I hope there is enough information here. Sorry if my
description is incomplete; it's the end of the day and my
brain is tired.

Matthew Hall
matthall@woodcraftmill.com

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.