L
lzmling
Unregistered / Unconfirmed
GUEST, unregistred user!
我在dll中用到spcomm,代码如下:
uses
ShareMem,SysUtils,Classes,Windows,Messages,
spcomm;
{$R *.res}
var
jmcomm:tcomm;
sbuf,rbuf:array[1..11] of byte;
function send():boolean;
var
i:integer;
begin
for i:=1 to 11 do
begin
if not jmcomm.writecommdata(@sbuf,1) then
begin
send:=false;
break;
end;
//发送时字节间的延时
sleep(2);
end;
send:=true;
end;
function openem(comno,txno:integer):integer;stdcall;
var
ls_commname:string;
i,j:integer;
s:string;
begin
ls_commname := 'COM'+inttostr(comno);
jmcomm.CommName := ls_commname;
if jmcomm.handle = 0 then
jmcomm.StartComm;
sbuf[1]:=byte($0); //帧头
for j:=2 to 10 do
sbuf[j]:=byte($30); //命令号
i:=strtoint('$'+inttostr(10+txno));
sbuf[11]:=byte(i); //帧尾
send;
end;
我该如何得到串口返回的值呢?
uses
ShareMem,SysUtils,Classes,Windows,Messages,
spcomm;
{$R *.res}
var
jmcomm:tcomm;
sbuf,rbuf:array[1..11] of byte;
function send():boolean;
var
i:integer;
begin
for i:=1 to 11 do
begin
if not jmcomm.writecommdata(@sbuf,1) then
begin
send:=false;
break;
end;
//发送时字节间的延时
sleep(2);
end;
send:=true;
end;
function openem(comno,txno:integer):integer;stdcall;
var
ls_commname:string;
i,j:integer;
s:string;
begin
ls_commname := 'COM'+inttostr(comno);
jmcomm.CommName := ls_commname;
if jmcomm.handle = 0 then
jmcomm.StartComm;
sbuf[1]:=byte($0); //帧头
for j:=2 to 10 do
sbuf[j]:=byte($30); //命令号
i:=strtoint('$'+inttostr(10+txno));
sbuf[11]:=byte(i); //帧尾
send;
end;
我该如何得到串口返回的值呢?