示例#1
0
        public MainWindow()
        {
            InitializeComponent();
           /* foreach (var k in AndroidSerialPort.EnumerateSerialPorts().Keys)
                MessageBox.Show(k + ":" + AndroidSerialPort.EnumerateSerialPorts()[k]);
            */
            Timer t = new Timer(50);
            t.Elapsed += T_Elapsed;
            Timer t2 = new Timer(200);
            t2.Elapsed += T2_Elapsed;
            arduino1 = new Arduino<UnitySerialPort.AndroidSerialPort>(BoardType.UNO);
            //arduino2 = new Arduino(BoardType.UNO);

            try
            {
                //arduino2.pinMode(13, PinMode.OUTPUT);
                /*arduino.pinMode(12, PinMode.OUTPUT);
                arduino.pinMode(7, PinMode.INPUT_PULLUP);*/
                //arduino.pinMode(12, PinMode.OUTPUT);
                var sp = new SerialPort("COM7", 9600, SerialPortNET.Parity.None, 8, SerialPortNET.StopBits.One);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //t.Start();
            //t2.Start();
        }
示例#2
0
        public static void Main(string[] args)
        {
            // Used for performance measurement

            /*
            DateTime t;
            TimeSpan s;
            t = DateTime.Now;
            */
            SerialPort sp = new SerialPort("COM18", 9600, Parity.None, 8, StopBits.One);
            sp.ReceivedBytesThreshold = 1;

            sp.DataReceived += (object sender, SerialDataReceivedEventArgs e) =>
            {
                Console.WriteLine(sp.ReadLine());
            };

            sp.Open();
            Thread.Sleep(5000);
            sp.RunAsync();
            //Console.WriteLine("{0}", sp.IsOpen);
            Console.ReadKey();
        }