?? zlgcomport.frm
字號:
Top = 2685
Width = 735
End
Begin VB.Label Label3
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 = 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, 周立功單片機發展有限公司
' * All rights reserved.
' *
' * 文 件: FrmZlgComPort
' *
' * 摘 要: 本程序主要是通過調用ZmpCom.dll動態連接庫函數對 DP-51學習板
' * 24WC02時行讀寫控制。
' *
' *
' * 創建日期: 2002年10月26日
' *
' ******************************************************************************
' */
Private Sub Ch1_Click()
'------------------------------------------------------------
'說明: 判斷是否是輸入十六時制數,而設定文本框數據接授長度
'------------------------------------------------------------
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()
'------------------------------------------------------------
'說明: 打開及關閉串口
'------------------------------------------------------------
If ComOpenPort.Caption = "&O.打開端口" Then
i = ComPro.ListIndex + 1
stbl = SetCommPort(i) '設置端口
If stbl = False Then
MsgBox "請檢查端口設置是否正確!", vbInformation, "提示"
Exit Sub
End If
st = OpenPort() '打開串口
If st <> 0 Then
MsgBox "打開串口失敗!", vbInformation, "提示"
PortOpen = False
Exit Sub
End If
PortOpen = True
ComOpenPort.Caption = "&C.關閉端口"
Else
st = ClosePort()
If st <> 0 Then
MsgBox "關閉端口失敗!", vbInformation, "提示"
Exit Sub
End If
ComOpenPort.Caption = "&O.打開端口"
End If
End Sub
Private Sub ComRead_Click()
'------------------------------------------------------------
'說明: 先判斷輸入的數據是否符合要求,然后傳給讀函數
'------------------------------------------------------------
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 "端口沒有打開!", vbInformation, "提示"
Exit Sub
End If
If Len(Trim(TIAdd)) = 0 Then
MsgBox "請輸入讀數據的起始地址!", vbInformation, "提示"
Exit Sub
End If
If Len(Trim(Tlen)) = 0 Then
MsgBox "請輸入數據長度!", vbInformation, "提示"
Exit Sub
End If
If Val(Trim(Tlen)) > 256 Then
MsgBox "最多只能讀取256個數據!", 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數據成功!", vbInformation, "提示"
Else
MsgBox "讀E2PROM數據出錯!", vbInformation, "提示"
End If
Exit Sub
HaveErr:
MsgBox "對不起!系統出錯,請重新操作。", vbInformation, "提示"
End Sub
Private Sub ComWrite_Click()
'------------------------------------------------------------
'說明: 先判斷輸入的數據是否符合要求,然后傳給寫函數
'------------------------------------------------------------
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 "端口沒有打開!", vbInformation, "提示"
Exit Sub
End If
If Len(Trim(TDAdd)) = 0 Then
MsgBox "請輸入寫數據的起始地址!", vbInformation, "提示"
Exit Sub
End If
If Len(Trim(TDown)) = 0 Then
MsgBox "請輸入要寫入的數據!", 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 "寫數據有誤,請重新操作!", vbInformation, "提示"
Exit Sub
End If
MsgBox "寫E2PROM數據成功!", vbInformation, "提示"
Exit Sub
HaveErr:
MsgBox "對不起!系統出錯,請重新操作。", vbInformation, "提示"
End Sub
Private Sub Form_Load()
'------------------------------------------------------------
'說明: 初始化端口
'------------------------------------------------------------
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 "請檢查波特率設置是否正確!", vbInformation, "提示"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'------------------------------------------------------------
'說明: 關閉串口釋放串口資源
'------------------------------------------------------------
st = ClosePort()
End Sub
Private Sub TDAdd_KeyPress(KeyAscii As Integer)
'------------------------------------------------------------
' 判斷輸入是否為有效字符符(十六進制數)
'------------------------------------------------------------
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)
'------------------------------------------------------------
' 判斷輸入是否為有效字符符(十六進制數),及空格
'------------------------------------------------------------
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)
'------------------------------------------------------------
' 判斷輸入是否為有效字符符(十六進制數)
'------------------------------------------------------------
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)
'------------------------------------------------------------
' 判斷輸入是否為有效字符符(十進制數)
'------------------------------------------------------------
Select Case KeyAscii
Case 8
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -