void CloseAll() { flgReceiving = false; flgPause = false; btnPause.Text = text.Pause; lbMac.Items.Clear(); BleDevice.DeviceList.Clear(); if (serial_port_dongle != null) { if (curDevice != null) { serial_port_dongle.SendData(BLEDongle.PackageData((byte)BLEDongle.CMD.Disconnect, curDevice.mac)); } serial_port_dongle.StopReceiveData(); serial_port_dongle.Close(); } }
private void lbMac_MouseDoubleClick(object sender, MouseEventArgs e) { if (lbMac.SelectedItem != null) { if (curDevice != null) { PaintXYZ.Abort(); serial_port_dongle.SendData(BLEDongle.PackageData((byte)BLEDongle.CMD.Disconnect, curDevice.mac)); Thread.Sleep(100); StartScan(); Thread.Sleep(100); } //lbMac.Enabled = false; //btnScan.Enabled = false; curDevice = BleDevice.DeviceList[lbMac.SelectedItem.ToString()]; serial_port_dongle.SendData(BLEDongle.PackageData((byte)BLEDongle.CMD.Connect, curDevice.mac)); btnScan.Text = text.Scan; flgReceiving = true; //PaintXYZ = new Thread(PaintToGrapgh) { IsBackground = true }; //PaintXYZ.Start(); } }
void ProccessDongleData(List <byte> data) { dUse duse; BLEDongle dongle; List <List <byte> > tl = BLEDongle.ParseData(data); if (tl is null) { return; } foreach (List <byte> l in tl) { dongle = new BLEDongle(l); WriteLog.Console("Dongle Data", $"CMD:{dongle.cmd.ToString("X2")},Data:{ByteConverter.ToHexString(dongle.data)}"); switch (dongle.cmd) { case 0xA2: string address = ByteConverter.ToHexString(dongle.data.GetRange(0, 6)); if (BleDevice.SetDevice(address)) { Invoke(duse = () => { lbMac.Items.Add(address); }); } if (dongle.data.Count > 8) { BleDevice.DeviceList[address].name = ByteConverter.ToAsciiString(dongle.data.GetRange(6, dongle.data.Count - 7)); } else { BleDevice.DeviceList[address].name = "None"; } BleDevice.DeviceList[address].rssi = dongle.data[dongle.data.Count - 1]; break; case 0xA3: if (curDevice is null) { break; } if (ByteConverter.ToHexString(curDevice.mac) == ByteConverter.ToHexString(dongle.data)) { curDevice.receiveA5 = true; curDevice.connecting = true; if (PaintXYZ.IsAlive) { PaintXYZ.Abort(); Thread.Sleep(10); } PaintXYZ = new Thread(PaintToGrapgh) { IsBackground = true }; PaintXYZ.Start(); } break; case 0xA4: if (curDevice is null) { break; } if (ByteConverter.ToHexString(curDevice.mac) == ByteConverter.ToHexString(dongle.data)) { curDevice.receiveA5 = false; curDevice.connecting = false; } break; case 0xA5: if (curDevice is null) { break; } if (curDevice.receiveA5 == false) { break; } byte[] tData = dongle.data.GetRange(6, dongle.data.Count - 6).ToArray(); if (tData[0] == 0x25 && tData.Length == 20) { for (int i = 1; i < 19; i += 6) { try { point.Enqueue(new PointXYX( (((sbyte)tData[0 + i]) * 256 + tData[1 + i]), (((sbyte)tData[2 + i]) * 256 + tData[3 + i]), (((sbyte)tData[4 + i]) * 256 + tData[5 + i]))); } catch (Exception) { } } } break; case 0xA6: if (dongle.data[6] == 0x01) { curDevice.connecting = true; curDevice.receiveA5 = true; PaintXYZ.Start(); } else { curDevice.connecting = false; curDevice.receiveA5 = false; PaintXYZ.Abort(); } break; //case 0xAA: // if (curDevice is null) // { // return; // } // if (ByteConverter.ToHexString(dongle.data.GetRange(0, 6)) == ByteConverter.ToHexString(curDevice.mac)) // { // PaintXYZ.Start(); // curDevice.connecting = true; // WriteLog.Console("Connecting", curDevice.name); // } // break; //case 0xB1: // if (dongle.data[0] == 0x01) // { // curDevice.inConnectList = true; // } // else { curDevice.inConnectList = false; } // break; //case 0xC1: // if (dongle.data[2] != 0x01) return; // string mac = ByteConverter.ToHexString(dongle.data.GetRange(3, 6)); // if (!_connectedMac.Contains(mac)) // _connectedMac.Add(mac); // break; } } }
void StopScan() { serial_port_dongle.SendData(BLEDongle.PackageData((byte)BLEDongle.CMD.StopScan, null)); btnScan.Text = text.Scan; }