Follow along with the video below to see how to install our site as a web app on your home screen.
Nota: This feature currently requires accessing the site using the built-in Safari browser.
Te dejo la aplicación para HID, luego les subo el manual dentro de unas semanas.
Bueno, me gano de mano Jonathan
Les comento que logre hacer un encapsulado de todo lo que es HID en una clase de vb.net. Apenas me haga un tiempo la hago prolija y la subo.
#Region "Recepcion de Datos"
'Al recibir los Datos
Private Sub Recepcion(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
'Acumula los datos recibidos en nuestro 'buffer' (integer)
'If cerrar = 0 Then
For i = 0 To cant
recibidos(i) = SerialPort1.ReadByte
Next
'End If
If recibidos(0) = &HFF Then
If recibidos(1) = &H32 Then
Me.BackgroundImage = System.Drawing.Image.FromFile("on_pant.jpg")
band1 = 1
End If
If recibidos(1) = &H33 Then
If CheckBox1.Checked = True Then
MsgBox("No Se Puede Apagar el Equipo, Se Esta Guardando la Base de Datos", MsgBoxStyle.Exclamation, "Base de Datos")
SerialPort1.Write(2)
Else
Me.BackgroundImage = System.Drawing.Image.FromFile("off_pant.jpg")
band1 = 0
End If
End If
If recibidos(1) = &H36 Then
MsgBox("Desconecte USB o La Bateria, El Equipo Puede Sufrir Daños", MsgBoxStyle.Exclamation, "Error Posible Daño")
Me.BackgroundImage = System.Drawing.Image.FromFile("off_pant.jpg")
band1 = 0
End If
If recibidos(1) = &H37 Then
esc = 1
'escala.Text = "R 10000"
End If
If recibidos(1) = &H38 Then
esc = 2
'escala.Text = " R 1000"
End If
If recibidos(1) = &H39 Then
esc = 3
'escala.Text = " R 100"
End If
If recibidos(1) = &H40 Then
esc = 4
'escala.Text = " R 100"
End If
End If
End Sub
#End Region
hola seaarg
esta es la parte de envio en el pic
outbuffer[0]=0x0f;
outbuffer[1]=0x0f;
outbuffer[2]=0x0f;
usb_put_packet(1, outbuffer, 3, USB_DTS_TOGGLE);
habiendo definido en el pic
#DEFINE USB_HID_DEVICE TRUE //Tells the CCS PIC USB firmware to include HID handling code.
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 3 //Numero de byte de envio (maximo 64 bytes)
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 1 //Numero de byte de Recepcion (maximo 64 bytes)
y en vb
oHID = New HIDWrapper(Me, &H4D8, &HA, 1, 3)
Bueno, te podria decir un par de lugares donde buscar.
Lo importante es que parece que definiste bien los tamaños de buffer
1)- Verificaste que el VendorID y el ProductID correspondan exactamente a los mismos que declaras en ccs?
2)- Definiste el objeto oHID con eventos (withevents), proba poner un msgbox en el evento onplugged a ver si detecta la conexion.
3)- para que el programa del pic envie datos se requiere alguna condicion especial que quiza no se este cumpliendo?
Tambien, depende de donde en tu programa vb.net creas el objeto oHID, deberias tener conectado el pic antes de ejecutar el programa. Para simplificar, ese objeto se intenta conectar al pic en el momento de su creacion.
Ej.: En mi caso lo instancio en el form_load. Esto hace que se necesite tener el pic primero conectado. En otros ejemplos de moyano, el tenia un boton "Conectar" para poder conectarse despues.
Revisa eso y comentanos. Podrias enviar el programa completo de vb.net? (la parte de comunicacion claro)
PD: No creo que tenga mucho que ver la version de .net, ya que en realidad lo que usa es la libreria mcHID.dll
Imports System.IO.Ports
Imports System.IO
Public Class Form4
Dim WithEvents oHID As HIDWrapper
#Region "Variables"
Dim recibidos As Integer() = New Integer(3) {}
Dim values As Double = 0
'Dim band As Integer = 0
Dim band1 As Integer = 0
'Dim conection As Integer = 0
Dim conect As Integer = 0
Dim Bd As Integer = 0
Public fic As String
Dim rut1 As String
Dim name1 As String
Dim resul As Integer = 5
Dim cant As Integer = 2
Dim valueslux As Double
'Dim cerrar As Integer = 0
Dim esc As Integer = 1
Dim outBuffer(0) As Byte
Dim PORTS As String() = IO.Ports.SerialPort.GetPortNames()
#End Region
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
oHID = New HIDWrapper(Me, &H4D8, &HA, 1, 3)
End Sub
#Region "Recepcion de Datos"
'Al recibir los Datos
Private Sub oHID_onRead(ByVal readedBytes() As Byte) Handles oHID.onRead
Dim i As Integer
For i = 0 To UBound(readedBytes)
recibidos(i) = readedBytes(i)
Next
If recibidos(0) = &HFF Then
If recibidos(1) = &H32 Then
Me.BackgroundImage = System.Drawing.Image.FromFile("on_pant.jpg")
band1 = 1
End If
If recibidos(1) = &H33 Then
If CheckBox1.Checked = True Then
MsgBox("No Se Puede Apagar el Equipo, Se Esta Guardando la Base de Datos", MsgBoxStyle.Exclamation, "Base de Datos")
outBuffer(0) = &H32
oHID.writeBuffer(outBuffer)
Else
Me.BackgroundImage = System.Drawing.Image.FromFile("off_pant.jpg")
band1 = 0
End If
End If
If recibidos(1) = &H36 Then
MsgBox("Desconecte USB o La Bateria, El Equipo Puede Sufrir Daños", MsgBoxStyle.Exclamation, "Error Posible Daño")
Me.BackgroundImage = System.Drawing.Image.FromFile("off_pant.jpg")
band1 = 0
End If
If recibidos(1) = &H37 Then
esc = 1
'escala.Text = "R 10000"
End If
If recibidos(1) = &H38 Then
esc = 2
'escala.Text = " R 1000"
End If
If recibidos(1) = &H39 Then
esc = 3
'escala.Text = " R 100"
End If
If recibidos(1) = &H40 Then
esc = 4
'escala.Text = " R 100"
End If
End If
End Sub
#End Region
#Region "Proceso de Inspeccion"
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' If band = 1 Then
' If band1 = 1 Then
If esc = 1 Then
escala.Text = "R 10000"
lxlb.Text = "lux"
FRG.Text = ""
End If
If esc = 2 Then
escala.Text = " R 1000"
lxlb.Text = "lux"
FRG.Text = ""
End If
If esc = 3 Then
escala.Text = " R 100"
lxlb.Text = "lux"
FRG.Text = ""
End If
outBuffer(0) = &H31
oHID.writeBuffer(outBuffer)
System.Threading.Thread.Sleep(50)
If recibidos(0) = &HFF Then
Else
temp.Text = " Temp: " & recibidos(0) & " °C"
values = (recibidos(2) * &H100) + recibidos(1)
If esc = 1 Then
valueslux = (10.163 * values) + 10
values = Int(valueslux)
End If
If esc = 2 Then
valueslux = (1.0071 * values) + 10
values = Int(valueslux)
End If
If esc = 3 Then
valueslux = (0.0916 * values) + 10
values = Int(valueslux)
End If
End If
If esc = 1 Or esc = 2 Or esc = 3 Then
If values < 10 Then
lux.Text = " " & values
ElseIf values < 100 Then
lux.Text = " " & values
ElseIf values < 1000 Then
lux.Text = " " & values
ElseIf values < 10000 Then
lux.Text = " " & values
ElseIf values < 100000 Then
lux.Text = values
ElseIf values < 200000 Then
lux.Text = values
End If
Else
lxlb.Text = ""
lux.Text = ""
FRG.Text = "FUERA DE RANGO"
End If
' End If
' End If
End Sub
#End Region
#Region "Boton On/Off"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If conect = 1 Then
If band1 = 0 Then
outBuffer(0) = &H32
oHID.writeBuffer(outBuffer)
Me.BackgroundImage = System.Drawing.Image.FromFile("on_pant.jpg")
Timer1.Enabled = True
band1 = 1
lxlb.Text = "lux"
If esc = 1 Then
escala.Text = "R 10000"
End If
If esc = 2 Then
escala.Text = " R 1000"
End If
If esc = 3 Then
escala.Text = " R 100"
End If
Else
If CheckBox1.Checked = True Then
Beep()
Beep()
MsgBox("No Se Puede Apagar el Equipo, Se Esta Guardando la Base de Datos", MsgBoxStyle.Exclamation, "Base de Datos")
Else
outBuffer(0) = &H33
oHID.writeBuffer(outBuffer)
Me.BackgroundImage = System.Drawing.Image.FromFile("off_pant.jpg")
band1 = 0
Timer1.Enabled = False
escala.Text = ""
temp.Text = " Temp: -- °C"
lxlb.Text = ""
lux.Text = " --"
FRG.Text = ""
End If
End If
End If
End Sub
#End Region
#Region "Reloj"
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
StatusStrip1.Items(0).Text = DateTime.Now.ToLongTimeString()
End Sub
#End Region
#Region "Opacidad"
Private Sub NormalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NormalToolStripMenuItem.Click
Opacity = 1
End Sub
Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click
Opacity = 0.75
End Sub
Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click
Opacity = 0.5
End Sub
Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click
Opacity = 0.25
End Sub
Private Sub ToolStripMenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem6.Click
Opacity = 0.05
End Sub
#End Region
#Region "Dispositivio Conectado"
Private Sub oHID_onPlugged() Handles oHID.onPlugged
ON_USB.Text = "CONECTADO"
USB.BackColor = Color.Green
'band = 1
conect = 1
cant = 2
'cerrar = 0
End Sub
#End Region
#Region "Dispositivio Desconectado"
Private Sub oHID_onUnplugged() Handles oHID.onUnplugged
CheckBox1.Checked = False
If band1 = 1 Then
MsgBox("Se Recomienda Apagar el Equipo Antes de Desconectarlo, De lo Contrario El Equipo podra sufrir Danos", MsgBoxStyle.Exclamation, "Desconexion")
End If
band1 = 0
conect = 0
ON_USB.Text = "DESCONECTADO"
USB.BackColor = Color.Red
Me.BackgroundImage = System.Drawing.Image.FromFile("off_pant.jpg")
End Sub
#End Region
#Region "Base de Datos"
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
If band1 = 1 Then
Dim rut As String = System.AppDomain.CurrentDomain.BaseDirectory()
outBuffer(0) = &H36
oHID.writeBuffer(outBuffer)
MsgBox("Inicio de Inspeccion en Base de Datos", MsgBoxStyle.OkOnly, "Base de Datos")
With SaveFileDialog1
.Title = "Guardar Base de Datos"
.Filter = "Archivos txt|*.txt"
.OverwritePrompt = True
If .ShowDialog = Windows.Forms.DialogResult.OK Then
Me.RichTextBox1.SaveFile(.FileName)
End If
End With
Dim resul As String = InputBox("Digite Por Favor El Tiempo Entre Muestras (min), si Descarta Este Mensaje, El Valor Sera de 5 min", "Tiempo de Muestreo")
If resul = "" Then
resul = 5
End If
Timer3.Interval = resul * 1000
name1 = System.IO.Path.GetFileName(SaveFileDialog1.FileName)
rut1 = System.Environment.CurrentDirectory()
System.Environment.CurrentDirectory = rut
'Const fic As String
fic = rut1 & "\" & name1
'Dim texto As String = "Pablito tenía una moto con un pito."
Dim sw As New System.IO.StreamWriter(fic, True)
sw.WriteLine("Inspeccion de Luminarias, Muestreo Cada " & resul & " min")
sw.WriteLine(" ")
sw.WriteLine("Hora de Inicio: " & DateTime.Now.ToLongTimeString())
sw.WriteLine(" ")
sw.WriteLine(" ")
sw.Close()
Timer3.Enabled = True
Else
CheckBox1.Checked = False
MsgBox("El Equipo esta Apagado", MsgBoxStyle.Exclamation, "Base de Datos")
End If
Else
If band1 = 1 Then
outBuffer(0) = &H37
oHID.writeBuffer(outBuffer)
MsgBox("Terminacion De Inspeccion en Base de Datos", MsgBoxStyle.OkOnly, "Base de Datos")
'Const fic As String
fic = rut1 & "\" & name1
Dim sw As New System.IO.StreamWriter(fic, True)
sw.WriteLine(" ")
sw.WriteLine("Hora de Terminacion: " & DateTime.Now.ToLongTimeString())
sw.WriteLine(" ")
sw.Close()
Timer3.Enabled = False
End If
End If
End Sub
#End Region
#Region "Base de Tiempo Para Muestreo"
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Bd = Bd + 1
'Const fic As String
fic = rut1 & "\" & name1
'Dim texto As String = "Pablito tenía una moto con un pito."
Dim sw As New System.IO.StreamWriter(fic, True)
sw.WriteLine("Muestra #" & Bd & ", Hora de Evento: " & DateTime.Now.ToLongTimeString())
sw.WriteLine(" ")
sw.WriteLine("Temperatura: " & recibidos(0) & "ºC Intensidad Luminica por Metro Cuadrado: " & values & " lux")
sw.WriteLine(" ")
sw.Close()
End Sub
#End Region
#Region "Al Salir"
Private Sub Form4_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Timer1.Enabled = False
cant = 0
outBuffer(0) = &H35
oHID.writeBuffer(outBuffer)
End Sub
#End Region
#Region "Abrir Archivo de Base de Datos"
Private Sub AbrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbrirToolStripMenuItem.Click
Dim myStream As Stream = Nothing
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "Archivos txt (*.txt)|*.txt"
openFileDialog1.FilterIndex = 1
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
myStream = openFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
Process.Start(openFileDialog1.FileName)
End If
Catch Ex As Exception
MessageBox.Show("No se pudo leer el archivo: Se genero un Error " & Ex.Message)
Finally
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Try
End If
End Sub
#End Region
End Class