-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduinoCom.cs
43 lines (37 loc) · 936 Bytes
/
ArduinoCom.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
namespace LightGun
{
public class ArduinoCom
{
SerialPort port = new SerialPort();
public void OpenPort(string port){
this.port = new SerialPort(port, 115200);
try
{
this.port.Open();
MessageBox.Show("Open");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void ClosePort()
{
this.port.Close();
}
public void SendCursorPos(int x, int y)
{
String data = $"0 {x} {y}\n";
if(port.BytesToWrite == 0)
{
port.Write(data);
}
}
}
}