Esempio n. 1
0
        static void Main(string[] args)
        {
            var settings = Properties.Settings.Default;

            // initialise the PiFace device to bind the server to
            var device = default(IPiFaceDevice);
            switch(settings.DeviceType)
            {
                case "Physical":
                    device = new PiFaceDevice();
                    break;
                case "Emulated":
                    device = new PiFaceEmulator();
                    break;
                default:
                    throw new System.Configuration.ConfigurationErrorsException("The 'DeviceType' setting in app.config must be either 'Physical' or 'Emulated'.");
            }

            // get the address to run the server on
            var address = default(IPAddress);
            if (string.IsNullOrEmpty(settings.ServerAddress))
            {
                address = PiFaceTcpHelper.GetLocalIPAddress();
            }
            else
            {
                address = IPAddress.Parse(settings.ServerAddress);
            }

            // get the port to run the server on
            var port = (uint)0;
            if (!uint.TryParse(settings.ServerPort, out port))
            {
                throw new System.Configuration.ConfigurationErrorsException("The 'ServerPort' setting in app.config must be an unsigned integer.");
            }

            // start the server
            var endpoint = new IPEndPoint(address, (int)port);
            var server = new PiFaceTcpServer(device, endpoint);
            server.MessageReceived += Program.PiFaceTcpServer_MessageReceived;
            server.ResponseSent += Program.PiFaceTcpServer_ResponseSent;
            server.Start();

            // wait around while the server runs
            while(true)
            {
                System.Threading.Thread.Sleep(1000);
            }
        }
Esempio n. 2
0
 private void btnStart_Click(object sender, EventArgs e)
 {
     // initialise the piface server
     var address = PiFaceTcpHelper.GetLocalIPAddress();
     var endpoint = new IPEndPoint(address, 43596);
     this.PiFaceTcpServer = new PiFaceTcpServer(this.PiFaceEmulator, endpoint);
     this.PiFaceTcpServer.MessageReceived += this.PiFaceTcpServer_MessageReceived;
     this.PiFaceTcpServer.ResponseSent += this.PiFaceTcpServer_ResponseSent;
     this.PiFaceTcpServer.Start();
     // update form controls
     txtLocalAddress.Enabled = false;
     txtLocalPort.Enabled = false;
     btnStart.Enabled = false;
     btnStop.Enabled = true;
     lblStatus.Text = "Started.";
     this.LogEvent("server started");
 }