PTP2000及其在不停車收費(fèi)系統(tǒng)中的應(yīng)用
5.2 PC機(jī)接收部分編程
本例中PC機(jī)接收部分通過(guò)對(duì)Visual Basic中的MSComm控件編程實(shí)現(xiàn)對(duì)計(jì)算機(jī)串口通訊的程序設(shè)計(jì)。
PC 串口的RTS經(jīng)電平轉(zhuǎn)換與PTR2000無(wú)線MODEM的TXEN相連。計(jì)算機(jī)要發(fā)送數(shù)據(jù)時(shí),RTS變?yōu)檫壿?有效,亦即PTR2000的Pin7 (TXEN)被置為1,此時(shí)可發(fā)送數(shù)據(jù);計(jì)算機(jī)接收數(shù)據(jù)時(shí),RTS變?yōu)檫壿?有效,亦即PTR2000的Pin7(TXEN)被置為0,此時(shí)可接收數(shù)據(jù)。
程序的設(shè)計(jì)窗體如圖5所示。
PC機(jī)接收部分程序介紹如下:
Option Explicit
Public ReceiveStr As String
Private Sub Form_Load()
MSComm2.CommPotr = 2
MSComm2.Settings = 9600,n,8,1
MSComm2.InBufferSize = 256
MSComm2.PotrOpen = True
MSComm2.Trhreshold = 1
End Sub
Private Sub MSComm2_OnComm ()
Select Case MSComm2.CommEvent
Case comEvReceive
ReceiveStr = ReceiveStr + MSComm2.Input
If InStr(ReceiveStr,##) > 0 Then
txtVIN.Text = Mid$(ReceiveStr, InStr(ReceiveStr,##)+2,10)
txtCarNO.Text = Mid$(ReceiveStr,InStr(ReceiveStr,##)+12,7)
txtCount.Text = Mid$(ReceiveStr,InStr(ReceiveStr,##)+19,12)
End If
End Select
End Sub
程序運(yùn)行結(jié)果如圖6所示。
評(píng)論