以下是用VB的程式寫的
Dim comx$
Dim keyin$
Dim SXD$
Dim RXD$
Private Sub Command1_Click()
keyin$ = InputBox$("輸入通訊命令(不必輸入SUM)", "輸入命令對話盒", "")
MsgBox keyin$
If keyin$ = "" Then GoTo null_keyin
STX$ = Chr$(2): ETX$ = Chr$(3)
'
T$ = keyin$ + ETX$
Sum$ = chksum(T$)
SXD$ = STX$ + T$ + Sum$
Text1.Text = "命令字串:" + SXD$
RXD$ = send_recieve(SXD$)
' Text2.Text = "回應字串:" + RXD$
'Text2.Text = "回應字串:" + Hex$(Asc(RXD$)) & "H" '在標籤上顯示回應字元
If CInt(comx$) = 0 Then
Text2.Text = "回應字串:" + RXD$
Else
Text2.Text = "回應字串:" + Hex$(Asc(RXD$)) & "H"
End If
null_keyin:
End Sub
Private Sub Command2_Click()
End
End Sub
Sub Option1_Click()
' 物件函數:致能通訊埠。
MSComm1.PortOpen = True
End Sub
Private Sub delay(delay_N%)
For i% = 1 To delay_N%
For j% = 1 To 90
xa! = 10 * Sin(10 * j% / 20)
Next j%
Next i%
End Sub
Private Function chksum$(T$)
L = Len(T$)
a = 0
For j = 1 To L
TJ$ = Mid$(T$, j, 1)
a = Asc(TJ$) + a
Next j
Sum$ = Hex$(a)
If Len(Sum$) = 1 Then Sum$ = "0" + Sum$
chksum$ = Right$(Sum$, 2)
End Function
Private Function resp_length%(SXD$)
'取得命令in/out
comx$ = Mid$(SXD$, 2, 1)
' 若是讀入命令,取得位元組數
' 讀入裝置狀態
If CInt(comx$) = 0 Then bytelenth% = CInt(Mid$(SXD$, 8, 1)): L% = bytelenth% * 2 + 4
' 寫出裝置狀態
If CInt(comx$) = 1 Then L% = 0
If CInt(comx$) = 7 Then L% = 0
If CInt(comx$) = 8 Then L% = 0
resp_length% = L%
End Function
Private Sub Form_Load()
Form1.Caption = "FX2之VB測試"
Command1.Caption = "輸入命令按鈕"
Option1.Caption = "開啟通訊埠"
Option2.Caption = "關閉通訊埠"
Label1.Caption = "命令字串:"
Label2.Caption = "回應字串:"
Text1.Text = "": Text2.Text = ""
MSComm1.CommPort = 1
MSComm1.Settings = "9600,e,7,1"
MSComm1.RTSEnable = True '請求要送資料
' 啟動通訊埠
Option1.Value = True
End Sub
Private Sub Option2_Click()
MSComm1.PortOpen = False
End Sub
Private Function send_recieve(SXD$)
MSComm1.Output = SXD$ ' 從通訊埠輸出命令字串。
Call delay(1000) ' 延時一些時間。
resp_len% = resp_length%(SXD$)
MSComm1.InputLen = resp_len%
RXD$ = MSComm1.Input ' 讀取回應字串。
send_recieve = RXD$
End Function
小弟怎麼作都做不出來
請問有沒有大大可以教我怎麼用LABVIEW作
拜託了!!!![](upload://bim7Kb3Zfl5SrPF2GFcCSDus3NW.gif)