Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Serial port!");
            var  ports = SerialDevice.GetPortNames();
            bool isTTY = false;

            foreach (var prt in ports)
            {
                Console.WriteLine($"Serial name: {prt}");
                if (prt.Contains("ttyS0"))
                {
                    isTTY = true;
                }
            }
            if (!isTTY)
            {
                Console.WriteLine("No ttyS0 serial port!");
                return;
            }
            Console.WriteLine("Yes, we have the embedded serial port available, opening it");
            SerialDevice mySer = new SerialDevice("/dev/ttyS0", BaudRate.B1152000);

            mySer.DataReceived += MySer_DataReceived;
            mySer.Open();
            while (!Console.KeyAvailable)
            {
                ;
            }
            mySer.Close();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var parser = new NmeaParser();

            var dummy = File.ReadAllText("/home/lubuntu/sample.nmea");
            //var dummyBytes = Encoding.UTF8.GetBytes(dummy);
            var nm = parser.Parse(dummy);

            return;

            var portNames = SerialDevice.GetPortNames();

            var serial = new SerialDevice("/dev/ttyACM0", BaudRate.B1152000);

            serial.DataReceived += (o, eventArgs) =>
            {
            };


            serial.Open();

            while (true)
            {
                Thread.Sleep(200);
            }
            return;

            var client = new UdpClient(5554);
            var sender = new UdpClient(5556);

            var ip     = "192.168.100.55";
            var exitBs = Encoding.ASCII.GetBytes("AT*CONFIG=\"general:navdata_demo\",\"TRUE\"\r");
            var ack    = Encoding.ASCII.GetBytes("AT*CTRL=0\r");

            sender.Send(exitBs, exitBs.Length, ip, 5556);
            sender.Send(ack, ack.Length, ip, 5556);
            client.Send(new byte[] { 1 }, 1, ip, 5554);

            var nav = new NavDataRetriever("192.168.100.55", 5554, 2000, client);

            nav.SendMessage = i => client.Send(new byte[] { (byte)i }, 1, ip, 5554);
            nav.Start();
            nav.WaitForFirstMessageToArrive();
            var navData = nav.CurrentNavigationData;

            while (true)
            {
                navData = nav.CurrentNavigationData;
            }
        }
Exemplo n.º 3
0
        private static bool IsSerialAvailable()
        {
            var  ports = SerialDevice.GetPortNames();
            bool isTTY = false;

            foreach (var prt in ports)
            {
                Console.WriteLine($"Serial name: {prt}");
                if (prt.Contains("ttyUSB0"))
                {
                    isTTY = true;
                }
            }

            return(isTTY);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Static function to get a list of available serial ports
 /// </summary>
 /// <returns></returns>
 public static string[] GetSerialPorts()
 {
     return(SerialDevice.GetPortNames());
 }