CH341

Dim mBuffer(mCH341_PACKET_LENGTH) As Byte Dim mLength As UInteger Dim mInLen As UInteger mBuffer(0) = mCH341A_CMD_I2C_STREAM ' 命令碼 mBuffer(1) = mCH341A_CMD_I2C_STM_STA mBuffer(2) = mCH341A_CMD_I2C_STM_OUT ' 輸出數(shù)據(jù),位5-位0為長度,0長度則只發(fā)送一個字節(jié)并返回應(yīng)答 mBuffer(3) = &HA0 ' 數(shù)據(jù)

mBuffer(4) = mCH341A_CMD_I2C_STM_OUT ' 輸出數(shù)據(jù),位5-位0為長度,0長度則只發(fā)送一個字節(jié)并返回應(yīng)答 mBuffer(5) = &H0 ' 數(shù)據(jù)

mBuffer(6) = mCH341A_CMD_I2C_STM_OUT ' 輸出數(shù)據(jù),位5-位0為長度,0長度則只發(fā)送一個字節(jié)并返回應(yīng)答 mBuffer(7) = &H55 ' 數(shù)據(jù)

mBuffer(8) = mCH341A_CMD_I2C_STM_STO mBuffer(9) = mCH341A_CMD_I2C_STM_END ' 當前包提前結(jié)束 mLength = 10 mInLen = 0

If (CH341WriteRead(0, mLength, mBuffer(9), mCH341A_CMD_I2C_STM_MAX, 1, mInLen, mBuffer(9)) = True) Then ' 執(zhí)行數(shù)據(jù)流命令,先輸出再輸入 MsgBox("寫數(shù)據(jù)成功!", vbExclamation, "CH341") End If 為什么運行這個程序就卡死?麻煩哪位仁兄幫忙分析一下CH341WriteRead的用法!

Dim mBuffer(mCH341_PACKET_LENGTH) As Byte Dim mLength As UInteger Dim mInLen As UInteger mBuffer(0) = mCH341A_CMD_I2C_STREAM ' 命令碼 mBuffer(1) = mCH341A_CMD_I2C_STM_STA mBuffer(2) = mCH341A_CMD_I2C_STM_OUT ' 輸出數(shù)據(jù),位5-位0為長度,0長度則只發(fā)送一個字節(jié)并返回應(yīng)答 mBuffer(3) = &HA0 ' 數(shù)據(jù)

mBuffer(4) = mCH341A_CMD_I2C_STM_OUT ' 輸出數(shù)據(jù),位5-位0為長度,0長度則只發(fā)送一個字節(jié)并返回應(yīng)答 mBuffer(5) = &H0 ' 數(shù)據(jù)

mBuffer(6) = mCH341A_CMD_I2C_STM_OUT ' 輸出數(shù)據(jù),位5-位0為長度,0長度則只發(fā)送一個字節(jié)并返回應(yīng)答 mBuffer(7) = &H55 ' 數(shù)據(jù)

mBuffer(8) = mCH341A_CMD_I2C_STM_STO mBuffer(9) = mCH341A_CMD_I2C_STM_END ' 當前包提前結(jié)束 mLength = 10 mInLen = 0

If (CH341WriteRead(0, mLength, mBuffer(10), mCH341A_CMD_I2C_STM_MAX, 1, mInLen, mBuffer(10)) = True) Then ' 執(zhí)行數(shù)據(jù)流命令,先輸出再輸入 MsgBox("寫數(shù)據(jù)成功!", vbExclamation, "CH341") End If 為什么運行這個VB程序就卡死?麻煩哪位仁兄幫忙分析一下CH341WriteRead的用法!


VB編程直接調(diào)用串口控件實現(xiàn)RS-232到USB轉(zhuǎn)換收發(fā)數(shù)據(jù)。為什么要象上述編程?有什么特別考慮和優(yōu)點嗎?以最簡單的方法達到目的不是更好嗎?


其實是CH341USB_I2C如果直接調(diào)用CH341.DLL中的ch341writei2c跟ch341readi2c這兩個函數(shù),其實是沒檢測ACK信號的,所以他們公司給了我一大段代碼,我最后整理成上面那樣在VC里可以實現(xiàn)檢測ACK信號了,但現(xiàn)在要轉(zhuǎn)到VB環(huán)境中去實現(xiàn),發(fā)現(xiàn)運行時卡死,我不知道 CH341WriteRead(0, mLength, mBuffer(10),mCH341A_CMD_I2C_STM_MAX, 1, mInLen, mBuffer(10)) 這個函數(shù)在VB里怎么給各個變量賦值


CH341除了usb轉(zhuǎn)異步串口功能之外還有usb轉(zhuǎn)i2c,spi,mem,epp等功能。 請參考下面的代碼: BOOL WINAPI IIC_OutByteCheckAck( // 輸出一字節(jié)數(shù)據(jù)并檢查應(yīng)答是否有效 ULONG iIndex, // 指定CH341設(shè)備序號 UCHAR iOutByte ) // 準備寫出的數(shù)據(jù) { UCHAR mBuffer[ mCH341_PACKET_LENGTH ]; ULONG mLength, mInLen; mBuffer[ 0 ] = mCH341A_CMD_I2C_STREAM; // 命令碼 mBuffer[ 1 ] = mCH341A_CMD_I2C_STM_OUT; // 輸出數(shù)據(jù),位5-位0為長度,0長度則只發(fā)送一個字節(jié)并返回應(yīng)答 mBuffer[ 2 ] = iOutByte; // 數(shù)據(jù) mBuffer[ 3 ] = mCH341A_CMD_I2C_STM_END; // 當前包提前結(jié)束 mLength = 4; mInLen = 0; if ( CH341WriteRead( iIndex, mLength, mBuffer, mCH341A_CMD_I2C_STM_MAX, 1, &mInLen, mBuffer ) ) { // 執(zhí)行數(shù)據(jù)流命令,先輸出再輸入 if ( mInLen && ( mBuffer[ mInLen - 1 ] & 0x80 ) == 0 ) return( TRUE ); // 返回的數(shù)據(jù)的位7代表ACK應(yīng)答位,ACK=0有效 } return( FALSE ); }


在VB中我用過函數(shù)CH341StreamI2C(mIndex, 2, buffer, 0, iBuff)成功,但是用CH341WriteRead就卡死,不知里面具體參數(shù)怎么設(shè)置,也不知道這個函數(shù)支不支持在VB中調(diào)用,求解!VB!VB!VB!VB!VB!VB!


與CH341WriteRead無關(guān),CH341StreamI2C函數(shù)也調(diào)用了CH341WriteRead


Type mBuf mBuff(mCH341_PACKET_LENGTH) As Byte End Type

Function IIC_OutByteCheckAck(ByVal iIndex As Long,ByVal iOutByte As Byte) As Boolean Dim mBuffer As mBuf Dim mLength, mInLen mBuffer.mBuff(0) = mCH341A_CMD_I2C_STREAM mBuffer.mBuff(1) = mCH341A_CMD_I2C_STM_OUT mBuffer.mBuff(2) = iOutByte mBuffer.mBuff(3) = mCH341A_CMD_I2C_STM_END mLength = 4 mInLen = 0 If (CH341WriteRead( iIndex, mLength, mBuffer, mCH341A_CMD_I2C_STM_MAX, 1, mInLen, mBuffer )) Then If ( mInLen <>0 and (mBuffer.mBuff(mInLen-1) And &H80) = 0 ) Then IIC_OutByteCheckAck = True Exit Function End If End If IIC_OutByteCheckAck = FALSE End Function If ( mInLen <>0 and (mBuffer.mBuff(mInLen-1) And &H80) = 0 ) Then 這句可能寫的有點問題,沒測試


Type mBuf mBuff(mCH341_PACKET_LENGTH) As Byte End Type‘我在類中定義的

Private Sub Command2_Click()’按鈕事件

Dim mBuffer As mBuf Dim mLength, mInLen As Long mBuffer.mBuff(0) = mCH341A_CMD_I2C_STREAM mBuffer.mBuff(1) = mCH341A_CMD_I2C_STM_OUT mBuffer.mBuff(2) = 20 mBuffer.mBuff(3) = mCH341A_CMD_I2C_STM_END mLength = 4 mInLen = 0

If (mOpen = True) Then If (CH341WriteRead(0, mLength, mBuffer, 32, 1, mInLen, mBuffer)) Then‘iIndex=0, ’mCH341A_CMD_I2C_STM_MAX=32 MsgBox "寫數(shù)據(jù)成功!", vbExclamation, "CH341" Else: MsgBox "寫數(shù)據(jù)失?。?, vbExclamation, "CH341" End If Else MsgBox "設(shè)備未打開!", vbExclamation, "CH341PAR" End If

End Sub

程序還是卡死掉,什么原因呢?


CH341WriteRead函數(shù)是怎么聲明的?


Declare Function CH341WriteRead Lib "CH341DLL.DLL" (ByVal iIndex As Long, ByVal iWriteLength As Long, ByRef iWriteBuffer As Any, ByVal iReadStep As Long, ByVal iReadTimes As Long, ByRef oReadLength As Long, ByRef oReadBuffer As Any) As Boolean ' CH341WriteRead 執(zhí)行數(shù)據(jù)流命令,先輸出再輸入 ' iIndex, 指定CH341設(shè)備序號 ' iWriteLength, 寫長度,準備寫出的長度 ' iWriteBuffer, 指向一個緩沖區(qū),放置準備寫出的數(shù)據(jù) ' iReadStep, 準備讀取的單個塊的長度, 準備讀取的總長度為(iReadStep*iReadTimes) ' iReadTimes, 準備讀取的次數(shù) ' oReadLength, 指向長度單元,返回后為實際讀取的長度 ' oReadBuffer 指向一個足夠大的緩沖區(qū),用于保存讀取的數(shù)據(jù)


各位WCH的高手們,趕緊幫幫忙吧,在VB中如何實現(xiàn)CH341WriteRead這個函數(shù),在VC中可以實現(xiàn)但轉(zhuǎn)到VB中程序就卡死掉,zyw { M } 給了一個VB的程序,但還是卡死掉,求助!謝謝


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频