顯示條屏

顯示條屏

顯示條屏是一個Rocky編寫的例程。

例程的作用類似於函式,但含義更為豐富一些。例程是某個系統對外提供的功能接口或服務的集合。比如作業系統的API、服務等就是例程;Delphi或C++Builder提供的標準函式和庫函式等也是例程。我們編寫一個DLL的時候,裡面的輸出函式就是這個DLL的例程。

基本介紹

  • 中文名:顯示條屏
  • 外文名:Display bar screen
  • 編寫:Rocky
  • 地點:深圳
  • 發布時間:2005年4月20日
具體代碼,End Sub,

具體代碼

'本例程由Rocky編寫,免費提供。-----------2005年04月20日於深圳
'本例程沒有經過在線上(條屏)調試,效果需要實際調試後才確定。
'
'本例程只傳送文本形式條屏內容,圖片形式可以根據協定修改。
'本例程只採用了兩幀文字,需要增加文字幀,只需要在指令中增加幀內容即可。
'
'本例程使用方法:
'第一步:打開串口
'測試串口的方法是:將串口的第2、3腳短路,利用本程式的傳送和接收測試。
'第二步:在線上調試,將條屏安裝在相應的串口上,通過逐條指令傳送,觀看效果。
'
'特別注意:
'
'由於本例程只寫了文字方式的傳送。在線上調試時,先使用圖文切換至文字模式。
'
'
Option Explicit
Private ComNum As String '串口通道
Private ComBps As String '傳輸速率
Private ComCheck As String '奇偶校驗位
Private ComBITNum As String '數據位
Private ComStop As String '停止位
Private bComStates As Boolean '串口打開/關閉狀態
Private txtSendWords As String '傳送數據,測試串口使用
Private disWords1 As String '傳送條屏顯示文字-1
Private disWords2 As String '傳送條屏顯示文字-2
Private swWord As String '切換到文字模式
Private swPIC As String '切換到圖片模式
Private swMOD As Boolean '模式
Private pnlX As Panel '狀態欄,可以不用
Private pnlX1 As Panel '狀態欄,可以不用
Private pnlX2 As Panel '狀態欄,可以不用
Private txtWord1 As String '顯示文字1
Private txtWord2 As String '顯示文字2
Private CtlWord1 As String '控制命令1-16
Private CtlWord2 As String
Private CtlWord3 As String
Private CtlWord4 As String
Private CtlWord5 As String
Private CtlWord6 As String
Private CtlWord7 As String
Private CtlWord8 As String
Private CtlWord9 As String
Private CtlWord10 As String
Private CtlWord11 As String
Private CtlWord12 As String
Private CtlWord13 As String
Private CtlWord14 As String
Private CtlWord15 As String
Private CtlWord16 As String
Private Sub bAutoRe Click
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
End Sub
Private Sub CloseCom Click
On Error GoTo ErrCode
MSComm1.PortOpen = False
bComStates = False
'MsgBox ''關閉串口成功
pnlX2.Text = ''串口關閉
pnlX.Text = ''''
Exit Sub
ErrCode:
'MsgBox ''關閉串口失敗
pnlX2.Text = ''串口關閉
pnlX.Text = ''''
bComStates = False
End Sub
Private Sub Command1 Click
If bComStates = True Then
MSComm1.Output = CtlWord1
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command10 Click
If bComStates = True Then
MSComm1.Output = CtlWord10
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command11 Click
If bComStates = True Then
If swMOD = True Then
swMOD = False
pnlX1.Text = ''傳送模式:文字模式''
Else
swMOD = True
pnlX1.Text = ''傳送模式:圖片模式''
End If
MSComm1.Output = CtlWord11
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command12 Click
If bComStates = True Then
MSComm1.Output = CtlWord12
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command13 Click
If bComStates = True Then
MSComm1.Output = CtlWord13
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command14 Click
If bComStates = True Then
MSComm1.Output = CtlWord14
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command15 Click
If bComStates = True Then
MSComm1.Output = CtlWord15
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command16 Click
If bComStates = True Then
MSComm1.Output = CtlWord16
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command17 Click
If bComStates = True Then
If swMOD = True Then
swMOD = False
pnlX1.Text = ''傳送模式:文字模式''
Else
swMOD = True
pnlX1.Text = ''傳送模式:圖片模式''
End If
MSComm1.Output = swWord
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command2 Click
If bComStates = True Then
MSComm1.Output = CtlWord2
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command3 Click
If bComStates = True Then
MSComm1.Output = CtlWord3
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Top
4樓tmran(Rocky愛瘦魚)回復於2005-04-2003:38:36
Private Sub Command4 Click
If bComStates = True Then
MSComm1.Output = CtlWord4
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command5 Click
If bComStates = True Then
MSComm1.Output = CtlWord5
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command6 Click
If bComStates = True Then
MSComm1.Output = CtlWord6
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command7 Click
If bComStates = True Then
MSComm1.Output = CtlWord7
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command8 Click
If bComStates = True Then
MSComm1.Output = CtlWord8
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Command9 Click
If bComStates = True Then
MSComm1.Output = CtlWord9
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Form_Unload Cancel As Integer
If bComStates = True Then
MSComm1.PortOpen = False '關閉串口
bComStates = False
End If
Unload Me
End Sub
Private Sub Rec Click
If bComStates = True Then
txtReceving.Text = MSComm1.Input
If txtReceving.Text Then
pnlX.Text = ''系統狀態:接收數據成功
Else
pnlX.Text = ''系統狀態:接收數據為空
End If
End If
End Sub
Private Sub Form Load
Set pnlX = sbrDB.Panels.Add(1)
Set pnlX1 = sbrDB.Panels.Add(2)
Set pnlX2 = sbrDB.Panels.Add(3)
pnlX.Width = 3500
pnlX1.Width = 3000
pnlX2.Width = 2000
pnlX1.Text = ''傳送模式:圖片模式''
pnlX2.Text = ''串口未打開
swMOD = True
Combo1.ListIndex = 0
Combo2.ListIndex = 8
Combo3.ListIndex = 4
Combo4.ListIndex = 2
Combo5.ListIndex = 0
txtWord1 = ''條屏通信效果測試'' '本例使用兩幀文字以作效果,可以多用幾組,根據效果需要設計
txtWord2 = ''條屏通信效果測試''
disWords1 = ''CMD01A'' & ''01'' & txtWord1 & ''00'' '第一幀文字
disWords2 = ''CMD01A'' & ''02'' & txtWord2 & ''00'' '第二幀文字,內容其實和第一幀一致
swWord = ''CMD01C'' & ''0a'' & ''00'' & ''00'' & ''00'' & ''0a'' & ''01'' & ''00'' & ''00'' & ''00'' '第一幀和第二幀全部切換到文字模式,和下一條指令一樣,這裡為了說明動作,故寫兩條。本例中假設幀號從“00”開始。
swPIC = ''CMD01C'' & ''0a'' & ''00'' & ''00'' & ''00'' & ''0a'' & ''01'' & ''00'' & ''00'' & ''00'' '第一幀和第二幀全部切換到圖片模式
'以下為效果指令,兩幀效果均一致,如需修改,可以根據協定修改部分效果,組合很多不同的效果,也可以根據規則添加幀及效果。
CtlWord1 = ''CMD01C'' & ''00'' & ''00'' & ''0a'' & ''05'' & ''00'' & ''01'' & ''0a'' & ''05'' & ''00'' '循環,速度設定為“0a”,停留時間設定為“05”,兩者均可以修改,下同。
CtlWord2 = ''CMD01C'' & ''01'' & ''00'' & ''0a'' & ''05'' & ''01'' & ''01'' & ''0a'' & ''05'' & ''00'' '上移,如果把後一個“01”改為“02”,則,第一幀上移,第二幀下移,即上下分開的效果。
CtlWord3 = ''CMD01C'' & ''02'' & ''00'' & ''0a'' & ''05'' & ''02'' & ''01'' & ''0a'' & ''05'' & ''00'' '下移
CtlWord4 = ''CMD01C'' & ''03'' & ''00'' & ''0a'' & ''05'' & ''03'' & ''01'' & ''0a'' & ''05'' & ''00'' '上覆蓋,同上道理,可以修改部分幀的效果來組合
CtlWord5 = ''CMD01C'' & ''04'' & ''00'' & ''0a'' & ''05'' & ''04'' & ''01'' & ''0a'' & ''05'' & ''00'' '下覆蓋
CtlWord6 = ''CMD01C'' & ''05'' & ''00'' & ''0a'' & ''05'' & ''05'' & ''01'' & ''0a'' & ''05'' & ''00'' '左移
CtlWord7 = ''CMD01C'' & ''06'' & ''00'' & ''0a'' & ''05'' & ''06'' & ''01'' & ''0a'' & ''05'' & ''00'' '右移
CtlWord8 = ''CMD01C'' & ''07'' & ''00'' & ''0a'' & ''05'' & ''07'' & ''01'' & ''0a'' & ''05'' & ''00'' '右覆蓋
CtlWord9 = ''CMD01C'' & ''08'' & ''00'' & ''0a'' & ''05'' & ''08'' & ''01'' & ''0a'' & ''05'' & ''00'' '左覆蓋
CtlWord10 = ''CMD01C'' & ''09'' & ''00'' & ''0a'' & ''05'' & ''09'' & ''01'' & ''0a'' & ''05'' & ''00'' '反白
CtlWord11 = ''CMD01C'' & ''0a'' & ''00'' & ''00'' & ''00'' & ''0a'' & ''01'' & ''00'' & ''00'' & ''00'' '圖文轉換,同swWord和swPIC。轉換時不考慮速度和停留時間
CtlWord12 = ''CMD01C'' & ''0b'' & ''00'' & ''0a'' & ''05'' & ''0b'' & ''01'' & ''0a'' & ''05'' & ''00'' '跑字
CtlWord13 = ''CMD01C'' & ''0c'' & ''00'' & ''0a'' & ''05'' & ''0c'' & ''01'' & ''0a'' & ''05'' & ''00'' '反向閃爍
CtlWord14 = ''CMD01C'' & ''0d'' & ''00'' & ''0a'' & ''05'' & ''0d'' & ''01'' & ''0a'' & ''05'' & ''00'' '時間
CtlWord15 = ''CMD01C'' & ''0e'' & ''00'' & ''00'' & ''00'' & ''0e'' & ''01'' & ''0a'' & ''00'' & ''00'' '清屏,清屏時不考慮速度和停留時間
CtlWord16 = ''CMD01C'' & ''0f'' & ''00'' & ''0a'' & ''05'' & ''0f'' & ''01'' & ''0a'' & ''05'' & ''00'' '閃爍

End Sub

Private Sub OpenCom Click
On Error GoTo ErrCode
ComInit '初始化串口參數
MSComm1.CommPort = ComNum '串口通道
MSComm1.Settings = ComBps & '','' & ComCheck & '','' & ComBITNum & '','' & ComStop '形如: ''9600,N,8,1''
MSComm1.PortOpen = True '打開串口
bComStates = True
'MsgBox ''打開串口成功
pnlX2.Text = ''串口打開
pnlX.Text = ''系統就緒
Exit Sub
ErrCode:
bComStates = False
'MsgBox Err.Description
'MsgBox ''打開串口失敗
pnlX2.Text = ''串口關閉
pnlX.Text = ''系統錯誤
End Sub
'-----------------------初始化串口------------------------
Public Sub ComInit
On Error GoTo ErrCode
ComNum = Combo1.ListIndex + 1
ComBps = Combo2.Text
ComBITNum = Combo3.ListIndex + 4
Select Case Combo4.ListIndex
Case 0
ComCheck = ''E'' '偶校驗
Case 1
ComCheck = ''O'' '奇校驗
Case 2
ComCheck = ''N'' '不校驗
Case 3
ComCheck = ''M'' '標誌校驗,固定為“1”
Case 4
ComCheck = ''S'' '空校驗,即為空
End Select
Select Case Combo5.ListIndex
Case 0
ComStop = ''1''
Case 1
ComStop = ''1'' '本來應該為1.5,但不知道怎么會出錯
Case 2
ComStop = ''2''
End Select
Exit Sub
ErrCode:
MsgBox Err.Description
End Sub
'-----------------------初始化串口------------------------
Private Sub Pquit Click
Unload Me
End Sub
Private Sub Psend Click
If bComStates = True Then
MSComm1.Output = txtSendWords '傳送數據
pnlX.Text = ''系統狀態:傳送數據成功
If bAutoRe.Value = 1 Then
Timer1.Enabled = True
End If
Else
MsgBox ''串口未打開
End If
End Sub
Private Sub Timer1 Timer
If bAutoRe.Value = 1 And bComStates = True Then
txtReceving.Text = MSComm1.Input '注意:接收數據與您設定的串口速度有關,速度慢時,請等待一段時間再接收,必要時,更改串口的其他參數,如緩衝區等。
Timer1.Enabled = False
End If
End Sub
Private Sub txtSend Change
txtSendWords = txtSend.Text
End Sub

相關詞條

熱門詞條

聯絡我們