X
xiaomai
Unregistered / Unconfirmed
GUEST, unregistred user!
初学乍练 找不到那错了
用TApdComPort写了个串口接收和发送 用dll封起来 由vb来调用 接收没有问题 发送也可以正常发送出去 就是发送的时候要先抱个access violation at address06A377B9 in module
"comdll.dll".read of address 00000304错误 然后才会发出去
程序如下 :(不知道那里有问题)
dll:
procedure formshow;
var form1:Tform1;
begin
form1:=tform1.Create(nil);
form1.ShowModal;
form1.Free;
end;
exports
formshow;
unit1:
procedure TForm1.ComPort1Trigger(CP: TObject; Msg, TriggerHandle,
Data: Word);
var
I : Word;
C : Char;
s : String;
begin
try
case Msg of
APW_TRIGGERDATA :
{got 'login', send response}
;
APW_TRIGGERAVAIL :
{extract and display/process the data}
begin
s:='';
for I:= 1 to Data do
begin
C := ComPort1.GetChar;
s:=s+c;
end;
memo1.Lines.Add(s);
end;
APW_TRIGGERTIMER :
{timed out waiting for login prompt, handle error}
;
end;
except
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var schar;
begin
s:=pchar(edit1.Text);
ComPort1.PutString(s);
waitcommEmpty;
end;
procedure tform1.waitcommEmpty;
var
t:integer;
begin
t:=0;
while (Form1.ComPort1.OutBuffUsed>0) or (t>100) do
begin
sleep(200);
inc(t);
end;
sleep(200);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComPort1.Open:=false;
ComPort1.ComNumber:=1;
ComPort1.Baud:=9600;
ComPort1.Parity:=pNone;
ComPort1.DataBits:=8;
ComPort1.StopBits:=1;
ComPort1.Open:=true;
end;
用TApdComPort写了个串口接收和发送 用dll封起来 由vb来调用 接收没有问题 发送也可以正常发送出去 就是发送的时候要先抱个access violation at address06A377B9 in module
"comdll.dll".read of address 00000304错误 然后才会发出去
程序如下 :(不知道那里有问题)
dll:
procedure formshow;
var form1:Tform1;
begin
form1:=tform1.Create(nil);
form1.ShowModal;
form1.Free;
end;
exports
formshow;
unit1:
procedure TForm1.ComPort1Trigger(CP: TObject; Msg, TriggerHandle,
Data: Word);
var
I : Word;
C : Char;
s : String;
begin
try
case Msg of
APW_TRIGGERDATA :
{got 'login', send response}
;
APW_TRIGGERAVAIL :
{extract and display/process the data}
begin
s:='';
for I:= 1 to Data do
begin
C := ComPort1.GetChar;
s:=s+c;
end;
memo1.Lines.Add(s);
end;
APW_TRIGGERTIMER :
{timed out waiting for login prompt, handle error}
;
end;
except
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var schar;
begin
s:=pchar(edit1.Text);
ComPort1.PutString(s);
waitcommEmpty;
end;
procedure tform1.waitcommEmpty;
var
t:integer;
begin
t:=0;
while (Form1.ComPort1.OutBuffUsed>0) or (t>100) do
begin
sleep(200);
inc(t);
end;
sleep(200);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComPort1.Open:=false;
ComPort1.ComNumber:=1;
ComPort1.Baud:=9600;
ComPort1.Parity:=pNone;
ComPort1.DataBits:=8;
ComPort1.StopBits:=1;
ComPort1.Open:=true;
end;