Ejemplo n.º 1
0
        private void CurrentPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            //byte[] receiveStr;

            SerialPort sp = sender as SerialPort;

            if (sp == null)
            {
                return;
            }
            byte[] readBuffer = new byte[sp.ReadBufferSize];
            sp.Read(readBuffer, 0, readBuffer.Length);

            //赋值
            //receiveStr = readBuffer;
            //将byte[]转换为字符串。
            string str = Encoding.Default.GetString(readBuffer);

            // Print string to console.
            Console.Write(str.Replace("\0", string.Empty).Trim());

            // Add string to queue.
            SerialProcessor.PushData(str);

            //await UploadData.UploadDataAsync(requestData);

            // Lower cpu using percent
            Thread.Sleep(100);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            // Read data feom serial port.
            SerialPortTool st = new SerialPortTool("COM6");

            // Save data to db.
            SerialProcessor.OnSaveData += St_SaveDataAsync;
            SerialProcessor.SaveData();

            Console.ReadLine();
        }