-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompanion.cs
63 lines (51 loc) · 1.92 KB
/
Companion.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net.Sockets;
using System.Windows.Forms;
using SimpleTCP;
using System.Net;
namespace Vision_Automix
{
class Companion
{
public void sendPush(RuntimeData runData, string ip, int port, int page, int bank)
{
if (runData.companionOutputEnabled == true)
{
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
try
{
string message = ("BANK-PRESS " + page.ToString() + " " + bank.ToString());
byte[] packetData = System.Text.ASCIIEncoding.ASCII.GetBytes(message);
IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ip), port);
client.SendTo(packetData, ep);
//Console.WriteLine("Pressing button " + page + "-" + bank);
}
catch (Exception e)
{
Console.WriteLine("Error sending TCP packet");
MessageBox.Show("Error sending TCP packet to Companion. The TCP client has probably not been initialized with a IP and Port yet. " + e);
}
} else
{
Console.WriteLine("Companion output disabled, no command was sent.");
}
}
public string getIPstringFromCon(int[] con)
{
try
{
string returnString = (con[0] + "." + con[1] + "." + con[2] + "." + con[3]);
return returnString;
} catch
{
Console.WriteLine("Error creating string for CompanionIP. Returning 127.0.0.1");
return "127.0.0.1";
}
}
}
}