Bueno hasta ahora no pude hacerlo andar asi que pongo una explicación detallada de lo que se quiere:
1º - El programa es una ejemplo de los muchos de USB que he posteado pero con la diferencia que los parámetros como VID, PID, IN_BUFF, OUT_BUFF , se cargan mediante TexBox que están en el formulario.
2º - Las variables que se manejan son del tipo
short con lo cuál los datos que se le deben asignar a dichas variables tienen que tener el mismo tipo.
3º - Pongo las variables en cuestion.
Dim VendorID
As Short = &H1781 Acá está definido el ID del vendedor del producto USB.
Dim ProductID
As Short = &H7D0 Acá está definido el ID del producto USB.
Dim BufferInSize
As Short = 8 Acá está definido el tamaño del Buffer de entrada de datos.
Dim BufferOutSize
As Short = 8 Acá está definido el tamaño del Buffer de salida de datos.
4º - Las variables nombradas anteriormente están definidas con constantes, en mi programa se tienen que cargar desde los correspondientes TextBox que tienen asignados como muestra la siguiente figura:
5º - Luego de asignarle a cada TexBox un valor determinado pongo conectar dispositivo.
6º - Mi problema concretamente reside en como asignarle el valor del textBOX correspondiente a la variable que muestro en el punto 3.
7º - Hasta ahora los diferentes intentos que he hecho por asignarle los datos me han dado la siguiente ventana de error al ejecutar el programa:
Ahi es donde tengo el problema....no se como pasarle el valor a una variable del tipo
short cuando el Texbox entrega un valor del tipo
string
Ya he probado todas las formas que he encontrado en internet y las que me han proporcionado ustedes pero no he tenido exito.
Voy a seguir investigando
Les pongo el código del programa:
Código:
Public Class Form1
Dim VendorID As Short = &H1781
Dim ProductID As Short = &H7D0 'product and vendor IDs
' read and write buffers
Dim BufferInSize As Short = 1 'Size of the data buffer coming IN to the PC
Dim BufferOutSize As Short = 1 'Size of the data buffer going OUT from the PC
Dim BufferIn(BufferInSize) As Byte 'Received data will be stored here - the first byte in the array is unused
Dim BufferOut(BufferOutSize) As Byte 'Transmitted data is stored here - the first item in the array must be 0
' ****************************************************************
' when the form loads, connect to the HID controller - pass
' the form window handle so that you can receive notification
' events...
'*****************************************************************
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
USB_ESTADO.BackColor = Color.Blue
End Sub
'*****************************************************************
' disconnect from the HID controller...
'*****************************************************************
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
DisconnectFromHID()
End Sub
'*****************************************************************
' a HID device has been plugged in...
'*****************************************************************
Public Sub OnPlugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
USB_ESTADO.BackColor = Color.Green
End If
End Sub
'*****************************************************************
' a HID device has been unplugged...
'*****************************************************************
Public Sub OnUnplugged(ByVal pHandle As Integer)
If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
hidSetReadNotify(hidGetHandle(VendorID, ProductID), False)
USB_ESTADO.BackColor = Color.Red
End If
End Sub
'*****************************************************************
' controller changed notification - called
' after ALL HID devices are plugged or unplugged
'*****************************************************************
Public Sub OnChanged()
' get the handle of the device we are interested in, then set
' its read notify flag to true - this ensures you get a read
' notification message when there is some data to read...
Dim pHandle As Integer
pHandle = hidGetHandle(VendorID, ProductID)
hidSetReadNotify(hidGetHandle(VendorID, ProductID), True)
End Sub
'*****************************************************************
' on read event...
'*****************************************************************
Public Sub OnRead(ByVal pHandle As Integer)
' read the data (don't forget, pass the whole array)...
If hidRead(pHandle, BufferIn(0)) Then
' ** YOUR CODE HERE **
' first byte is the report ID, e.g. BufferIn(0)
' the other bytes are the data from the microcontroller...
End If
End Sub
Private Sub CONECTAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CONECTAR.Click
ConnectToHID(Me)
End Sub
End Class
Espero poder solucionarlo asi sigo con mis ejemplos sobre USB
Un saludo !