さて、単一のアプリ ソリューションではありませんが、できることは次のとおりです。
見つかりません - 指定された目的で開いている API アプリが見つかりません。
加速度計データの受信 - UDP
class Inertia : IDisposable
{
UdpClient listener = new UdpClient(5555);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, 5555);
Control context = null;
public Inertia(Control context)
{
this.context = context;
IAsyncResult result = listener.BeginReceive(new AsyncCallback(udpCallback), null);
}
private void udpCallback(IAsyncResult result)
{
byte[] data = listener.EndReceive(result, ref groupEP);
if (data.Length > 0)
{
string line = ASCIIEncoding.ASCII.GetString(data);
if (context.InvokeRequired)
context.BeginInvoke(UDPStringReceived, line);
else
if (UDPStringReceived != null) UDPStringReceived(line);
}
result = listener.BeginReceive(new AsyncCallback(udpCallback), null);
}
public delegate void UDPStringReceivedHandler(string line);
public event UDPStringReceivedHandler UDPStringReceived;
public void Dispose()
{
//TODO: Stop listening
}
}
WinForms で使用する Inertia クラスの使用:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;
}
Inertia inertia = null;
void Form1_Load(object sender, EventArgs e)
{
inertia = new Inertia(this);
inertia.UDPStringReceived += inertia_UDPStringReceived;
}
void inertia_UDPStringReceived(string line)
{
try
{
string[] components = line.Split(',');
//My text boxes, showing the data
t.Text = components[0];
//index 1 contains the value 2, which probably indicates "Accelerometer" in next 3 values
aX.Text = components[2];
aY.Text = components[3];
aZ.Text = components[4];
//index 5 contains the value 3, which probably indicates "Gyroscope" in next 3 values
gX.Text = components[6];
gY.Text = components[7];
gZ.Text = components[8];
}
catch (Exception ex)
{
}
}
}