我使用VB程序做CH372的上位機(jī)
下位機(jī)已經(jīng)由同事自己編寫一個(gè)小程序,用調(diào)試小工具可以使用,從端口1發(fā)送一個(gè)字節(jié)數(shù)據(jù)下去,從端口2接受五個(gè)字節(jié)上來
我下載了CH372EVT的程序,里面關(guān)于端口 沒有進(jìn)行選擇,我直接調(diào)用端口CH375WriteData讀寫函數(shù) 執(zhí)行完寫返回ture,到讀命令CH375ReadData就死了
這個(gè)端口需要自己另外去設(shè)置嗎
Private Sub Command1_Click()
??? mIndex = 0? '第一個(gè)ch375設(shè)備
??? mShowLED = 0
??? mKeyCode = &HFF
??? mCaptionInform = " 信息提示 "
??? mOpen = -1
???
??? mOpen = CH375OpenDevice(mIndex)????????????????? '窗體加載時(shí)打開設(shè)備
??? If mOpen = -1 Then
??????? Call pnpproce_KeyUp(CH375_DEVICE_REMOVE, 0)? '作設(shè)備拔出處理
??????? Exit Sub
??? Else
??????? Call pnpproce_KeyUp(CH375_DEVICE_ARRIVAL, 0) '作設(shè)備插入處理
??? End If
???
??? ' 設(shè)置USB數(shù)據(jù)讀寫的超時(shí),超過3000mS未完成讀寫將強(qiáng)制返回,避免一直等待下去
??? CH375SetTimeout mIndex, 3000, 3000
??? mDemoReq.mCommandCode = DEF_CMD_TEST_DATA??? ' 測(cè)試命令,將PC機(jī)發(fā)來的所有數(shù)據(jù)取反后返回
??? mDemoReq.mCommandCodeNot = &HFF - DEF_CMD_TEST_DATA
??? mDemoReq.mParameter(0) = &H29? ' 任意的測(cè)試數(shù)據(jù),返回后將按位取反
??? mLength = 1??? ' 命令包的長(zhǎng)度
??? If (CH375Writedata(mIndex, mDemoReq, mLength)) Then?????? ' 通過CH375發(fā)送命令數(shù)據(jù),成功
??????? mLength = 5
??????? If (CH375ReadData(mIndex, mDemoReq, mLength)) Then??????? ' 通過CH375接收應(yīng)答數(shù)據(jù),成功
??????????? If (mLength = CONST_CMD_LEN) Then
??????????????? If ((mDemoReq.mCommandCode <> (&HFF - DEF_CMD_TEST_DATA)) Or (mDemoReq.mParameter(0) <> (&HFF - &H5A)) Or (mDemoReq.mParameter(1) <> (&HFF - &H96))) Then
??????????????????? MsgBox "通過USB傳輸?shù)臄?shù)據(jù)有錯(cuò)誤", vbExclamation, mCaptionInform
??????????????? End If
??????????? Else
??????????????? MsgBox "CH375數(shù)據(jù)測(cè)試返回的長(zhǎng)度錯(cuò)誤", vbExclamation, mCaptionInform
??????????? End If
?????????????????
??????? Else
??????????? MsgBox "CH375ReadData 失敗", vbExclamation, mCaptionInform
??????? End If
??? Else
??????? MsgBox "CH375WriteData 失敗", vbExclamation, mCaptionInform
??? End If
???
End Sub