-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
72 lines (57 loc) · 1.62 KB
/
Program.cs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System.IO.Ports;
var ArrayComPortsNames = SerialPort.GetPortNames();
Console.WriteLine($"COM ports; {ArrayComPortsNames.Length}");
foreach (var i in ArrayComPortsNames)
{
var portName = i.ToString();
Console.WriteLine(portName);
}
var _serialPort = new SerialPort();
_serialPort.PortName = "/dev/ttyUSB2";
_serialPort.BaudRate = 115200;
//_serialPort.Parity = Parity.None;
//_serialPort.StopBits = StopBits.One;
//_serialPort.DataBits = 8;
//_serialPort.Handshake = Handshake.None;
_serialPort.DataReceived += port_DataReceived;
Console.WriteLine($"PortName: {_serialPort.PortName}");
Console.WriteLine($"BaudRate: {_serialPort.BaudRate}");
Console.WriteLine($"Parity: {_serialPort.Parity}");
Console.WriteLine($"StopBits: {_serialPort.StopBits}");
Console.WriteLine($"DataBits: {_serialPort.DataBits}");
Console.WriteLine($"Handshake: {_serialPort.Handshake}");
_serialPort.ReadTimeout = 2000;
_serialPort.Open();
//bool _continue = true;
//Task.Run(() =>
//{
// while (_continue)
// {
// try
// {
// var message = _serialPort.ReadLine();
// Console.WriteLine($"output: {message}");
// }
// catch (TimeoutException) { }
// }
//});
//while (_continue)
//{
// var message = Console.ReadLine();
// if (message == "quit")
// {
// _continue = false;
// }
// else
// {
// _serialPort.Write($"\r{message}\r");
// }
//}
void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Console.WriteLine($"{_serialPort.ReadExisting()}");
}
_serialPort.Write("\rAT\r");
_serialPort.Write("\rAT#ECM=1,0\r");
Task.Delay(1000).Wait();