Week15:interface and application programming

Previous weekAssciment listNext week

Preparation

input


build my own GUI window to display the message

Private Sub Command1_Click()

MSComm1.Output = Text2.Text + Chr$(13) + Chr$(10)

End Sub

Private Sub Command2_Click()
Label1.Caption = ""
End Sub

Private Sub Form_Load()
 '設定comport的位置
 MSComm1.CommPort = Val(Text1.Text)

 '檢查一下Com1是否被使用了,若被使用了,把Com1關閉並重設.
 If (MSComm1.PortOpen) Then MSComm1.PortOpen = False

 '設定comport的讀取速率,注意RS232傳送速率,有的是9600,有的是1200,看你的Device而定
 MSComm1.Settings = "9600,N,8,1"

 '設定DTR線路為高電位
 MSComm1.DTREnable = True

 '設定讀取的長度
 MSComm1.InputLen = 30

 '當緩衝區有33bytes則觸發事件
 MSComm1.RThreshold = 1

 '交握模式設定
 MSComm1.Handshaking = MSCOMMLIB.HandshakeConstants.comNone

 '資料格式,走10byte,text模式
 MSComm1.InputMode = MSCOMMLIB.InputModeConstants.comInputModeText
 
 'null一樣照收
 MSComm1.NullDiscard = False

 '打開comport 1
 MSComm1.PortOpen = True

 MSComm1.RTSEnable = True
 
End Sub

Private Sub MSComm1_OnComm()

Dim TempStr As String

If MSComm1.CommEvent = comEvReceive Then

TempStr = MSComm1.Input

Label1.Caption = Label1.Caption + TempStr
    
End If

End Sub

Private Sub Text1_Change()

MSComm1.PortOpen = False

MSComm1.CommPort = Val(Text1.Text)
 
MSComm1.PortOpen = True

End Sub

About meassignmentAbout Final Project

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.