Example #1
0
        public static void ConnectDevice(BluetoothDeviceInfo device, string devicePin)
        {
            // set pin of device to connect with
            if (devicePin != null)
            {
                LocalClient.SetPin(devicePin);
            }

            // check if device is paired
            if (device.Authenticated)
            {
                // synchronous connection method
                LocalClient.Connect(device.DeviceAddress, BluetoothService.SerialPort);
                if (LocalClient.Connected)
                {
                    _stream             = LocalClient.GetStream();
                    _stream.ReadTimeout = 500;
                }
            }
        }
        public LiveVisualization()
        {
            InitializeComponent();

            DatabaseOperation.Connect();

            SqlDataReader reader = DatabaseOperation.SelectQuery("SELECT * FROM Zone WHERE ZoneId='Zone1'");

            while (reader.Read())
            {
                Message1.ZoneId    = reader.GetString(0);
                Message1.ZoneName  = reader.GetString(1);
                zoneLocationFromDB = reader.GetString(2);
            }
            reader.Close();
            DatabaseOperation.Disconnect();

            //zone1 area
            zone1 = new LocationCollection();
            List <MyLocation> zoneLocation = new List <MyLocation>();

            string[] zoneLoc = zoneLocationFromDB.Split('|');
            for (int i = 0; i < 5; i++)
            {
                string[] collection = zoneLoc[i].Split(',');
                Location l          = new Location(Convert.ToDouble(collection[0]), Convert.ToDouble(collection[1]));
                zone1.Add(l);


                MyLocation ml = new MyLocation(Convert.ToDouble(collection[0]), Convert.ToDouble(collection[1]));
                zoneLocation.Add(ml);

                if (i == 0)
                {
                    ll  = l;
                    ml1 = ml;
                }
            }
            zone1.Add(ll);
            zoneLocation.Add(ml1);
            Message1.ZoneLocation = zoneLocation;

            //rain sensor1
            rl1         = new Location(21.1843465, 72.8080135);
            rl2         = new Location(21.183261, 72.805444);
            rl3         = new Location(21.180415, 72.807622);
            rl4         = new Location(21.180685, 72.809339);
            rl5         = new Location(21.1820105, 72.8115755);
            rl6         = new Location(21.1843465, 72.8080135);
            zone1_rain1 = new LocationCollection();
            zone1_rain1.Add(rl1);
            zone1_rain1.Add(rl2);
            zone1_rain1.Add(rl3);
            zone1_rain1.Add(rl4);
            zone1_rain1.Add(rl5);
            zone1_rain1.Add(rl6);

            //rain sensor2
            r1l1        = new Location(21.1843465, 72.8080135);
            r1l2        = new Location(21.1820105, 72.8115755);
            r1l3        = new Location(21.183336, 72.813812);
            r1l4        = new Location(21.185432, 72.810583);
            r1l5        = new Location(21.1843465, 72.8080135);
            zone1_rain2 = new LocationCollection();
            zone1_rain2.Add(r1l1);
            zone1_rain2.Add(r1l2);
            zone1_rain2.Add(r1l3);
            zone1_rain2.Add(r1l4);
            zone1_rain2.Add(r1l5);



            //for main server client
            Client_main.Connect(@"172.16.0.12", 9001);


            //creation of msg1 object

            Message1.Fire_Location = new MyLocation(21.182782, 72.808912);

            //for rain1 location,creation of message class
            List <MyLocation> rain1Location = new List <MyLocation>();

            rain1Location.Add(new MyLocation(21.1843465, 72.8080135));
            rain1Location.Add(new MyLocation(21.183261, 72.805444));
            rain1Location.Add(new MyLocation(21.180415, 72.807622));
            rain1Location.Add(new MyLocation(21.180685, 72.809339));
            rain1Location.Add(new MyLocation(21.1820105, 72.8115755));
            rain1Location.Add(new MyLocation(21.1843465, 72.8080135));
            Message1.Rain1_Location = rain1Location;

            //for rain2 location,creation of message class
            List <MyLocation> rain2Location = new List <MyLocation>();

            rain2Location.Add(new MyLocation(21.1843465, 72.8080135));
            rain2Location.Add(new MyLocation(21.1820105, 72.8115755));
            rain2Location.Add(new MyLocation(21.183336, 72.813812));
            rain2Location.Add(new MyLocation(21.185432, 72.810583));
            rain2Location.Add(new MyLocation(21.1843465, 72.8080135));
            Message1.Rain2_Location = rain2Location;


            currentDate  = DateTime.Now;
            tempSensorId = "temp1";
            presSensorId = "pres1";
            humSensorId  = "humidity1";
            zoneId       = "zone1";

            Lib.Communication.DataReceivedEventHandler += CommunicationPort_DataReceivedEventHandler;
            NewMap          = new MyMap(myMap, MapKey);
            myMap.Center    = new Location(21.182782, 72.808912);
            myMap.ZoomLevel = 17;
            myMap.Focus();
        }
 private void ConnectClientToServerAndCheckState(LocalClient client, LocalServer server)
 {
     client.Connect(server.Address);
     Assert.IsTrue(client.IsConnected);
 }