专线modem的串口通信(200分)

D

dzm5773

Unregistered / Unconfirmed
GUEST, unregistred user!
我用spcomm控件做了一个串口通信的程序,现在用专线modem连接(相当于两个串口连接)程序不通,程序如下:unit gps;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, SPComm;

type
TForm1 = class(TForm)
Comm1: TComm;
Memo1: TMemo;
procedure Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
s: string;
begin
Comm1.startcomm;
SetLength(S,500); //接收RS232的数据并显示Memo1上。
Move(Buffer^, PChar(S)^, 500);
Memo1.Lines.Add(S);
Memo1.Invalidate;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
comm1.StopComm;
end;

end.
为什么?急!!!
 
试过别的控件吗?比如commdrv32?
那里有个例子,可以直接测试一下。

另外,专线Modem是干什么用的?
是用来拨号吗?
 
专线 Modem 的通信与普通"猫"完全一样

专线与普通 Modem 的区别只在于专线猫能够在开启后通过哑方式自动呼叫/应答来实
现握手连接

在调试的时候可以关闭掉哑方式, 按普通猫对待, 调试通了后在调试专线方式. 哑方
式的设置参见具体猫的说明书
 
专线 Modem 是什么东东?Cable Modem?


 
专线 Modem 是个好东西呦.

所谓专线是指带有专线功能的调制解调器, 可以用两个专线猫直接用电话线连接两个
机器如同直接电缆连接一样. 专线猫能过自身发出拨号音而无需通过电话交换台. 例
如两个办公室相隔几百米, 可以用拉一条专线用专线猫直接连将两个机器连起来而不
需要拨号.

专线猫比普通猫贵上个几百元钱吧, 有钱就买一对玩玩吧.
 
我曾经用普通猫试通过我的程序,后改用专线猫后就试不通,之后又用qbasic编了一个通信程序测试发现串口设置是正确的
证明用spcomm编的程序确有问题,但我不知是属性不对还是代码有问题!!请高手指教!!!!
 
我曾经用普通猫试通过我的程序,后改用专线猫后就试不通,之后又用qbasic编了一个通信程序测试发现串口设置是正确的
证明用spcomm编的程序确有问题,但我不知是程序中tcomm属性设置不对还是代码有问题!!请高手指教!!!!
 
按理说在普通猫上通过后再专线猫上不会有问题

不知道你的Comm1的属性是如何设置的?

对你的程序的几个意见:

var s: string;
begin
Comm1.startcomm; //??? 是否必要
SetLength(S,500); //??? 是否必要,Buffer length 应该再属性中设置
Move(Buffer^, PChar(S)^, 500); //??? 为什么要用Move而不用PCopy

spcomm 没用过, 用MSComm32.OCX试一下, 该控件比较稳定
 
Comm1的属性设置如下:com1,9600,n,1,8,因为spcomm支持多线程程序,所以用spcomm控件。
spcomm属性中没有buffer设置,setlenght(s,500)是设置s字符长度。请问高手,若有spcomm控件
的详细说明,主要属性和方法设置,最好是中文,有例子就太好了!!多谢!!!
 
我用专线modem写过几个程序. 请把modem的牌子和型号写清楚.
我用的是爱华的28.8K专线modem.不同的modem在参数设置时可
能会不同.

要注意的是专线modem在命令状态时发送的字符的速度不能太快.
您可以自己编写一个delay函数, 每发送一个字符就delay(50),
否则modem无法正常处理,但是在modem进入数据处理状态时就没
有必要考虑这些问题了.
Comm1.StatrComm最好不要放在OnReceive事件中. 对于专线
modem, 他来不及处理.一下例子, 请参考.
procedure TCommWatchForm.CommConnect(Comm : TComm);// Init
begin
Comm1.BaudRate := DBIniFile.ReadInteger('Comm1','BaudRate', 1200);
Comm1HaveModem := DBIniFile.ReadBool('Comm1','HaveModem',False);

Comm1.StartComm ;

//有Modem时, 用如下方式来初始化Modem
Delay(1000);
OutPut(Comm1,#13#10+'asATZ'+#13#10); //发送ATZ来初始化, "as"师附加的, 可用另外别的字符
end;

procedure TCommWatchForm.Comm2ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
begin
Memo2.SelText := StrPas(Buffer);
MainForm.StatusBar.Panels[1].Text := '通道2接收';
end;
 
请问, Comm1.BaudRate := DBIniFile.ReadInteger('Comm1','BaudRate', 1200)
1200是指波特率吗?
Comm1HaveModem := DBIniFile.ReadBool('Comm1','HaveModem',False);这句是什么意思??

我用的是active牌14.4k的猫。多谢!!!
 
Don't mined it just set your BaudRate
 
虽然说专线猫是一个好东东, 其实不需要他使用普通猫照样实现专线连接, 只需要
将两个猫连起来其中一方或双方都设成自动应答, 给一个猫发出一个拨号指令, 任意
给一个号码即可
 
用MSCOMM32来试试吧,它不需要PCHAR的转换,直接用字符串收发
VB4.0以上中有这个ACTIVEX构件
具体编程我以前用VB边国
主要对应答ACK等信号判断处理
ONCOMM事件中
if Comm32.CommEvent = 2 then //收事件
begin

end;
我想用DELPHI是一样的
VB源码发给你.请你自己改为DELPHI,改完不妨给我寄一份


 
正好我前几天做了个SPCOMM的RS232通讯程序,不妨看看吧

//..........................//
// Created by Bluebird //
// 1998.12 //
// Communication public //
//........................../
//部分如下.......

private
{ Private declarations }
Nid :TNotifyIconData;
Did :integer;
AllowNext : Boolean;
TestStop: Boolean;
CountOfRight,CountOfFault :Integer;
procedure SetCom;
public
{ Public declarations }
procedure IconTray(var msg : Tmessage);message wm_IconMessage;
end;

var
Commfrm: TCommfrm;

implementation



{$R *.DFM}
procedure TCommFrm.SetCom;
//读REG文件并且设定目前的显示和信息
var RegFile : TRegIniFile;
begin
RegFile := TRegIniFile.Create('KJ99');
Comm1.CommName := RegFile.ReadString(COMMSEC, 'DownCom','COM1');
Comm1.BaudRate := RegFile.ReadInteger(COMMSEC,'DownBaudRate',9600);
RegFile.Free;
end;
procedure TcommFrm.CommDela(sec:WORD);
var T1 : LongWORD;
begin
t1:= GetTickCount;
while Sec>GetTickCount-t1 do Application.ProcessMessages;
end;
procedure TCommFrm.SendString(Str:String);
var PSendStr : Pchar;
begin
GetMem(PsendStr,100);
StrPCopy(PsendStr,Str);
Comm1.WriteCommData(PsendStr,Length(Str));
FreeMem(PsendStr);
end;
procedure Tcommfrm.ChangeIcon;
begin
if did=3 then did := 1;
if did=1 then nid.Hicon := CommsetFrm.Icon.Handle;
if did=2 then nid.Hicon := Icon.Handle;
did := did+1;
Shell_NotifyIcon(NIM_Modify,@nid);
end;

procedure TCommfrm.IconTray(var msg : Tmessage);
var pt :Tpoint;
begin
if msg.LParam = wm_Rbuttondown then
begin
GetCursorPos(pt);
SetForegroundWindow(Handle);
PopupMenu1.Popup(pt.x,pt.y);
end;
if msg.LParam =WM_LBUTTONdblclk then
begin
ShowWindow(Handle,sw_ShowNormal);
SetForegroundWindow(Handle);
show;
end;

end;
procedure TCommfrm.FormCreate(Sender: TObject);
begin
Comm1.StartComm;
CommTestOk := False;
end;
procedure TCommfrm.T1Click(Sender: TObject);
begin
Comm1.WriteCommData('CC1',3);
end;

procedure TCommfrm.FormDestroy(Sender: TObject);
begin
Comm1.StopComm;
end;

procedure TCommfrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caNone;
ShowWindow(handle,sw_Hide);
end;

procedure TCommfrm.Timer1Timer(Sender: TObject);
begin
End;


procedure TCommfrm.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var RevP : Pchar;
RevStr :string;
begin
SetLength(RevStr,2048);
RevP := Buffer;
RevStr := String(Revp);
Caption := inttostr(BufferLength);
If RevStr[1]='J' then
begin
CommTestOk := True;
CommRealFlag := True;
Timer1.Enabled := True;
end;
end;

procedure TCommfrm.BitBtn1Click(Sender: TObject);
var i ,Timescount: integer;
begin
AllowNext := True;
CountOfRight :=0;
CountOfFault :=0;
TimesCount := 0;
TestStop := False;
Label1.Caption := '';
Self.ResultList.Clear;
Self.ProgressBar1.Position := 0;
if not self.CheckBox1.Checked and CommTestOk and
(Cntlist.text<> '')then
Label1.Caption :=cntList.Text+'#中心站通讯正常!';
if not self.CheckBox1.Checked and not CommTestOk and
(Cntlist.text<> '')then
Label1.Caption :=cntList.Text+'#中心站通讯异常!';

if self.CheckBox1.Checked then //全部测试
begin
Self.ProgressBar1.Min := 0;
self.ProgressBar1.Max :=100* COMMTIMEOUT*self.CntList.Items.Count;
self.StatusBar1.Panels.Items[1].Text := '正在测试...';
For i := 0 to self.CntList.Items.Count-1 do
begin
CommTestOk := False;
TimesCount := 0;
SendString(COMMTESTFLAG +CntList.Items.strings);
repeat
Commdela(100);
TimesCount := TimesCount+1 ;
ProgressBar1.Position := ProGressBar1.Position+100;
until CommTestOk or TestStop or (TimesCount>=COMMTIMEOUT);
self.ProgressBar1.Position :=100*(i+1)*COMMTIMEOUT;
if CommTestOk then
begin
CountOfRight := CountOfRight + 1;
ResultList.Items.Add(cntList.Items.Strings+
'#中心站通讯正常 '+IntToStr(TimesCount*100)+'毫秒');
self.Update;
end
Else
begin
CountOfFault := CountOfFault +1 ;
ResultList.Items.Add(cntList.Items.Strings+
'#中心站通讯异常');
end;//if 1
Label1.Caption := '正常:'+ IntToStr(CountOfRight)
+'个 异常: ' +IntToStr(CountOfFault);
if TestStop Then begin
Self.ProgressBar1.Position := 0;
self.StatusBar1.Panels.Items[1].Text := '通讯暂停!'
end;//if 2

end; // for
Self.ProgressBar1.Position := 0;
self.StatusBar1.Panels.Items[1].Text := '通讯测试完毕!'
end
else
begin
SendString(COMMTESTFLAG +CntList.Text);
end;//
end;



end.
 
dwm5773:
上面程序片断是我从程序中考出来的, 删除了一些与您的问题无关的内容.
>Comm1.BaudRate := DBIniFile.ReadInteger('Comm1','BaudRate', 1200);
//设置波特率, 从ini文件中读取.
>Comm1HaveModem := DBIniFile.ReadBool('Comm1','HaveModem',False);
// 这是程序中另外的设置,与您的问题无关.
我觉得您出现的问题一定与modem的参数设置有关, 最好您是对照modem的
说明书, 用windows 的超级终端来察看和设置好参数.
我用爱华的28.8K &amp; 14.4K 使用这样的参数设置: #13+'ATQ0V1E1&amp;C1&amp;D2S0=0'+#13;
注意:每发送一个字符时中间要delay一下(因为是命令状态).
还有, Spcomm所能操作的Com口只能是硬端口(计算机原有的com1 &amp; com2 com3 ...),
对于一些用多功能卡扩展的软端口则不能正常工作, 只能对卡直接编程了.
 
首先,多谢各位高手指点,我发现把startcomm放在一个formcreat事件中后,可以接收信息。
但又有新问题:一。如果两只专线猫握手前执行我的程序,握手后程序只显示连接上了,无任何
字符接收。二。如果我的程序在猫握手后执行,程序显示几个乱字符,停止接收,当时对端还在不断的
发信息!!为什么,请高手指点!!!
 
DZM5773收到我的MAIL吗?
再给你一份
 
我的拨号程序是用VB写的,
关于这个程序,你一看就明白,你自己写成DELPHI的吧!
有什么问题,给我发MAIL
你可以参考,看完别忘了给我加分噢!

Option Explicit
Dim pack_num
Dim data_reactive$
Dim tel_num As String

Function dial_init() As Integer
Dim succ, i, start
Dim data_re$
succ = False
For i = 0 To 10
data_re$ = ""
mscomm1.InBufferCount = 0
mscomm1.Output = Chr$(13) + "ATQ0V1E1S0=0" + Chr$(13)
start = Timer
Do While Timer - start < 3.2
If mscomm1.InBufferCount Then
data_re$ = data_re$ + mscomm1.Input
If InStr(data_re$, "OK") Then
dial_init = 0
Exit Function
End If
End If
Loop
Next i
dial_init = 1
End Function
Function dela(ByVal i As Single) As Integer
Dim start As Single
start = Timer
Do While Timer - start < i
Loop
dela = 0
End Function


Function dial_t(ByVal Number As String) As Integer
Dim dialstring$
Dim start, rn, i
rn = dial_init()
If rn <> 0 Then
dial_t = 20
Form60.Caption = "dial init fail!"
Exit Function
Else
Form60.Caption = "dial init ok"
End If
rn = dela(1)
dialstring$ = Chr$(13) + "ATDP" + Form2.Text1.Text + Chr$(13)
mscomm1.Output = dialstring$
rn = dela(5)
data_reactive$ = ""
mscomm1.InBufferCount = 0
For i = 1 To 30
rn = dela(1)
Form60.Caption = Str(i)
If mscomm1.InBufferCount Then
data_reactive$ = data_reactive$ + mscomm1.Input
If InStr(data_reactive$, "CONNECT 2400") Then
dial_t = 0
txtconnect.Text = "建立(2400)"
txtwait.Text = " "
Exit Function
Else
If InStr(data_reactive$, "OK") Then
dial_t = 1
txtconnect.Text = "命令态"
txtwait.Text = " "
Exit Function
Else
If InStr(data_reactive$, "RING") Then
dial_t = 2
txtconnect.Text = "ring"
txtwait.Text = " "
Exit Function
Else
If InStr(data_reactive$, "CONNECT 1200") Then
dial_t = 0
txtconnect.Text = "connect 1200"

Exit Function
Else
If InStr(data_reactive$, "CONNECT 4800") Then
dial_t = 0
txtconnect.Text = "connect 4800"

Exit Function
Else
If InStr(data_reactive$, "CONNECT 9600") Then
dial_t = 0
txtconnect.Text = "connect 9600"
txtwait.Text = " "
Exit Function
Else
If InStr(data_reactive$, "CONNECT 19200") Then
dial_t = 0
txtconnect.Text = "connect 19200"
txtwait.Text = " "
Exit Function
Else
If InStr(data_reactive$, "CONNECT 33600") Then
dial_t = 0
txtconnect.Text = "connect 33600"
txtwait.Text = " "
Exit Function
Else
If InStr(data_reactive$, "NO CARRIER") Then
dial_t = 3
txtconnect.Text = "没有检测到远端载波"
txtwait.Text = " "
Exit Function
Else
If InStr(data_reactive$, "ERROR") Then
dial_t = 4
txtconnect.Text = "命令错"
txtwait.Text = " "
Exit Function
Else
If InStr(data_reactive$, "NO DIALTONE") Then
dial_t = 5
txtconnect.Text = "无拨号音"
txtwait.Text = " "
Exit Function
Else
If InStr(data_reactive$, "BUSY") Then
dial_t = 6
txtconnect.Text = "占线"
txtwait.Text = " "
Exit Function
Else
If InStr(data_reactive$, "NO ANSWER") Then
dial_t = 8
txtconnect.Text = "no answer"
txtwait.Text = " "
Exit Function
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If



Next i
dial_t = 21
Form60.Caption = "fail at line"
End Function




Function hangup() As Integer
Dim start, rn, i
Dim data_re$
For i = 1 To 10
data_re$ = " "
mscomm1.InBufferCount = 0
rn = dela(2)
mscomm1.Output = "+++"
rn = dela(2)
mscomm1.Output = "ATH" + Chr$(13) + Chr$(10)
start = Timer
Do While Timer - start < 4
If mscomm1.InBufferCount Then
data_re$ = data_re$ + mscomm1.Input
If InStr(data_re$, "OK") Then
hangup = 0
txtstatus.Text = "挂机"
Exit Function

End If
End If
Loop
Next i


hangup = 1


End Function

Function init_modem() As Integer
Dim dummy
Dim data_re$
Dim i, succ, start
On Error Resume Next
mscomm1.PortOpen = True
If Err Then
init_modem = 1
Exit Function
End If

mscomm1.Settings = "9600,N,8,1"
mscomm1.InBufferCount = 0
mscomm1.OutBufferCount = 0
mscomm1.InputLen = 0

succ = False
For i = 0 To 10
data_re$ = " "
mscomm1.InBufferCount = 0
mscomm1.Output = Chr$(13) + "ATZ" + Chr$(13)
start = Timer
Do While Timer - start < 3.2
If mscomm1.InBufferCount Then
data_re$ = data_re$ + mscomm1.Input
If InStr(data_re$, "OK") Then
succ = True
Exit For
End If
End If
Loop
Next i


If succ = False Then
init_modem = 2
mscomm1.PortOpen = False
Exit Function
End If


succ = False
For i = 0 To 10
data_re$ = " "
mscomm1.InBufferCount = 0

mscomm1.Output = Chr$(13) + "ATQ0V1E1S0=0" + Chr$(13)
start = Timer
Do While Timer - start < 2.2
If mscomm1.InBufferCount Then
data_re$ = data_re$ + mscomm1.Input
If InStr(data_re$, "OK") Then
succ = True
Form60.Caption = "reset ok"
Exit For
End If
End If
Loop
Next i


If succ = False Then
init_modem = 3
mscomm1.PortOpen = False
Exit Function
End If


init_modem = 0

End Function






Function rece_data(ByVal Number As String)
Dim data_rece$
Dim start, rn, dummy, nak_number
Dim crcdata$
Dim goon, re_flag
Dim normal_end

Dim rece_flag
pack_num = 0


rn = dial_t(Form2.Text1.Text)
txtstatus = "handing"
If rn <> 0 Then
rece_data = 1

Exit Function
End If

goon = True
normal_end = True
rece_flag = 0
nak_number = 0
Do
dummy = DoEvents()

mscomm1.Output = Chr$(21)
nak_number = nak_number + 1
If nak_number > 3 Then
normal_end = False
goon = False
End If
mscomm1.InBufferCount = 0
start = Timer
Do While Timer - start < 2
If mscomm1.InBufferCount >= 133 Then
rece_flag = 1
Exit Do
End If
Loop
start = Timer
If rece_flag = 1 And goon = True Then
rece_flag = 0
nak_number = 0
Do
dummy = DoEvents()
data_rece$ = mscomm1.Input
'show_text2 (data_rece$)
text2.Text = text2.Text + Mid(data_rece$, 1, 122)
Open "c:/t.txt" For Output As #1
Close #1
If Len(Trim(data_rece$)) > 0 Then
rn = 0
End If

rn = 0
If Mid(data_rece$, 1, 1) = Chr$(4) And rn = 0 Then
mscomm1.Output = Chr(24)
pack_num = pack_num + 1
normal_end = True
goon = True '原为false
txtstatus.Text = "结束"
Exit Do
End If

If Mid(data_rece$, 1, 1) = Chr$(24) Then
normal_end = False
goon = True '原为false
txtstatus.Text = "abort"
Exit Do
End If

If Mid(data_rece$, 1, 1) = Chr$(1) And rn = 0 Then
txtstatus.Text = "confirm"
mscomm1.Output = Chr$(6)
pack_num = pack_num + 1
nak_number = 0
mscomm1.InBufferCount = 0
re_flag = False
start = Timer
Do While Timer - start < 2
If mscomm1.InBufferCount >= 10 Then
re_flag = True
Exit Do
End If
Loop
If re_flag = False Then
Exit Do
End If
Else
End If
Loop
End If
Loop While goon = True
If normal_end = False Then
txtstatus.Text = "unnormal"
mscomm1.Output = Chr$(24)
End If
Close
End Function

Private Sub Command1_Click()
Dim rn, dummy
Dim i As Long
i = 0
If init_modem() <> 0 Then
txtconnect.Text = "modem bad"
rn = dela(3)


End
Else
txtconnect.Text = "modem status normal"

End If
rn = rece_data("20")
rn = hangup()
rn = dela(3)
mscomm1.PortOpen = False
End Sub

Private Sub Command2_Click()
Dim hn
hn = hangup()
End Sub

Private Sub Command3_Click()
formsee.Show
End Sub


Private Sub Form_Activate()
Label1.Caption = "接收到的数据"
txtconnect.Text = " "
txtstatus.Text = " "
txtwait.Text = " "
Text1.Text = Form2.Text1.Text

End Sub

Private Sub show_text2(data_rece$)
Dim chrl, chrr As Integer
Dim ch$
Dim i%
Dim text_2 As String
text_2$ = "收到字节数="
text_2$ = text_2$ + Str(Len(data_rece$)) + Chr(13) + Chr(10)
text_2$ = text_2$ + Mid(data_rece$, 1, 5) + Chr(13) + Chr(10) + "日期:"
For i% = 6 To 9
ch$ = Mid(data_rece$, i%, 1)
chrl = (Asc(ch$) And &amp;HF0) / 16
chrr = Asc(ch$) And &amp;HF
text_2$ = text_2$ + Chr$(chrl + 48) + Chr$(chrr + 48)
Next i%
text_2$ = text_2$ + Chr(13) + Chr(10) + "前半包数据:"
For i% = 10 To 57
ch$ = Mid(data_rece$, i%, 1)
chrl = (Asc(ch$) And &amp;HF0) / 16
If chrl < 10 Then
text_2$ = text_2$ + Chr$(chrl + 48)
Else
text_2$ = text_2$ + Chr$(chrl + 55)
End If
chrr = Asc(ch$) And &amp;HF
If chrr < 10 Then
text_2$ = text_2$ + Chr$(chrr + 48)
Else
text_2$ = text_2$ + Chr$(chrr + 55)
End If
Next i%
text_2$ = text_2$ + Chr(13) + Chr(10)
text_2$ = text_2$ + Mid(data_rece$, 58, 10) + Chr(13) + Chr(10)
text_2$ = text_2$ + Mid(data_rece$, 68, 2) + Chr(13) + Chr(10) + "日期:"
For i% = 70 To 73
ch$ = Mid(data_rece$, i%, 1)
chrl = (Asc(ch$) And &amp;HF0) / 16
chrr = Asc(ch$) And &amp;HF
text_2$ = text_2$ + Chr$(chrl + 48) + Chr$(chrr + 48)
Next i%
text_2$ = text_2$ + Chr(13) + Chr(10) + "后半包数据:"
For i% = 74 To 121
ch$ = Mid(data_rece$, i%, 1)
chrl = (Asc(ch$) And &amp;HF0) / 16
If chrl < 10 Then
text_2$ = text_2$ + Chr$(chrl + 48)
Else
text_2$ = text_2$ + Chr$(chrl + 55)
End If
chrr = Asc(ch$) And &amp;HF
If chrr < 10 Then
text_2$ = text_2$ + Chr$(chrr + 48)
Else
text_2$ = text_2$ + Chr$(chrr + 55)
End If
Next i%
text_2$ = text_2$ + Chr(13) + Chr(10)
text_2$ = text_2$ + Mid(data_rece$, 122, 10) + Chr(13) + Chr(10)
text_2$ = text_2$ + "CRC校验:" + Chr(13) + Chr(10)
For i% = 132 To 133
ch$ = Mid(data_rece$, i%, 1)
chrl = (Asc(ch$) And &amp;HF0) / 16
If chrl < 10 Then
text_2$ = text_2$ + Chr$(chrl + 48)
Else
text_2$ = text_2$ + Chr$(chrl + 55)
End If
chrr = Asc(ch$) And &amp;HF
If chrr < 10 Then
text_2$ = text_2$ + Chr$(chrr + 48)
Else
text_2$ = text_2$ + Chr$(chrr + 55)
End If
Next i%
text2.Text = text_2$ + Chr(13) + Chr(10)
End Sub

Public Function rece(ByVal Number As String)
Dim data_rece$
Dim start, rn, dummy, nak_number
Dim goon, re_flag
Dim normal_end
Dim rece_flag
pack_num = 0
rn = dial_t(Text1.Text)
txtstatus = "handing"
If rn <> 0 Then
rece_data = 1
Exit Function
End If
goon = True
normal_end = True
rece_flag = 0
nak_number = 0
Do
dummy = DoEvents()
mscomm1.Output = Chr$(21)
nak_number = nak_number + 1
If nak_number > 3 Then
normal_end = False
goon = False
End If
mscomm1.InBufferCount = 0
start = Timer
Do While Timer - start < 2
If mscomm1.InBufferCount >= 133 Then
rece_flag = 1
Exit Do
End If
Loop
start = Timer
If rece_flag = 1 And goon = True Then
rece_flag = 0
nak_number = 0
Do
dummy = DoEvents()
data_rece$ = mscomm1.Input
'show_text2 (data_rece$)
text2.Text = Mid(data_rece$, 3, 131)
If Len(Trim(data_rece$)) > 0 Then
rn = 0
End If
rn = 0
If Mid(data_rece$, 131, 1) = Chr$(4) And rn = 0 Then
mscomm1.Output = Chr(24)
pack_num = pack_num + 1
normal_end = True
goon = False
txtstatus.Text = "结束"
Exit Do
End If

If Mid(data_rece$, 1, 1) = Chr$(24) Then
normal_end = False
goon = False
txtstatus.Text = "abort"
Exit Do
End If

If Mid(data_rece$, 1, 1) = Chr$(1) And rn = 0 Then
txtstatus.Text = "confirm"
mscomm1.Output = Chr$(6)
pack_num = pack_num + 1
nak_number = 0
mscomm1.InBufferCount = 0
re_flag = False
start = Timer
Do While Timer - start < 2
If mscomm1.InBufferCount >= 133 Then
re_flag = True
Exit Do
End If
Loop
If re_flag = False Then
Exit Do
End If
Else
End If

Loop
End If
Loop While goon = True
If normal_end = False Then
txtstatus.Text = "unnormal"
mscomm1.Output = Chr$(24)
End If
Close
End Function
 
异步通信专业版,带源码,5.2M
应该可以解决你的问题
http://www.seawind.com.cn/files/delphi/async25.zip
 

Similar threads

I
回复
0
查看
494
import
I
I
回复
0
查看
482
import
I
I
回复
0
查看
760
import
I
I
回复
0
查看
586
import
I
I
回复
0
查看
480
import
I
顶部