예제 #1
0
        static void Main(string[] args)
        {
            try
            {
                // create a RestfulDeviceService used to communicate with the DeviceHive cloud
                // insert your assigned DeviceHive service URL here
                var service = new RestfulDeviceService("http://pg.devicehive.com/api");

                // create a DeviceHive network where our device will reside
                var network = new Network("VirtualLed Sample Network", "A DeviceHive network for VirtualLed sample");

                // create a DeviceHost used to run our device
                var deviceHost = new DeviceHost(service, network);

                // create an instance of virtual LED device and add it to the host
                var led = new VirtualLedDevice();
                deviceHost.AddDevice(led);

                // start the host - it will register the device and start polling commands
                deviceHost.Start();

                // wait for console key press and then stop the host
                Console.WriteLine("Device is now running, press any key to stop...");
                Console.ReadKey();
                deviceHost.Stop();
            }
            catch (Exception ex)
            {
                // handle the error
                Console.WriteLine("Error: " + ex);
                Console.ReadKey();
            }
        }
예제 #2
0
        private static void Main()
        {
            try
            {
                // initialize logger
                log4net.Config.XmlConfigurator.Configure();

                // create a RestfulDeviceService used to communicate with the DeviceHive cloud
                // insert your assigned DeviceHive service URL here
                using (var deviceService = new RestfulDeviceService("http://localhost/DeviceHive.API"))
                {
                    // create a DeviceHive network where our gateway will reside
                    var network = new Network("Gateway Sample Network", "A DeviceHive network for Gateway sample");

                    // create gateway service
                    var gatewayService = new GatewayService(deviceService, network);

                    // create connection to device through COM port and add it to the gateway
                    // insert your COM port name here
                    var serialPort = new SerialPort("COM3")
                    {
                        ReadTimeout = 1000, WriteTimeout = 1000
                    };
                    var serialPortConnection = new SerialPortBinaryConnection(serialPort);
                    gatewayService.DeviceConnectionList.Add(serialPortConnection);

                    // start gateway
                    gatewayService.Start();

                    // wait for console key press and then dispose gateway service
                    Console.WriteLine("Gateway is now running, press any key to stop...");
                    Console.ReadKey();
                    gatewayService.Stop();
                }
            }
            catch (Exception ex)
            {
                // handle the error
                Console.WriteLine("Error: " + ex);
                Console.ReadKey();
            }
        }
예제 #3
0
        private static void Main()
        {
            try
            {
                // initialize logger
                log4net.Config.XmlConfigurator.Configure();

                // create a RestfulDeviceService used to communicate with the DeviceHive cloud
                // insert your assigned DeviceHive service URL here
                using (var deviceService = new RestfulDeviceService("http://localhost/DeviceHive.API"))
                {
                    // create a DeviceHive network where our gateway will reside
                    var network = new Network("Gateway Sample Network", "A DeviceHive network for Gateway sample");

                    // create gateway service
                    var gatewayService = new GatewayService(deviceService, network);
                    
                    // create connection to device through COM port and add it to the gateway
                    // insert your COM port name here
                    var serialPort = new SerialPort("COM3") {ReadTimeout = 1000, WriteTimeout = 1000, BaudRate = 9600};
                    var serialPortConnection = new SerialPortBinaryConnection(serialPort);
                    gatewayService.DeviceConnectionList.Add(serialPortConnection);

                    // start gateway
                    gatewayService.Start();

                    // wait for console key press and then dispose gateway service
                    Console.WriteLine("Gateway is now running, press any key to stop...");
                    Console.ReadKey();
                    gatewayService.Stop();
                }
            }
            catch (Exception ex)
            {
                // handle the error
                Console.WriteLine("Error: " + ex);
                Console.ReadKey();
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            try
            {
                // initialize logger
                log4net.Config.XmlConfigurator.Configure();

                // create a RestfulDeviceService used to communicate with the DeviceHive cloud
                // insert your assigned DeviceHive service URL here
                using (var service = new RestfulDeviceService("http://localhost/DeviceHive.API"))
                {
                    // create a DeviceHive network where our device will reside
                    var network = new Network("VirtualLed Sample Network", "A DeviceHive network for VirtualLed sample");
                    // or use network with network key
                    //var network = new Network("Network WPNBEP", "Playground Network", "%NETWORK_KEY%");

                    // create a DeviceHost used to run our device
                    var deviceHost = new DeviceHost(service, network);

                    // create an instance of virtual LED device and add it to the host
                    var led = new VirtualLedDevice();
                    deviceHost.AddDevice(led);

                    // start the host - it will register the device and start polling commands
                    deviceHost.Start();

                    // wait for console key press and then stop the host
                    Console.WriteLine("Device is now running, press any key to stop...");
                    Console.ReadKey();
                    deviceHost.Stop();
                }
            }
            catch (Exception ex)
            {
                // handle the error
                Console.WriteLine("Error: " + ex);
                Console.ReadKey();
            }
        }