Ir ao conteúdo
  • Cadastre-se

iFireOxz

Membro Pleno
  • Posts

    29
  • Cadastrado em

  • Última visita

Tudo que iFireOxz postou

  1. Olá pessoal, tudo bem? estou trabalhando em um projeto de PIC usando a USB no modo HID, meu código de envio ficou mais ou menos assim, if ((aux_cont1 == 0) && (SENSOR1 == 1 )) { aux_cont1 = 1; writebuff[1] = 1; while(!Hid_Write(&writebuff, 64)) } if ((aux_cont1 == 1) && (SENSOR1 == 0)) { aux_cont1 = 0; } nesse caso o comando while(!Hid_Write(&writebuff, 64)) que é padrão pelo tutorial que achei, quando faço os testes ele envia os 64 bits, e queria que enviasse apenas o valor de writebuff[1] alguém pode me ajudar a fazer isso? Sou novo na linguagem C.
  2. Tudo bem matheus? Então cara, estou trabalhando em um projeto usb HID e consegui fazer o computador reconhece-lo, mas quando tento fazer o aplicativo do C# reconhecer que o dispositivo foi conectado, nada acontece. Estou usando um exemplo do Livro "Criação de Sistemas Supervisórios em Visual C# 2010 Express" segue abaixo o código. Vi o seu código mas n entendi muita coisa, a importação da dll, a parte de envio de informações e recebimentos, sou novo nessa área, teria como me explicar? using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication2{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { toolStripStatusLabel1.Text = "Dispositivo desconectado..."; } private void conectarToolStripMenuItem_Click(object sender, EventArgs e) { try { UsbCom.ProductId = 0001; UsbCom.VendorId = 1234; UsbCom.CheckDevicePresent(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void UsbCom_OnSpecifiedDeviceArrived(object sender, EventArgs e) { toolStripStatusLabel1.Text = "Dispositivo Conectado..."; } private void toolStripStatusLabel1_Click(object sender, EventArgs e) { } }}
  3. O problema ja foi resolvido, o MikroC estava com um crack bugado e gerando um .hex todo errado, identifiquei isso olhando as possições de memória pelo PicKit2, pode fechar o tópico
  4. Tudo bem pessoal? Estou com um problema. Estou fazendo um projeto que lê informações vindas de um sensor e joga para um software no PC através da USB, estou usando HID para mandar. Segue abaixo o código. O meu problema é, quando compilo, coloco a usb ele não identifica nada, como se nada estivesse sido plugado, alguém ja possou por isso ou sabe arrumar? Tem algo de errado com meu código? Estou usando o MikroC para compilar. Arquivo Usbdsc.c gerado pelo HID terminal do MikroC const unsigned int USB_VENDOR_ID = 0x1234;const unsigned int USB_PRODUCT_ID = 0x0001;const char USB_SELF_POWER = 0xC0; // Self powered 0xC0, 0x80 bus poweredconst char USB_MAX_POWER = 50; // Bus power required in units of 2 mAconst char HID_INPUT_REPORT_BYTES = 64;const char HID_OUTPUT_REPORT_BYTES = 64;const char USB_TRANSFER_TYPE = 0x03; //0x03 Interruptconst char EP_IN_INTERVAL = 1;const char EP_OUT_INTERVAL = 1;const char USB_INTERRUPT = 1;const char USB_HID_EP = 1;const char USB_HID_RPT_SIZE = 33;/* Device Descriptor */const struct { char bLength; // bLength - Descriptor size in bytes (12h) char bDescriptorType; // bDescriptorType - The constant DEVICE (01h) unsigned int bcdUSB; // bcdUSB - USB specification release number (BCD) char bDeviceClass; // bDeviceClass - Class Code char bDeviceSubClass; // bDeviceSubClass - Subclass code char bDeviceProtocol; // bDeviceProtocol - Protocol code char bMaxPacketSize0; // bMaxPacketSize0 - Maximum packet size for endpoint 0 unsigned int idVendor; // idVendor - Vendor ID unsigned int idProduct; // idProduct - Product ID unsigned int bcdDevice; // bcdDevice - Device release number (BCD) char iManufacturer; // iManufacturer - Index of string descriptor for the manufacturer char iProduct; // iProduct - Index of string descriptor for the product. char iSerialNumber; // iSerialNumber - Index of string descriptor for the serial number. char bNumConfigurations; // bNumConfigurations - Number of possible configurations} device_dsc = { 0x12, // bLength 0x01, // bDescriptorType 0x0200, // bcdUSB 0x00, // bDeviceClass 0x00, // bDeviceSubClass 0x00, // bDeviceProtocol 8, // bMaxPacketSize0 USB_VENDOR_ID, // idVendor USB_PRODUCT_ID, // idProduct 0x0001, // bcdDevice 0x01, // iManufacturer 0x02, // iProduct 0x00, // iSerialNumber 0x01 // bNumConfigurations };/* Configuration 1 Descriptor */const char configDescriptor1[]= { // Configuration Descriptor 0x09, // bLength - Descriptor size in bytes 0x02, // bDescriptorType - The constant CONFIGURATION (02h) 0x29,0x00, // wTotalLength - The number of bytes in the configuration descriptor and all of its subordinate descriptors 1, // bNumInterfaces - Number of interfaces in the configuration 1, // bConfigurationValue - Identifier for Set Configuration and Get Configuration requests 0, // iConfiguration - Index of string descriptor for the configuration USB_SELF_POWER, // bmAttributes - Self/bus power and remote wakeup settings USB_MAX_POWER, // bMaxPower - Bus power required in units of 2 mA // Interface Descriptor 0x09, // bLength - Descriptor size in bytes (09h) 0x04, // bDescriptorType - The constant Interface (04h) 0, // bInterfaceNumber - Number identifying this interface 0, // bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber. 2, // bNumEndpoint - Number of endpoints supported not counting endpoint zero 0x03, // bInterfaceClass - Class code 0, // bInterfaceSubclass - Subclass code 0, // bInterfaceProtocol - Protocol code 0, // iInterface - Interface string index // HID Class-Specific Descriptor 0x09, // bLength - Descriptor size in bytes. 0x21, // bDescriptorType - This descriptor's type: 21h to indicate the HID class. 0x01,0x01, // bcdHID - HID specification release number (BCD). 0x00, // bCountryCode - Numeric expression identifying the country for localized hardware (BCD) or 00h. 1, // bNumDescriptors - Number of subordinate report and physical descriptors. 0x22, // bDescriptorType - The type of a class-specific descriptor that follows USB_HID_RPT_SIZE,0x00, // wDescriptorLength - Total length of the descriptor identified above. // Endpoint Descriptor 0x07, // bLength - Descriptor size in bytes (07h) 0x05, // bDescriptorType - The constant Endpoint (05h) USB_HID_EP | 0x80, // bEndpointAddress - Endpoint number and direction USB_TRANSFER_TYPE, // bmAttributes - Transfer type and supplementary information 0x40,0x00, // wMaxPacketSize - Maximum packet size supported EP_IN_INTERVAL, // bInterval - Service interval or NAK rate // Endpoint Descriptor 0x07, // bLength - Descriptor size in bytes (07h) 0x05, // bDescriptorType - The constant Endpoint (05h) USB_HID_EP, // bEndpointAddress - Endpoint number and direction USB_TRANSFER_TYPE, // bmAttributes - Transfer type and supplementary information 0x40,0x00, // wMaxPacketSize - Maximum packet size supported EP_OUT_INTERVAL // bInterval - Service interval or NAK rate};const struct { char report[USB_HID_RPT_SIZE];}hid_rpt_desc = { {0x06, 0x00, 0xFF, // Usage Page = 0xFF00 (Vendor Defined Page 1) 0x09, 0x01, // Usage (Vendor Usage 1) 0xA1, 0x01, // Collection (Application) // Input report 0x19, 0x01, // Usage Minimum 0x29, 0x40, // Usage Maximum 0x15, 0x00, // Logical Minimum (data bytes in the report may have minimum value = 0x00) 0x26, 0xFF, 0x00, // Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255) 0x75, 0x08, // Report Size: 8-bit field size 0x95, HID_INPUT_REPORT_BYTES,// Report Count 0x81, 0x02, // Input (Data, Array, Abs) // Output report 0x19, 0x01, // Usage Minimum 0x29, 0x40, // Usage Maximum 0x75, 0x08, // Report Size: 8-bit field size 0x95, HID_OUTPUT_REPORT_BYTES,// Report Count 0x91, 0x02, // Output (Data, Array, Abs) 0xC0} // End Collection };//Language code string descriptorconst struct { char bLength; char bDscType; unsigned int string[1]; } strd1 = { 4, 0x03, {0x0409} };//Manufacturer string descriptorconst struct{ char bLength; char bDscType; unsigned int string[26]; }strd2={ 54, //sizeof this descriptor string 0x03, {'P','r','o','j','e','c','t',' ','P','e','r','f','o','r','m','a','n','c','e',' ','T','i','s','s','u','e'} };//Product string descriptorconst struct{ char bLength; char bDscType; unsigned int string[26];}strd3={ 54, //sizeof this descriptor string 0x03, {'P','r','o','j','e','c','t',' ','P','e','r','f','o','r','m','a','n','c','e',' ','T','i','s','s','u','e'} };//Array of configuration descriptorsconst char* USB_config_dsc_ptr[1];//Array of string descriptorsconst char* USB_string_dsc_ptr[3];void USB_Init_Desc(){ USB_config_dsc_ptr[0] = &configDescriptor1; USB_string_dsc_ptr[0] = (const char*)&strd1; USB_string_dsc_ptr[1] = (const char*)&strd2; USB_string_dsc_ptr[2] = (const char*)&strd3;}

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!