User Tools

Site Tools


thefirstprogram

The first control program

This little Windows Tablet was bought a couple of years ago, with the intent to use it as a controlcenter for a Home Control System, as it's fairly simple to make programs for it in C#. So a program was made: Each time a LED button is pressed a UDP (User Datagram Protocol UDP) datagram is transmitted:

private void button1_Click(object sender, EventArgs e){  
       if (LED1) 
              UDP_SEND("ON_NO1"); 
          else 
              UDP_SEND("OFF_NO1"); 
      }















And the code for UDP_SEND:

private void UDP_SEND(string str2Send)
      {
          byte[] data = new byte[1024];
          IPEndPoint ip = new IPEndPoint(IPAddress.Parse("192.168.1.101"), 2390);
          Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
          data = Encoding.ASCII.GetBytes(str2Send.ToCharArray());
          server.SendTo(data, data.Length, SocketFlags.None, ip);
          server.Close();
      }

thefirstprogram.txt · Last modified: 2018/01/03 23:23 by 92.246.24.25