USB CDC VB.NET

#2
Gracias GVZ, sobre todo por el libro, que en su momento lo busque pero no encontré, y bueno la explicación es mas que clara al menos para mi, Saludos
 

gvz

Bovino adicto
#5
En realidad ese es un resumen de el pdf de USB 2.0 que igual viene adjuntn, solo que la verdad el libro si es mas digerible, y menos tecnico, y de nada, que bueno que le sirva a alguien, subire el enlace usb pero con la mpusbapi si veo que el tema les interesa
 
#8
De nada, para eso estan los cuates jaja
Hola gvz, y aprovechando un poco de tu amabilidad. ¿tendrás por ahí una aplicación muy sencilla para entrarle a la comunicación HID en css? ya que la comunicación CDC, ya logre cosas, pero creo es mas interesante entrarle al HID de lleno, por la vesatilidad que le veo.

Con un ejemplito que solo mande y reciba un byte, me es suficiente. Mucho te lo agradecer si me puedes auxiliar.

ya compile y grabe el ejemplo que viene en el ccs al respecto....
Código:
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
////                        ex_usb_hid.c                             ////
////                                                                 ////
//// A simple demo that shows how to use the HID class to send       ////
//// and receive custom data from the PC.  Normally HID is used      ////
//// with pre-defined classes, such as mice and keyboards, but       ////
//// can be used for vendor specific classes as shown in this        ////
//// example.                                                        ////
////                                                                 ////
//// The first byte sent by the PIC is the ADC reading               ////
//// on channel 0 (AN0), the second byte is the status of the        ////
//// pushbutton.  The two bytes sent by the PC are LED on/off        ////
//// toggle status.                                                  ////
////                                                                 ////
//// CCS has provided an example Windows program that reads / writes ////
//// to the HID device provided in this example.  This Windows       ////
//// example is called hiddemo.exe.                                  ////
////                                                                 ////
//// Normally this program sends and receives 2 bytes.  These        ////
//// sizes can be changed with USB_CONFIG_HID_TX_SIZE and            ////
//// USB_CONFIG_HID_RX_SIZE.  Changing these values will cause       ////
//// hiddemo.exe to not work.                                        ////
////                                                                 ////
//// This file is part of CCS's PIC USB driver code.  See USB.H      ////
//// for more documentation and a list of examples.                  ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
//// ABOUT HID:                                                      ////
////                                                                 ////
//// HID devices are useful because HID drivers are generally        ////
//// installed and supplied with modern operating systems.           ////
//// However, since HID is a general device with general drivers     ////
//// there are limitations to what a HID device can do:              ////
////                                                                 ////
//// - A report (message) can't be larger than 255 bytes.            ////
////  (A report or message != A packet)                              ////
////                                                                 ////
//// - On slow speed devices the max packet size is 8.               ////
////   On a full speed device the max packet size is 64.             ////
////                                                                 ////
//// - Data is obtained on the host / PC through polling the HID     ////
////   device (PC polls the PIC)                                     ////
////                                                                 ////
//// - On a full speed device, max polling rate is 1 transaction     ////
////   per 1ms. This is 64000 bytes per second (64 byte packets      ////
////   every 1ms).                                                   ////
////                                                                 ////
//// - On a slow speed device, max polling rate is 1 transaction     ////
////   per 10ms.  This is 800 bytes per second (8 byte packets every ////
////   10ms)                                                         ////
////                                                                 ////
//// - No guarantee that polls will happen at a guaranteed rate.     ////
////   If you want guaranteed transfer rate you must use Isochronous ////
////   transfers, which HID is not.                                  ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
////                      WINDOWS DRIVERS:                           ////
////                                                                 ////
//// USB HID drivers come included with all Windows, starting        ////
//// with Windows 98 and up.  Windows 95 does not include USB        ////
//// support, unless you are running Windows 95 Gold (aka OSR2, or   ////
//// Windows 95b).                                                   ////
////                                                                 ////
//// If you plug in the USB device, and it is working, a "Found new  ////
//// device" window should pop-up.  The Add Device wizard then will  ////
//// install the HID drivers automatically.                          ////
////                                                                 ////
//// If you plug in the USB device and do not get this window then   ////
//// the device is not working, or USB does not work on your         ////
//// computer.  Goto the Device Manager (Right Click on my Computer, ////
//// it is located under one of the Tabs.  It is located under the   ////
//// Hardware tab of Windows2000), and make sure that "Universal     ////
//// Serial Bus controllers" is installed.  Open "Universal Serial   ////
//// Bus controllers" and you should see 1 or more "USB Root Hubs".  ////
//// If you see these then that's a good indication that USB is      ////
//// working on your computer.  If you see a question mark and       ////
//// an unkown USB device then this is quite possibly your USB       ////
//// device that is not working.                                     ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
//// NOTE ABOUT ENDPOINT BUFFER SIZE:                                ////
////                                                                 ////
//// Although this application sends and receives only 2 bytes from  ////
//// the PC, this demo defines USB_EP1_TX_SIZE and USB_EP1_RX_SIZE   ////
//// to 8 to allocate 8 bytes for these endpoint.  These constants   ////
//// are also used in the endpoint descriptor to specify the         ////
//// endpoint max size.  If you were concious of RAM savings you     ////
//// could redefine these to 2 (or even 1!), but you would lose      ////
//// throughput. The reason for throughput loss is that if you send  ////
//// a packet that is the same size as the max packet size then      ////
//// you need to send a 0 len packet to specify end of message       ////
//// marker.  The routines usb_puts() and usb_gets() send and        ////
//// receive multiple packet message, waiting for a 0 len packet     ////
//// or a packet that is smaller than max-packet size.               ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////                                                                 ////
//// VERSION HISTORY                                                 ////
////                                                                 ////
//// Oct 15th, 2010:                                                 ////
////  Potential bug in CDC that causes lost PIC->PC chars resolved?  ////
////  Added initial 18F47J53 family support.                         ////
////  Added USB_ISR_POLLING support.  Define this and interrupts     ////
////     will not be used.  usb_task() must be called periodically   ////
////     in your main loop.  If it is not called faster than once    ////
////     per millisecond, USB may not work (PIC18 and PIC24 only).   ////
////                                                                 ////
//// April 28th, 2010:                                               ////
////  Added ex_usb_common.h.                                         ////
////  Initial support for CCS PIC24USB board.                        ////
////                                                                 ////
//// March 5th, 2009:                                                ////
////   Cleanup for Wizard.                                           ////
////   PIC24 Initial release.                                        ////
////                                                                 ////
//// June 20th, 2005: 18fxx5x initial release.                       ////
////                                                                 ////
//// March 22nd, 2005: Cleanup to work with PIC18Fxx5x               ////
////                                                                 ////
//// June 24th, 2004:  Cleanup to work with updated USB API          ////
////                                                                 ////
/////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2005 Custom Computer Services         ////
//// This source code may only be used by licensed users of the CCS  ////
//// C compiler.  This source code may only be distributed to other  ////
//// licensed users of the CCS C compiler.  No other use,            ////
//// reproduction or distribution is permitted without written       ////
//// permission.  Derivative programs created using this software    ////
//// in object code form are not restricted in any way.              ////
/////////////////////////////////////////////////////////////////////////

#include <ex_usb_common.h>

// you can change the tx and rx packet sizes here.
// in order to be compatbile with hiddemo.exe, these values must be 2.
#define USB_CONFIG_HID_TX_SIZE   2
#define USB_CONFIG_HID_RX_SIZE   2


/////////////////////////////////////////////////////////////////////////////
//
// Include the CCS USB Libraries.  See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////
#if __USB_PIC_PERIF__
 #if defined(__PCM__)
  #include <pic_usb.h>   //Microchip PIC16C765 hardware layer for usb.c
 #elif defined(__PCH__)
  #include <pic18_usb.h>   //Microchip PIC18Fxx5x hardware layer for usb.c
 #elif defined(__PCD__)
  #include <pic24_usb.h>   //Microchip PIC24 hardware layer for usb.c
 #endif
#else
 #include <usbn960x.h>   //National 960x hardware layer for usb.c
#endif
#include <usb_desc_hid.h>   //USB Configuration and Device descriptors for this UBS device
#include <usb.c>        //handles usb setup tokens and get descriptor reports

/////////////////////////////////////////////////////////////////////////////
//
// usb_debug_task()
//
// When called periodically, displays debugging information over serial
// to display enumeration and connection states.  Also lights LED1 based upon
// enumeration and status.
//
/////////////////////////////////////////////////////////////////////////////
void usb_debug_task(void) 
{
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;

   new_connected=usb_attached();
   new_enumerated=usb_enumerated();

   if (new_enumerated)
      LED_ON(LED1);
   else
      LED_OFF(LED1);

   if (new_connected && !last_connected)
      uart_printf("\r\n\nUSB connected, waiting for enumaration...");
   if (!new_connected && last_connected)
      uart_printf("\r\n\nUSB disconnected, waiting for connection...");
   if (new_enumerated && !last_enumerated)
      uart_printf("\r\n\nUSB enumerated by PC/HOST");
   if (!new_enumerated && last_enumerated)
      uart_printf("\r\n\nUSB unenumerated by PC/HOST, waiting for enumeration...");

   last_connected=new_connected;
   last_enumerated=new_enumerated;
}

void display_array(unsigned int8 *p, unsigned int8 n)
{
   while(n--)
   {
      uart_printf(" 0x%X", *p++);
   }
}

void main(void) 
{
   int8 out_data[USB_CONFIG_HID_TX_SIZE];
   int8 in_data[USB_CONFIG_HID_RX_SIZE];
   int8 send_timer=0;
   
   HW_INIT();

   LED_OFF(LED1);
   LED_OFF(LED2);
   LED_OFF(LED3);

   uart_printf("\r\n\nCCS Vendor Specific HID Example");

  #ifdef __PCH__
   uart_printf("\r\nPCH: v");
   uart_printf(__PCH__);
  #elif defined(__PCD__)
   uart_printf("\r\nPCD: v");
   uart_printf(__PCD__);
  #else
   uart_printf("\r\nPCM: v");
   uart_printf(__PCM__);
  #endif

   usb_init_cs();

  #if !(__USB_PIC_PERIF__)
   uart_printf("\r\nUSBN: 0x%X", usbn_get_version());
  #endif
   uart_printf("\r\n");

   setup_adc_ports(HW_ADC_PORTS);
   setup_adc(HW_ADC_CONFIG);
   set_adc_channel(HW_ADC_CHANNEL);
   
   memset(in_data, 0x00, USB_CONFIG_HID_RX_SIZE);
   memset(out_data, 0x00, USB_CONFIG_HID_TX_SIZE);

   while (TRUE) 
   {
      usb_task();
      usb_debug_task();
      if (usb_enumerated()) 
      {
         if (!send_timer) 
         {
            send_timer=250;
            out_data[0]=read_adc();
            out_data[1]=BUTTON_PRESSED();
            if (usb_put_packet(1, out_data, USB_CONFIG_HID_TX_SIZE, USB_DTS_TOGGLE))
            {
               uart_printf("\r\n<-- Sending %u bytes:", USB_CONFIG_HID_TX_SIZE);
               display_array(out_data, USB_CONFIG_HID_TX_SIZE);
            }
         }
         if (usb_kbhit(1)) 
         {
            usb_get_packet(1, in_data, USB_CONFIG_HID_RX_SIZE);
            uart_printf("\r\n--> Received %u bytes:", USB_CONFIG_HID_RX_SIZE);
            display_array(in_data, USB_CONFIG_HID_RX_SIZE);
            if (in_data[0]) {LED_ON(LED2);} else {LED_OFF(LED2);}
            if (in_data[1]) {LED_ON(LED3);} else {LED_OFF(LED3);}
         }
         send_timer--;
         delay_ms(1);
      }
   }
}


Windows me reconoce perfecto el microcontrolador; instala automático drivers, etc.


sin embargo, por el lado de windows, no me queda claro que hacer para verificar la comunicación.

estoy atorado....una ayudadita....en los comentarios de este ejemplo se menciona una aplicación "hiddemo.exe" pero no lo localizo en ninguna carpeta de la instalación del ccs.

De antemano un saludo y gracias...entre tanto; ojala San google me de una respuesta.
 

gvz

Bovino adicto
#9
Antes mencioname tu so, tu framework, porque mira supongo que saves que hid se comunica enviando paquetes de alta prioridad en usb para que el usuario interactue de inmediato, ahora en el lado de windows tienes que crear una aplicacion en el programa de tu eleccion, c#, c++, delphi, vb(el que yo uso), etc, porque en cdc con la hiperterminal nos bastaba, bueno entnces dime en que lenguaje programaras, y ve descargandote la mpusbapi 1.1 que es el controlador que nos proporciona microchip para la compu como enlace, ah y que micro usas?
 
#10
Gracias gvz, Tengo Windows 7 ultimate (32 bits), framework 5 (con todos sus antecesores), y tengo una buena idea de lo que sucede en la comunicación HID, tengo visual basic, pero por supuesto puedo entrarle al c++, seguramente entienda mas c++, pero puedo ajustarme. De hecho considero que lo que necesito saber en plan ABC o receta de cocina, es dentro de windows como obtengo y envió el dato; por DLL, o acceso directo a alguna región (variable) de memoria, ya me contaras.

Voy bajándome el mpusbapi, ¡ahh! tengo tanto 18f2550 y 18f4550.

Recibe un cordial saludo. y Gracias, Muchas gracias por ocuparte en responderme.
 

gvz

Bovino adicto
#11
Muy bien, te falto decirme la version d tu visual, ahora, la mpusbapi, es la dll, y hay instrucciones dependiendo d tu visual que se encargan de enviar otra d recibir, otra para checar los pipes, ve leyendo sobre los pipes, otra para leer la version de la api etc etc, ya ke la descarges y leas lo k viene se t aclararan muchas dudas. Y talvez t ponga lineas d codigo para k n t kiebres tanto la kabeza aunque hay muchos ke soln quieren ke les de tips, segun eyos entre mas dificil el reto mayor es la gloria
 

gvz

Bovino adicto
#12
Bien la otra cosa que tendrias que saver es que con los ejemplos que trae el ccs dl raton o teclado no podras hacer nada en absoluto, solo enviar datos, bueno reportes, ya que esos ejemplos son para usar los controladores por defekto d windows, asi que tendrias que modificarlos para interacctuar con visual, otra cosa, el mpusbapi se modifica con su lenguaje nativo, o podrias usar otras dlls como el hid y setupapi
 
#13
Gracias otra ves gvz, ya me estoy documentando y aunque no lo creas me a servido de mucho tus comentarios, vamos leyendo la documentación del mpusbapi y espero pronto poder compartir mis avances...y prefiero la paz que la gloria, y el camino sin tanto contratiempo, hasta pronto, a leer y leer.

Saludos
 
#15
Como te habrás percatado GVZ, se "perdieron" nuestros últimos comentarios, y en los que se comenta la falta de interés por parte de el foro de temas como este; y que quizás migramos a otros lares, cosa que definitivamente yo hago, ya que aparte de que el sitio en general constantemente tiene caídas y no se encuentra disponible. Entiendo que el servicio es gratuito y lo agradezco, pero francamente ya se a convertido en un sitio de descargas y nada mas, no hay moderación, no se si por falta de ellos o simplemente por que a nadie le interesa.

Con todo esto, agradezco de cualquier forma a todos aquellos que en su momento colaboraron en este foro.

Saludos y hasta luego......
 

gvz

Bovino adicto
#16
me sorprende que los administradores borren nuestros comentarios sin siquiera avizarnos, eso si me hace enojar, pero no se preocupen, es mas, pueden borrar mi cuenta, no quiero pertenecer a un foro que ni nos toma en cuenta, te apoyo miborbolla, adios a este foro
 
Arriba