private void TX_Sync(DevicePacket devicePacket) { SerialPort_Lock.WaitOne(); try { DashboardPacket packet = new DashboardPacket(); packet.Sync1 = '$'; packet.Sync2 = '&'; packet.length = (UInt16)(devicePacket.Length); packet.id = (byte)devicePacket.ID; packet.crc = 0xAA; foreach (var t in devicePacket.Data) { packet.crc += t; } // Write header byte[] bPacket = ByteMethods.ToBytes(packet); SP.Write(bPacket, 0, 6); // Write packet data SP.Write(devicePacket.Data, 0, devicePacket.Length); byte[] dump = new byte[64]; for (int lol = 0; lol < 64; lol++) { dump[lol] = 64; } SP.Write(dump, 0, 16); } catch (Exception ex) { } SerialPort_Lock.Release(); }
private void TX_Sync(DevicePacket devicePacket) { DashboardPacket packet = new DashboardPacket(); packet.Sync1 = '$'; packet.Sync2 = '&'; packet.length = (UInt16)(devicePacket.Length); packet.id = (byte)devicePacket.ID; // Write header byte[] bPacket = ByteMethods.ToBytes(packet); SP.Write(bPacket, 0, 5); // Write packet data SP.Write(devicePacket.Data, 0, devicePacket.Length); // Write junk incase bytes are missed on embedded system. // This way there is a better chance the next package is received. byte[] bf = new byte[2]; bf[0] = 0; bf[1] = 0; SP.Write(bf, 0, 2); }
private void SendPackage(DashboardPackages package, byte[] data) { DevicePacket pk = new DevicePacket((int)package, data); Telemetry.m.Peripherals.TX(pk, ""); return; SerialPort_Lock.WaitOne(); DashboardPacket packet = new DashboardPacket(); packet.Sync1 = '$'; packet.Sync2 = '&'; packet.length = (UInt16)(data.Length); packet.id = (byte)package; byte[] bPacket = ByteMethods.ToBytes(packet); sp.Write(bPacket, 0, 5); sp.Write(data, 0, data.Length); byte[] bf = new byte[2]; bf[0] = 0; bf[1] = 0; sp.Write(bf, 0, 2); SerialPort_Lock.Release(); }