情况如下:
自己做个调试助手来配合公司的虚拟串口软件(软件可以创建一个虚拟串口比如com3)
现在的问题是:
结合底层设备和虚拟串口软件创建一个com3,利用调试助手来收发数据(打开俩个调试助手软件,一个是com1(本机的),另一个是com3)
问题来了:
com3发数据com1可以收到,但是com1发数据com3却收不到,我调试过了com1发数据的时候com3的ReceiveData接收事件根本没反应,请问是什么原因,请大侠们多多指教! 另外我 抓包发现底层设备时确实返回了com1发给com3的数据,com3就是没有反应。很纠结
另附spcomm收发代码:
function TfrmMain.SendData(): Boolean;
var
sErr, strSend : string;
begin
Result := False;
try
if not bOpenCom then
begin
sbInfo.Panels.Items[2].Text := '请打开串口后再发送数据!';
Exit;
end;
if mmoSend.Text = '' then
begin
sbInfo.Panels.Items[2].Text := '请输入要发送的内容!';
Exit;
end;
if not bHexSend then
begin
if Comm1.WriteCommData(Pchar(mmoSend.Text),Length(mmoSend.Text)) then
begin
nSendData := nSendData + Length(mmoSend.Text);
sbInfo.Panels[1].Text := '发送:' + IntToStr(nSendData);
end
else
begin
DoSendDataError(Length(mmoSend.Text));
end;
end
else
if bHexSend then
begin
strSend := HexToIntStr(mmoSend.Text);// mmoSend中的内容是十六进制的字符串
if strSend = '' then
begin
chkHexSend.Checked := False;
//mmoReceive.Lines.Add('十六进制数据输入有误。');
sbInfo.Panels.Items[2].Text := '十六进制数据输入有误。';
Exit;
end;
if Comm1.WriteCommData(PChar(strSend), length(strSend)) then
begin
nSendData := nSendData + Length(strSend);
sbInfo.Panels[1].Text := '发送:' + IntToStr(nSendData);
end
else
DoSendDataError(Length(mmoSend.Text));
end;
Result := True;
if sbInfo.Panels.Items[2].Text <> '' then
sbInfo.Panels.Items[2].Text := '';
except
on E: Exception do
begin
Result := False;
sErr := 'Send data error, ' + E.Message;
SaveErrorMsg(sErr);
mmoReceive.Lines.Add(sErr);
end;
end;
end;
*************************
procedure TfrmMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
strReceive : String;
i : Integer;
nRbuffer : array of Byte;
begin
if BufferLength <= 0 then Exit;
SetLength(nRbuffer, BufferLength);
Move(Buffer^, nRbuffer[0], BufferLength); //调试时这里没反应
ShowRecData(nRbuffer, BufferLength);
end;
自己做个调试助手来配合公司的虚拟串口软件(软件可以创建一个虚拟串口比如com3)
现在的问题是:
结合底层设备和虚拟串口软件创建一个com3,利用调试助手来收发数据(打开俩个调试助手软件,一个是com1(本机的),另一个是com3)
问题来了:
com3发数据com1可以收到,但是com1发数据com3却收不到,我调试过了com1发数据的时候com3的ReceiveData接收事件根本没反应,请问是什么原因,请大侠们多多指教! 另外我 抓包发现底层设备时确实返回了com1发给com3的数据,com3就是没有反应。很纠结
另附spcomm收发代码:
function TfrmMain.SendData(): Boolean;
var
sErr, strSend : string;
begin
Result := False;
try
if not bOpenCom then
begin
sbInfo.Panels.Items[2].Text := '请打开串口后再发送数据!';
Exit;
end;
if mmoSend.Text = '' then
begin
sbInfo.Panels.Items[2].Text := '请输入要发送的内容!';
Exit;
end;
if not bHexSend then
begin
if Comm1.WriteCommData(Pchar(mmoSend.Text),Length(mmoSend.Text)) then
begin
nSendData := nSendData + Length(mmoSend.Text);
sbInfo.Panels[1].Text := '发送:' + IntToStr(nSendData);
end
else
begin
DoSendDataError(Length(mmoSend.Text));
end;
end
else
if bHexSend then
begin
strSend := HexToIntStr(mmoSend.Text);// mmoSend中的内容是十六进制的字符串
if strSend = '' then
begin
chkHexSend.Checked := False;
//mmoReceive.Lines.Add('十六进制数据输入有误。');
sbInfo.Panels.Items[2].Text := '十六进制数据输入有误。';
Exit;
end;
if Comm1.WriteCommData(PChar(strSend), length(strSend)) then
begin
nSendData := nSendData + Length(strSend);
sbInfo.Panels[1].Text := '发送:' + IntToStr(nSendData);
end
else
DoSendDataError(Length(mmoSend.Text));
end;
Result := True;
if sbInfo.Panels.Items[2].Text <> '' then
sbInfo.Panels.Items[2].Text := '';
except
on E: Exception do
begin
Result := False;
sErr := 'Send data error, ' + E.Message;
SaveErrorMsg(sErr);
mmoReceive.Lines.Add(sErr);
end;
end;
end;
*************************
procedure TfrmMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
strReceive : String;
i : Integer;
nRbuffer : array of Byte;
begin
if BufferLength <= 0 then Exit;
SetLength(nRbuffer, BufferLength);
Move(Buffer^, nRbuffer[0], BufferLength); //调试时这里没反应
ShowRecData(nRbuffer, BufferLength);
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货