/// <summary> /// 关闭键盘灯 /// </summary> public static void CloseLED() { var te = CUSB._EnumPorts_(0x048D, 0xCE00); var data = new byte[] { 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; var m_usb = new CUSB(); byte b = 0; foreach (var t in te) { m_usb.Open(t); m_usb.CmdWrite(data, ref b); m_usb.Close(); } }
static void Main(string[] args) { Test(); return; var te = CUSB.EnumPorts(0x0001, 0x064); var data = new byte[] { 0x04, 0x01, 0x00, 0x00, 0x00, 0x00 }; var m_usb = new CUSB(); byte b = 0; foreach (var t in te) { m_usb.Open(t); m_usb.CmdWrite(data, ref b); m_usb.Close(); } }
/// <summary> /// 修改键盘灯亮度 /// </summary> /// <param name="brightness">颜色 (0~32)</param> public static void ModifyBrightness(byte brightness) { if (brightness < 0 || brightness > 32) { throw new Exception("亮度范围为0~32!"); } var te = CUSB._EnumPorts_(0x048D, 0xCE00); var data = new byte[] { 0x08, 0x02, 0x01, 0x05, brightness, 0x08, 0x00, 0x00 }; var m_usb = new CUSB(); byte b = 0; foreach (var t in te) { m_usb.Open(t); m_usb.CmdWrite(data, ref b); m_usb.Close(); } }
/// <summary> /// 修改键盘灯颜色 /// </summary> /// <param name="index">灯位(1~4)</param> /// <param name="color">颜色</param> public static void ModifyColor(byte index, Color color) { if (index <= 0 || index > 4) { throw new Exception("这款键盘只有4个颜色区!"); } var te = CUSB._EnumPorts_(0x048D, 0xCE00); var data = new byte[] { 0x14, 0x00, index, color.R, color.G, color.B, 0x00, 0x00 }; var m_usb = new CUSB(); byte b = 0; foreach (var t in te) { m_usb.Open(t); m_usb.CmdWrite(data, ref b); m_usb.Close(); } }
public CUSBParser(string xml, CUSBNaming cusbnaming) : base(xml, cusbnaming) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlNodeList nodes = doc.GetElementsByTagName("api_response"); foreach (XmlNode node in nodes) { if (_errorcode == string.Empty) { XmlNode cusbs = node.SelectSingleNode(cusbnaming.ContainerNode); if (cusbs != null) { foreach (XmlNode cusbnode in cusbs) { CUSB cusb = new CUSB(); cusb.Xml = cusbnode.InnerXml; cusb.APIVersion = _version; cusb.Id = GetNode(cusbnode, "mac"); cusb.Name = GetNode(cusbnode, "name"); cusb.IPAddress = GetNode(cusbnode, "ip"); cusb.MacAddress = GetNode(cusbnode, "mac"); cusb.ConnectedTo = GetNode(cusbnode, "connectedTo"); cusb.Online = Str2Bool(GetNode(cusbnode, "online")); string type = GetNode(cusbnode, "type"); if (type == "rx") cusb.Type = DeviceType.RX; else cusb.Type = DeviceType.TX; CUSB.Add(cusb); } } } } }
private void SendCMD() { this.usbDelay(); try { byte b = 0; byte[] array = new byte[6]; array[0] = (byte)this.CMD2send[0]; array[1] = (byte)this.CMD2send[1]; array[2] = (byte)this.CMD2send[2]; array[3] = (byte)this.CMD2send[3]; array[4] = (byte)this.CMD2send[4]; this.m_usb = new CUSB(); this.m_usb.Open(this.m_strUSBSymbolicLinks[0]); this.m_usb.CmdWrite(array, ref b); this.m_usb.Close(); } catch (Exception ex) { this.HandleException(ex.Message); } }
private void ReadDataBufFromHID(int readCmd, int data1) { try { byte[] array = new byte[6]; array[0] = (byte)readCmd; array[1] = (byte)data1; this.m_usb = new CUSB(); this.m_usb.Open(this.m_strUSBSymbolicLinks[0]); this.m_usb.CmdRead(ref array); this.m_usb.Close(); this.readDataBuf[0] = (int)array[0]; this.readDataBuf[1] = (int)array[1]; this.readDataBuf[2] = (int)array[2]; this.readDataBuf[3] = (int)array[3]; this.readDataBuf[4] = (int)array[4]; } catch (Exception ex) { this.HandleException(ex.Message); } }