Professional Documents
Culture Documents
Codegiaodien
Codegiaodien
Codegiaodien
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;
using UsbLibrary;
namespace USB_PIC
{
public partial class Form1 : Form
{
byte[] readbuff = new byte[2];
byte[] writebuff = new byte[2];
int count = 0;
public Form1()
{
InitializeComponent();
}
if (this.usbHidPort.SpecifiedDevice != null)
{
this.usbHidPort.SpecifiedDevice.SendData(writebuff);
}
textBox_VID.Text = usbHidPort.VendorId.ToString("x4");
textBox_PID.Text = usbHidPort.ProductId.ToString("x4");
}
if (this.usbHidPort.SpecifiedDevice != null)
this.usbHidPort.SpecifiedDevice.SendData(writebuff);
else
{
MessageBox.Show("Device not found . Please reconnect USB Device to
use.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (InvokeRequired)
{
Invoke(new EventHandler(usbHidPort1_OnDeviceRemoved), new object[]
{ sender, e });
}
else
{
toolStripStatusLabel_InforDevice.Text = "USB Removed";
}
}
}
else
{
toolStripStatusLabel_InforDevice.Text = "Device Disconnected";
textBox_Status.Text = "Disconnected!";
textBox_Status.BackColor = Color.Red;
}
}
}
catch
{ }
}
else
{
readbuff = args.data;
toolStripStatusLabel_InforDevice.Text = "New Received Data";
if (readbuff[1] == '0')
{
ovalShape_LED.BackColor = Color.Black;
}
else if (readbuff[1] == '1')
{
ovalShape_LED.BackColor = Color.Red;
}
else if (readbuff[1] == 'b')
{
count++;
textBox_SW1.Text = count.ToString();
}
}
}
}
}