void thr() { while (run) { int avail; try { avail = serial_port.BytesToRead; } catch { avail = 0; } if (avail > 0) { int len = serial_port.BytesToRead; byte[] b = new byte[len]; serial_port.Read(b, 0, len); if (mode == COMM_MODE.Serial) { AppendToBuffer(b); } else { mav.ParseBytes(b); } } else { Thread.Sleep(1); } } }
public void parseMavlink() { try { while (_tcpClient.Connected) { Byte[] data; _stream = _tcpClient.GetStream(); data = new Byte[256]; //Read the first batch of the TcpServer response bytes. if (_tcpClient.Connected) { Int32 bytes = _stream.Read(data, 0, data.Length); if (bytes > 0) { //parse mavlink _mav.ParseBytes(data); Console.WriteLine("ParseBytes: " + Thread.CurrentThread.ManagedThreadId.ToString()); } } } _stream.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } }
void tlog() { tlog_mav.PacketReceived += Tlogmav_PacketReceived; int left = tlog_buf.Length; int total = left; int cnt = 20; int idx = 0; Console.WriteLine("got {0} .tlog bytes", left); do { if (seek != -1) { idx = (seek * total) / 100; left = total - idx; seek = -1; } int c = Math.Min(left, cnt); byte[] b = new byte[cnt]; Array.Copy(tlog_buf, idx, b, 0, c); tlog_mav.ParseBytes(b); idx += c; left -= c; progress = (idx * 100) / total; if (!tlog_active) { break; } } while (left > 0); tlog_mav.PacketReceived -= Tlogmav_PacketReceived; }
private void Data(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { int x = Serial.BytesToRead; byte[] b = new byte[x]; for (int i = 0; i < x; i++) { b[i] = (byte)Serial.ReadByte(); } Mv.ParseBytes(b); }
void SocketReceive() { while (true) { recvData = new byte[40]; recvLen = socket.ReceiveFrom(recvData, ref serverEnd); Mv.ParseBytes(recvData); print(System.BitConverter.ToString(recvData)); } }
private void DataRecieved(object sender, SerialDataReceivedEventArgs e) { int x = serialPort.BytesToRead; byte[] b = new byte[x]; for (int i = 0; i < x; i++) { b[i] = (byte)serialPort.ReadByte(); } Mv.ParseBytes(b); }
public void SendTest() { Mavlink mavlink = new Mavlink(); Msg_attitude msg_Attitude = new Msg_attitude(); msg_Attitude.roll = 1; MavlinkPacket packet = new MavlinkPacket(msg_Attitude); var res = mavlink.Send(packet); mavlink.PacketReceived += Mavlink_PacketReceived; mavlink.ParseBytes(res); Assert.AreNotEqual(mavlink.PacketsReceived, 0); }
private void serialPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { List <byte> bytes = new List <byte>(); while (serialPort.IsOpen && serialPort.BytesToRead > 0) { if (serialPort.IsOpen) { bytes.Add((byte)serialPort.ReadByte()); } } mavlink.ParseBytes(bytes.ToArray()); }
private static void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { byte[] readBytes = new byte[serialPort.BytesToRead]; serialPort.Read(readBytes, 0, readBytes.Length); mavlink.ParseBytes(readBytes); }
private void E34_2G4D20D_ReciveEvent(byte[] bytes) { Mavlink.ParseBytes(bytes); }
private async Task loop(string name, int sleepTime, bool readAsCharArray) { BluetoothDevice device = null; BluetoothAdapter adapter = BluetoothAdapter.DefaultAdapter; //Thread.Sleep(1000); _ct = new CancellationTokenSource(); while (_ct.IsCancellationRequested == false) { try { Thread.Sleep(sleepTime); adapter = BluetoothAdapter.DefaultAdapter; if (adapter == null) { System.Diagnostics.Debug.WriteLine("No Bluetooth adapter found."); continue; } else { System.Diagnostics.Debug.WriteLine("Adapter found!!"); } if (!adapter.IsEnabled) { System.Diagnostics.Debug.WriteLine("Bluetooth adapter is not enabled."); } else { System.Diagnostics.Debug.WriteLine("Adapter enabled!"); } System.Diagnostics.Debug.WriteLine("Try to connect to " + name); foreach (var bd in adapter.BondedDevices) { System.Diagnostics.Debug.WriteLine("Paired devices found: " + bd.Name.ToUpper()); if (bd.Name.ToUpper().IndexOf(name.ToUpper()) >= 0) { System.Diagnostics.Debug.WriteLine("Found " + bd.Name + ". Try to connect with it!"); device = bd; break; } } if (device == null) { System.Diagnostics.Debug.WriteLine("Named device not found."); } else { UUID uuid = UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"); //SerialPortServiceClass if ((int)Android.OS.Build.VERSION.SdkInt >= 10) // Gingerbread 2.3.3 2.3.4 { BthSocket = device.CreateInsecureRfcommSocketToServiceRecord(uuid); } else { BthSocket = device.CreateRfcommSocketToServiceRecord(uuid); } if (BthSocket != null) { await BthSocket.ConnectAsync(); if (BthSocket.IsConnected) { System.Diagnostics.Debug.WriteLine("Connected!"); while (_ct.IsCancellationRequested == false) { using (var ist = BthSocket.InputStream) { var base_inp_steream = (ist as InputStreamInvoker).BaseInputStream; var data_size = 0; if ((data_size = base_inp_steream.Available()) > 0) { byte[] data = new byte[data_size]; var nn = base_inp_steream.Read(data, 0, data_size); mavlink_obj.ParseBytes(data); } } // A little stop to the uneverending thread... System.Threading.Thread.Sleep(sleepTime); if (!BthSocket.IsConnected) { System.Diagnostics.Debug.WriteLine("BthSocket.IsConnected = false, Throw exception"); throw new Exception(); } } System.Diagnostics.Debug.WriteLine("Exit the inner loop"); } } else { System.Diagnostics.Debug.WriteLine("BthSocket = null"); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("EXCEPTION: " + ex.Message); } finally { if (BthSocket != null) { BthSocket.Close(); } device = null; adapter = null; } } System.Diagnostics.Debug.WriteLine("Exit the external loop"); }
public void SerialPortReceivedHandler(byte[] received_data) { mavlink_obj.ParseBytes(received_data); }