OpenDevice function

kaveh rahimi 61 Reputation points
2021-06-26T17:23:58.487+00:00

Hi ,here is my code:
Private Declare Function CH341OpenDevice Lib "CH341DLL.DLL" (ByVal iIndex As Int64) As Integer
Private Declare Function CH341WriteI2C Lib "CH341DLL.DLL" (ByVal iIndex As Int64, ByVal idevice As Integer, ByVal iaddr As Integer, ByVal ibyte As Integer) As UInteger
Private Declare Function CH341ReadI2C Lib "CH341DLL.DLL" (ByVal iIndex As Int64, ByVal idevice As Integer, ByVal iaddr As Integer, ByVal obyte As Integer) As Integer
Private Declare Function CH341CloseDevice Lib "CH341DLL.DLL" (ByVal iIndex As Int64) As Integer
Private Declare Function CH341ResetDevice Lib "CH341DLL.DLL" (ByVal iIndex As Int64) As Integer
Private Declare Function CH341SetStream Lib "CH341DLL.DLL" (iIndex As Int64, iMode As Long) As Integer
Sub main()
MsgBox("ok")
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim iIndex As Long = 0
    Dim iDevice As ULong = &H48
    Dim iAddr As ULong = &H48
    Dim iByte As UInteger = &H91
    Dim closing As Integer
    Dim reading As Integer
    Dim opning As Integer = CH341OpenDevice(iIndex)
    Dim rseting As Integer = CH341ResetDevice(iIndex)
    Dim wrting As UInteger = CH341WriteI2C(iIndex, iDevice, iAddr, iByte)
    'reading = CH341ReadI2C(iIndex, 48, 91, 91)
    closing = CH341CloseDevice(0)
    MsgBox(opning)
    MsgBox(wrting)
    MsgBox(closing)
    MsgBox(iAddr)
End Sub

End Class
When I run the code the opning value is negative in this condition there is an error. The value of wrting must be also 91H which is in the code mentioned but '0' is displaid. Please help.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
0 comments No comments
{count} votes