forked from Ellerbach/serialapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
37 lines (35 loc) · 1.09 KB
/
Program.cs
File metadata and controls
37 lines (35 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
namespace serialapp
{
class Program
{
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;
while (!Console.KeyAvailable)
;
}
private static void MySer_DataReceived(object arg1, byte[] arg2)
{
Console.WriteLine($"Received: {System.Text.Encoding.UTF8.GetString(arg2)}");
}
}
}