?? yuntai.frm
字號(hào):
'*****************************************
'功能:確定是第一次運(yùn)行本程序以及相關(guān)文件是否存在
'*****************************************
Private Sub FileTest()
Dim IsInstalled As Boolean
Dim IsExist As Boolean
Dim file As New clsFile
Dim strMsg As String
'檢測(cè)相關(guān)文件是否存在
IsExist = file.IsFileExist(App.Path + "\" + "WinIo.sys")
If Not IsExist Then
MsgBox "找不到文件WinIo.sys,請(qǐng)確定與本應(yīng)用程序在同一目錄下!", vbCritical
End
End If
IsExist = file.IsFileExist(App.Path + "\" + "WinIo.dll")
If Not IsExist Then
MsgBox "找不到文件WinIo.dll,請(qǐng)確定與本應(yīng)用程序在同一目錄下!", vbCritical
End
End If
IsExist = file.IsFileExist(App.Path + "\" + "WinIo.vxd")
If Not IsExist Then
MsgBox "找不到文件WinIo.vxd,請(qǐng)確定與本應(yīng)用程序在同一目錄下!", vbCritical
End
End If
Dim st As String
st = GetSetting("Yuntai", "Settings", "IsInstalled")
'第一次運(yùn)行,安裝WinIo庫,寫入注冊(cè)信息
If st <> "1" Then
SaveSetting "Yuntai", "Settings", "WinioPath", App.Path + "\" + "winio.sys"
SaveSetting "Yuntai", "Settings", "IsInstalled", "1"
'安裝WinIo庫
IsInstalled = InstallWinIoDriver(App.Path + "\" + "winio.sys", False)
If Not IsInstalled Then
MsgBox "WinIo庫安裝失敗,請(qǐng)確認(rèn)是否有管理員權(quán)限,詳細(xì)問題請(qǐng)與管理員聯(lián)系" _
+ Chr(13) + "警告:WinIo庫安裝失敗的情況下只可以使用串口通訊,并口無法使用。", vbCritical
Call RemoveWinIoDriver
Else
strMsg = "云臺(tái)控制系統(tǒng)在您當(dāng)前操作系統(tǒng)中成功安裝了WinIo庫 "
Call SystemUpdatedRestart(strMsg, EWX_REBOOT)
End
End If
End If
End Sub
'*****************************************
'初始化
'*****************************************
Private Sub Form_Load()
'指定顏色值
frameRgb = RGB(173, 166, 156)
brightRgb = RGB(255, 255, 255)
darkRgb = RGB(115, 105, 99)
bkUpRgb = RGB(215, 215, 215)
bkDownRgb = &H8000000F
'求得pixel和twip之間的關(guān)系
Scale_X = Screen.TwipsPerPixelX
Scale_Y = Screen.TwipsPerPixelY
strFileName = "YuntaiConfig.ini"
StatusBar1.Panels(1).Width = Me.Width
'確定是第一次運(yùn)行本程序以及相關(guān)文件是否存在
Call FileTest
'繪制按鈕
Call DrawPushButton
'加載指令集和通讀參數(shù)
Call Initial
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim iniFile As New clsFile
Dim bSuccess As Boolean
'終止WinIo庫
ShutdownWinIo
'清空配置文件
' bSuccess = iniFile.DeleteFileEx(App.Path + "\" + strFileName)
With iniFile
.OpenFile (App.Path + "\" + strFileName)
'存儲(chǔ)通信方式
.WriteByte bSerial
'存儲(chǔ)串口各參數(shù)
.WriteByte conSerialPort.Parity
.WriteLong conSerialPort.BaudRate
.WriteLong conSerialPort.DataBits
.WriteSingle conSerialPort.StopBits
.WriteByte conSerialPort.PortNr
'存儲(chǔ)IO端口號(hào)
.WriteLong IoPort
'存儲(chǔ)指令集
.WriteArray ByteCodeChoose
.WriteArray ByteCodeAct
.WriteArray ByteCodeMir
.WriteArray ByteCodeStatus
'存儲(chǔ)32個(gè)云臺(tái)狀態(tài)
.WriteArray2Dim ByteStatus, 33, 3
.CloseFile
End With
End Sub
Private Sub labChoose_Click(index As Integer)
picChoose_Click index
End Sub
'*********************************************
'功能:使指定按鈕浮起
'參數(shù):index,被浮起按鈕在控件數(shù)組中的index值
'*********************************************
Private Sub LiftButton(index As Integer)
InnerLineTop(index).BorderColor = brightRgb
InnerLineLeft(index).BorderColor = brightRgb
picChoose(index).BackColor = bkUpRgb
shpFrame(index).BorderColor = frameRgb
End Sub
'*********************************************
'功能:使指定按鈕下沉
'參數(shù):index,被下沉按鈕在控件數(shù)組中的index值
'*********************************************
Private Sub DownButton(index As Integer)
InnerLineTop(index).BorderColor = darkRgb
InnerLineLeft(index).BorderColor = darkRgb
picChoose(index).BackColor = bkDownRgb
shpFrame(index).BorderColor = bkUpRgb
End Sub
'*******************************************
'功能:響應(yīng)對(duì)云臺(tái)選擇按鈕和狀態(tài)按鈕的單擊響應(yīng)
'參數(shù):Index:被點(diǎn)擊的picChoose的index值
'*******************************************
Private Sub picChoose_Click(index As Integer)
Dim i As Integer
'點(diǎn)擊選擇云臺(tái)按鈕
If index < 33 Then
If index = curChoose Then Exit Sub
'重畫按鈕,使原按鈕浮起
Call LiftButton(curChoose)
'重畫按鈕,使當(dāng)前被點(diǎn)擊按鈕凹下
Call DownButton(index)
curChoose = index
'發(fā)送云臺(tái)選擇指令
WriteToPort ByteCodeChoose(curChoose), 1
'裝載選中云臺(tái)三狀態(tài)(射燈、雨刷與自動(dòng)),并取消原云臺(tái)選中標(biāo)志
For i = 0 To 2
If ByteStatus(curChoose, i) = 0 Then
Call LiftButton(33 + i)
Else
Call DownButton(33 + i)
End If
Next i
'點(diǎn)擊狀態(tài)切換按鈕
Else
'改變?cè)婆_(tái)指定狀態(tài)值
If ByteStatus(curChoose, index - 33) Then
ByteStatus(curChoose, index - 33) = 0
Call LiftButton(index)
Else
ByteStatus(curChoose, index - 33) = 1
Call DownButton(index)
End If
'計(jì)算待發(fā)送指令值
Dim code As Byte
code = &HC0
If ByteStatus(curChoose, 0) Then
code = code + 1
End If
For i = 1 To 2
If ByteStatus(curChoose, i) Then
code = code + i * 2
End If
Next i
'發(fā)送指令
Call WriteToPort(code, 1)
End If
End Sub
'狀態(tài)欄消息,顯示程序向解碼器發(fā)送的控制碼
Private Sub StatusInfo(strPort As String, strData As String)
StatusBar1.Panels(1).Text = "通過" + strPort + "發(fā)送指令" + strData
End Sub
'******************************************************
'向串口或IO口發(fā)指令,程序上層界面與底層通信模塊交互的唯一函數(shù)
'******************************************************
Private Sub WriteToPort(ByVal pData As Byte, datLen As Integer)
On Error GoTo ErrProcess:
'格式化狀態(tài)欄消息參數(shù)Data
Dim strPort As String
Dim Data As String
Dim bRet As Boolean
Dim arData(0 To 0) As Byte
Data = CBin(pData)
arData(0) = pData
If bSerial Then
'格式化狀態(tài)欄消息參數(shù)strPort
strPort = "串口" + Str(conSerialPort.PortNr)
'向串口發(fā)送指令
' MSComm1.CommPort = conSerialPort.PortNr
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
MSComm1.Output = arData()
MSComm1.PortOpen = False
Else
'格式化狀態(tài)欄消息參數(shù)strPort
strPort = "并口" + Str(IoPort)
'向IO端口發(fā)送指令,若失敗則在狀態(tài)欄顯示失敗消息。
'注意失敗只可能由WinIO庫初始化錯(cuò)誤引起
bRet = SetPortVal(IoPort, pData, Len(pData))
If Not bRet Then
Data = Data + "失敗"
End If
End If
'在狀態(tài)欄顯示傳送指令信息
StatusInfo strPort, Data
Exit Sub
ErrProcess:
MsgBox "錯(cuò)誤提示:" + Err.Description, vbCritical
End Sub
'*********************************************
'功能:在未提供配置文件時(shí),以默認(rèn)指令集初始化各程序控制碼
'*********************************************
Private Sub DefaultCodeSet()
Dim i As Byte
For i = 1 To 32
ByteCodeChoose(i) = i
Next i
For i = 0 To 3
ByteCodeAct(i) = &H40 + i
Next i
ByteCodeAct(4) = 0 'reset
For i = 0 To 5
ByteCodeMir(i) = &H80 + i
Next i
ByteCodeStatus(0) = &HC0 + 1
For i = 1 To 2
ByteCodeStatus(i) = &HC0 + i * 2
Next i
End Sub
'*********************************************
'功能:在未提供配置文件時(shí),以默認(rèn)參數(shù)初始化串口和IO
'*********************************************
Private Sub DefaultPortSet()
On Error GoTo ErrProcess:
'串口的默認(rèn)設(shè)置
With conSerialPort
.PortNr = 1
.BaudRate = 9600
.Parity = Asc("E")
.DataBits = 7
.StopBits = 1
MSComm1.CommPort = .PortNr
MSComm1.InputMode = comInputModeText
MSComm1.Settings = Str(.BaudRate) + "," + Chr(.Parity) + "," + Str(.DataBits) + "," + Str(.StopBits)
End With
'IO口的默認(rèn)設(shè)置
IoPort = 956
'默認(rèn)啟用串口
bSerial = True
MSComm1.InputLen = 0
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
Exit Sub
'錯(cuò)誤處理:
ErrProcess:
'有錯(cuò)誤發(fā)生時(shí)MSComm1的最保守配置
MSComm1.CommPort = 1
MSComm1.InputMode = comInputModeText
MSComm1.Settings = "9600,n,8,1"
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
End Sub
'*******************************************
'功能:初使化用,加載指令集和串口、并口的通訊參數(shù)
'*******************************************
Private Sub Initial()
'定義類模塊clsFile對(duì)象,用于文件操作
Dim iniFile As New clsFile
'標(biāo)志
Dim bSuccess As Boolean
'文件操作時(shí)用,讀取串口參數(shù)
Dim Parity As Byte
Dim PortNr As Byte
Dim BaudRate As Long
Dim DataBits As Long
Dim StopBits As Single
On Error GoTo ErrProcess:
'打開配置文件對(duì)象,配置文件存儲(chǔ)程序通信方式及其參數(shù)、云臺(tái)指令集與32云臺(tái)狀態(tài)
bSuccess = iniFile.OpenFile(App.Path + "\" + strFileName)
'若存在配置文件且配置文件不為空
If iniFile.GetLength() = 0 Then
'若不存在配置文件或配置文件為空,
'并使用默認(rèn)指令集初始化各控制碼
DefaultCodeSet
'則使用默認(rèn)串口參數(shù)初始化串口,
DefaultPortSet
Else
With iniFile
'由配置文件讀入通信方式
.ReadByte bSerial
'由配置文件讀入串口與IO口參數(shù)
.ReadByte Parity
.ReadLong BaudRate
.ReadLong DataBits
.ReadSingle StopBits
.ReadByte PortNr
'讀入IO端口號(hào)
.ReadLong IoPort
'由配置文件讀入指令集
.ReadArray ByteCodeChoose
.ReadArray ByteCodeAct
.ReadArray ByteCodeMir
.ReadArray ByteCodeStatus
'由配置文件讀入各云臺(tái)狀態(tài)
.ReadArray2Dim ByteStatus, 33, 3
End With
'更新串口參數(shù)
With conSerialPort
.Parity = Parity
.BaudRate = BaudRate
.DataBits = DataBits
.StopBits = StopBits
.PortNr = PortNr
End With
'若通信使用串口,則初始化串口,并啟動(dòng)串口監(jiān)聽
If bSerial = True Then
If conSerialPort.PortNr < 1 Or conSerialPort.PortNr > 4 Then
conSerialPort.PortNr = 1
End If
MSComm1.CommPort = conSerialPort.PortNr
MSComm1.InputMode = comInputModeText
MSComm1.Settings = Str(conSerialPort.BaudRate) + "," + _
Chr(conSerialPort.Parity) + "," + Str(conSerialPort.DataBits) _
+ "," + Str(conSerialPort.StopBits)
MSComm1.InputLen = 0
' 打開串口
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
'若通信使用并口,初始化WinIO庫
Else
Dim bResult As Boolean
bResult = InitializeWinIo()
If Not bResult Then
MsgBox ("WINIO庫初始化失敗")
End If
End If
End If
'讀取完畢,關(guān)閉配置文件存檔對(duì)象指針
iniFile.CloseFile
curChoose = 0
'默認(rèn)選擇云臺(tái)1
picChoose_Click (1)
Exit Sub
ErrProcess:
DefaultCodeSet
DefaultPortSet
iniFile.CloseFile
curChoose = 0
picChoose_Click (1)
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -