我在处理一个小 dll 并在其上使用 TComport 组件。我在这个 dll 中有一个函数,它接受一些参数并返回一个字符。我在项目中添加了一个数据模块,并在其上放置了 TComport 和 TComDataPacket。一切正常,但 TComport 无法捕获任何事件。例如,我想从 TComDataPacket 组件的 OnPacket evet 中的设备中获取字符串。任何建议我为我糟糕的英语道歉。
library VoteService;
uses
System.SysUtils,
System.Classes,
Extra in 'Extra\Extra.pas',
Un_Dm in 'DataModule\Un_Dm.pas' {DM: TDataModule},
CPort in 'CPort\CPort.pas';
var ComPort1 : TComPort;
ComDataPacket1 : TComDataPacket;
{$R *.res}
function getVote(personnelCode:Pchar; docCode: Pchar):Integer; stdcall;
var
intStatus, intIdentifier: Integer;
strStatus_message: string;
Port: TPort;
StopBits: TStopBits;
Parity: TParityBits;
DataBits: TDataBits;
BaudRate: TBaudRate;
i, j : Integer;
begin
Answer := 0;
SerialPortSetting(Port, StopBits, Parity, DataBits, BaudRate);
dm := TDM.Create(nil);
try
DM.ComPort1.Port := Port;
DM.ComPort1.StopBits := StopBits;
DM.ComPort1.Parity.Bits := Parity;
DM.ComPort1.DataBits := DataBits;
DM.ComPort1.BaudRate := BaudRate;
DM.ComPort1.Connected := True;
DM.ComPort1.WriteStr('*');
DM.ComPort1.Close;
DM.ComPort1.Open;
for i := 0 to 5 do
begin
j := 0;
while Answer = 0 do
begin
//setAnswer;
end;
Result := Answer;
end;
finally
dm.Free;
end;
end;
exports
getVote;
begin
end.