Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- setup like this:
- serial = new System.IO.Ports.SerialPort("COM1", (int)BaudRates.Baud115200);
- serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);
- serial.Open();
- */
- void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
- {
- Debug.Print("serial data received");
- Stream tmp = new MemoryStream();
- int byteRead = 0;
- while (serial.BytesToRead > 0)
- {
- Byte b = (Byte)serial.ReadByte();
- tmp.WriteByte(b);
- tmp.Flush();
- byteRead++;
- Debug.Print("byte read: " + b);
- }
- Debug.Print("finished reading serial data!" + byteRead);
- Byte[] buffer = new Byte[byteRead];
- tmp.Seek(0, SeekOrigin.Begin);
- tmp.Read(buffer, 0, byteRead);
- foreach (Byte b in buffer)
- Debug.Print("byte sent: " + b);
- Char[] ch = System.Text.Encoding.UTF8.GetChars(buffer);
- String st = new String(ch);
- Debug.Print(st);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement