?? zlgcomport.frm
字號(hào):
Top = 2685
Width = 735
End
Begin VB.Label Label3
Caption = "下載數(shù)據(jù)"
BeginProperty Font
Name = "宋體"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 270
Left = 480
TabIndex = 2
Top = 840
Width = 735
End
Begin VB.Label Label1
Caption = "起始地址"
BeginProperty Font
Name = "宋體"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 270
Left = 480
TabIndex = 1
Top = 405
Width = 735
End
End
Begin VB.Label Label8
Caption = "端口"
BeginProperty Font
Name = "宋體"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 360
TabIndex = 18
Top = 4185
Width = 375
End
End
Attribute VB_Name = "FrmZlgComPort"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' /*
' *****************************************************************************
' *
' * Copyright(c) 2002, 周立功單片機(jī)發(fā)展有限公司
' * All rights reserved.
' *
' * 文 件: FrmZlgComPort
' *
' * 摘 要: 本程序主要是通過(guò)調(diào)用ZmpCom.dll動(dòng)態(tài)連接庫(kù)函數(shù)對(duì) DP-51學(xué)習(xí)板
' * 24WC02時(shí)行讀寫(xiě)控制。
' *
' *
' * 創(chuàng)建日期: 2002年10月26日
' *
' ******************************************************************************
' */
Private Sub Ch1_Click()
'------------------------------------------------------------
'說(shuō)明: 判斷是否是輸入十六時(shí)制數(shù),而設(shè)定文本框數(shù)據(jù)接授長(zhǎng)度
'------------------------------------------------------------
TDown = ""
If Ch1.Value = 1 Then
TDown.MaxLength = 256 * 3
Else
TDown.MaxLength = 256
End If
End Sub
Private Sub ComExit_Click()
Unload Me '退出
End Sub
Private Sub ComOpenPort_Click()
'------------------------------------------------------------
'說(shuō)明: 打開(kāi)及關(guān)閉串口
'------------------------------------------------------------
If ComOpenPort.Caption = "&O.打開(kāi)端口" Then
i = ComPro.ListIndex + 1
stbl = SetCommPort(i) '設(shè)置端口
If stbl = False Then
MsgBox "請(qǐng)檢查端口設(shè)置是否正確!", vbInformation, "提示"
Exit Sub
End If
st = OpenPort() '打開(kāi)串口
If st <> 0 Then
MsgBox "打開(kāi)串口失敗!", vbInformation, "提示"
PortOpen = False
Exit Sub
End If
PortOpen = True
ComOpenPort.Caption = "&C.關(guān)閉端口"
Else
st = ClosePort()
If st <> 0 Then
MsgBox "關(guān)閉端口失敗!", vbInformation, "提示"
Exit Sub
End If
ComOpenPort.Caption = "&O.打開(kāi)端口"
End If
End Sub
Private Sub ComRead_Click()
'------------------------------------------------------------
'說(shuō)明: 先判斷輸入的數(shù)據(jù)是否符合要求,然后傳給讀函數(shù)
'------------------------------------------------------------
Dim BgnAdr_L As Integer
Dim BgnAdr_H As Integer
Dim nLen As Integer
Dim Str As String
Dim str2 As String '用于接收返回值
On Error GoTo HaveErr
If PortOpen = False Then
MsgBox "端口沒(méi)有打開(kāi)!", vbInformation, "提示"
Exit Sub
End If
If Len(Trim(TIAdd)) = 0 Then
MsgBox "請(qǐng)輸入讀數(shù)據(jù)的起始地址!", vbInformation, "提示"
Exit Sub
End If
If Len(Trim(Tlen)) = 0 Then
MsgBox "請(qǐng)輸入數(shù)據(jù)長(zhǎng)度!", vbInformation, "提示"
Exit Sub
End If
If Val(Trim(Tlen)) > 256 Then
MsgBox "最多只能讀取256個(gè)數(shù)據(jù)!", vbInformation, "提示"
Exit Sub
End If
BgnAdr_L = HtoD(Trim(TDAdd))
BgnAdr_H = 0
nLen = Val(Trim(Tlen))
str2 = ""
str2 = ReadE2PRom(BgnAdr_L, BgnAdr_H, nLen)
If Len(str2) <> 0 Then
TIncept = ""
If Ch2.Value = 1 Then
TIncept = StoH(str2)
Else
TIncept = str2
End If
MsgBox "讀E2PROM數(shù)據(jù)成功!", vbInformation, "提示"
Else
MsgBox "讀E2PROM數(shù)據(jù)出錯(cuò)!", vbInformation, "提示"
End If
Exit Sub
HaveErr:
MsgBox "對(duì)不起!系統(tǒng)出錯(cuò),請(qǐng)重新操作。", vbInformation, "提示"
End Sub
Private Sub ComWrite_Click()
'------------------------------------------------------------
'說(shuō)明: 先判斷輸入的數(shù)據(jù)是否符合要求,然后傳給寫(xiě)函數(shù)
'------------------------------------------------------------
Dim BgnAdr_L As Integer
Dim BgnAdr_H As Integer
Dim Str As String
Dim str2 As String
On Error GoTo HaveErr
If PortOpen = False Then
MsgBox "端口沒(méi)有打開(kāi)!", vbInformation, "提示"
Exit Sub
End If
If Len(Trim(TDAdd)) = 0 Then
MsgBox "請(qǐng)輸入寫(xiě)數(shù)據(jù)的起始地址!", vbInformation, "提示"
Exit Sub
End If
If Len(Trim(TDown)) = 0 Then
MsgBox "請(qǐng)輸入要寫(xiě)入的數(shù)據(jù)!", vbInformation, "提示"
Exit Sub
End If
BgnAdr_L = HtoD(Trim(TDAdd))
BgnAdr_H = 0
If Ch1.Value = 1 Then
Str = HtoS(TDown)
Else
Str = Trim(TDown)
End If
st = WriteE2PRom(BgnAdr_L, BgnAdr_H, Str)
If st <> 0 Then
MsgBox "寫(xiě)數(shù)據(jù)有誤,請(qǐng)重新操作!", vbInformation, "提示"
Exit Sub
End If
MsgBox "寫(xiě)E2PROM數(shù)據(jù)成功!", vbInformation, "提示"
Exit Sub
HaveErr:
MsgBox "對(duì)不起!系統(tǒng)出錯(cuò),請(qǐng)重新操作。", vbInformation, "提示"
End Sub
Private Sub Form_Load()
'------------------------------------------------------------
'說(shuō)明: 初始化端口
'------------------------------------------------------------
ComPro.Clear
ComPro.AddItem (" COM1")
ComPro.AddItem (" COM2")
ComPro.AddItem (" COM3")
ComPro.AddItem (" COM4")
ComPro.ListIndex = 0
stbl = SetCommBaud(9600) '波特率
If stbl = False Then
MsgBox "請(qǐng)檢查波特率設(shè)置是否正確!", vbInformation, "提示"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'------------------------------------------------------------
'說(shuō)明: 關(guān)閉串口釋放串口資源
'------------------------------------------------------------
st = ClosePort()
End Sub
Private Sub TDAdd_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判斷輸入是否為有效字符符(十六進(jìn)制數(shù))
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub TDown_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判斷輸入是否為有效字符符(十六進(jìn)制數(shù)),及空格
'------------------------------------------------------------
If Ch1.Value = 1 Then
Select Case KeyAscii
Case 8
Case 32 '空格
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End If
End Sub
Private Sub TIAdd_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判斷輸入是否為有效字符符(十六進(jìn)制數(shù))
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 48 To 57
Case 65 To 70
Case 97 To 102
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub TIncept_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Private Sub Tlen_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判斷輸入是否為有效字符符(十進(jìn)制數(shù))
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -