CH341

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

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 ' 當(dāng)前包提前結(jié)束 mLength = 10 mInLen = 0

If (CH341.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 End Sub 這個VB.NET程序運行時就卡死,哪位仁兄幫忙分析一下!謝謝

請參考下面的代碼: BOOL WINAPI IIC_OutByteCheckAck( // 輸出一字節(jié)數(shù)據(jù)并檢查應(yīng)答是否有效 ULONG iIndex, // 指定CH341設(shè)備序號 UCHAR iOutByte ) // 準(zhǔn)備寫出的數(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; // 當(dāng)前包提前結(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 ); }


BOOL WINAPI COtherPage::IIC_WRITEBYTE(ULONG iIndex, UCHAR DevAddr,UCHAR DataAddr,UCHAR Data) { UCHAR mBuffer[ mCH341_PACKET_LENGTH ]; ULONG mLength, mInLen; 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 ] = DevAddr; // 數(shù)據(jù)

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

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

mBuffer[ 8 ] =mCH341A_CMD_I2C_STM_STO; mBuffer[ 9 ] = mCH341A_CMD_I2C_STM_END; // 當(dāng)前包提前結(jié)束 mLength = 10; //mInLen = 0; if ( CH341WriteRead( iIndex, mLength, mBuffer, 32, 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 ); } 這段代碼才是真正的進(jìn)行單字節(jié)寫入EEPROM并有起始位,停止位,檢測ACK信號的代碼, 而且我問的又不是在VC環(huán)境中運行,在VC中我運行通過了,現(xiàn)在想在VB中運行,但是把這段代碼移植過去,程序總是卡死掉,運行不下去,求解! 就是想問一下CH341WriteRead這個函數(shù)在VB中如何設(shè)置 CH341WriteRead( iIndex, mLength, mBuffer, mCH341A_CMD_I2C_STM_MAX, 1, &mInLen, mBuffer )里面的參數(shù)問題,謝謝!


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

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