Пример #1
0
 //lenh lay hinh anh
 private void btTakephoto_Click(object sender, System.EventArgs e)
 {
     try
     {
         Database myDatabase = new Database();
         int now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
         InformationNode.timeDapUng.Remove(sensor.Mac);
         InformationNode.timeDapUng.Add(sensor.Mac, now);
         sensor.Mac = cbnodeImg.Text.Substring(7, 2);
         if (sensor.Mac[0] == '0')
         {
             sensor.Ip = myDatabase.getNetworkIpSensor(sensor.Mac);
         }
         else
         {
             sensor.Ip = myDatabase.getNetworkIpSensorBC(sensor.Mac);
         }
         sensor.Command = sensor.Ip + "444$";    //lenh chup anh o sensor.Ip
         byte[] commandbyte = comPort.ConvertTobyte(sensor.Command);
         comPort.DisplayData("(" + comPort.showTime() + "): Gui lenh chup anh!! (" + sensor.Mac + "):\r\n Ma lenh : " + commandbyte.ToString(), tbShow2);
         comPort.writeByteData(commandbyte);
     }
     catch
     {
         MessageBox.Show("Ban chua nhap thong tin node", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
     }
 }
Пример #2
0
        /// <summary>
        /// Su kien khi kich nut gui (send) lenh tren giao dien xuong actor
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btSend_Click(object sender, EventArgs e)
        {
            try
            {
                Database myDatabase = new Database();
                int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
               
                if (cbMalenh.SelectedIndex == 0)
                {
                    sensor.Mac = cbnode.Text.Substring(7, 2);
                    int now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                    ImformationNode.timeDapUng.Remove(sensor.Mac);
                    ImformationNode.timeDapUng.Add(sensor.Mac,now);
                    if (sensor.Mac[0] == '0')
                    {
                        sensor.Ip = myDatabase.getNetworkIpSensor(sensor.Mac);
                    }
                    else
                    {
                        sensor.Ip = myDatabase.getNetworkIpSensorBC(sensor.Mac);
                    }
                    sensor.Command = sensor.Ip + "000$";
                    comPort.DisplayData("(" + comPort.showTime()+ "): Gui lenh lay du lieu sensor (" + sensor.Mac + "):\r\n Ma lenh : " + sensor.Command, tbShow);
                    if (sensor.Command.Length == 8)
                    {
                        cbMalenh.SelectedIndex = -1;
                        cbnode.Items.Clear();
                        cbnode.Text = "";
                        byte[] commandbyte = comPort.ConvertTobyte(sensor.Command);
                        comPort.writeByteData(commandbyte);
                    }
                }
                else if (cbMalenh.SelectedIndex == 16)  //lenh lay dia chi sensor canh thiet bi android
                {
                    int now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                    ImformationNode.timeDapUng.Remove(sensor.Mac);
                    ImformationNode.timeDapUng.Add(sensor.Mac, now);
                    sensor.Mac = cbMalenh.SelectedItem.ToString();
                    //sensor.Command = "FFFF333$";
                    //byte[] commandbyte = comPort.ConvertTobyte(sensor.Command);   //ham khong dung de chuyen doi kieu lenh nay
                    byte[] commandbyte = {0xFF,0xFF,3,3,3};
                    comPort.DisplayData("(" + comPort.showTime() + "): Gui lenh dia chi MAC cac Node lan can Node (" + sensor.Mac + "):\r\n Ma lenh : " + commandbyte.ToString(), tbShow);
                    comPort.writeByteData(commandbyte);
                }
                else if (cbMalenh.SelectedIndex == 17)  //lenh lay hinh anh
                {
                    int now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                    ImformationNode.timeDapUng.Remove(sensor.Mac);
                    ImformationNode.timeDapUng.Add(sensor.Mac, now);
                    sensor.Mac = cbMalenh.SelectedItem.ToString();
                    //sensor.Command = "FFFF444$";
                    //byte[] commandbyte = comPort.ConvertTobyte(sensor.Command);   //ham khong dung de chuyen doi kieu lenh nay
                    byte[] commandbyte = { 0xFF, 0xFF, 4, 4, 4};
                    comPort.DisplayData("(" + comPort.showTime() + "): Gui lenh dia chi MAC cac Node lan can Node (" + sensor.Mac + "):\r\n Ma lenh : " + commandbyte.ToString(), tbShow);
                    comPort.writeByteData(commandbyte);
                }
                else
                {
                    actor.Ip = myDatabase.getNetworkIpActor(actor.Mac);
                    int now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
                    ImformationNode.timeDapUng.Remove(actor.Mac);
                    ImformationNode.timeDapUng.Add(actor.Mac, now);
                    int id = cbMalenh.SelectedIndex;
                    if (id < 8)
                    {
                        if (id == 7)
                        {
                            actor.Command = actor.commandOnActor(15, "0000");
                            comPort.DisplayData("(" + comPort.showTime() + "): Bat tat ca cac van:\r\n Ma lenh : " + actor.Command, tbShow);
                        }
                        else
                        {
                            actor.Command = actor.commandOnActor(id, "0000");
#if ACTOR_BAOCHAY
                            comPort.DisplayData("(" + comPort.showTime() + "): Gui canh bao muc " + id + ":\r\n Ma lenh : " + actor.Command, tbShow);

#else
                            comPort.DisplayData("(" + comPort.showTime() + "): Bat van so " + id + ":\r\n Ma lenh : " + actor.Command, tbShow);
#endif

                        }
                    }
                    else
                    {
                        int vanoff = id - 7;
                        if (vanoff == 7)
                        {
                            actor.Command = actor.commandOffActor(15, "0000");
                            comPort.DisplayData("(" + comPort.showTime() + "): Tat tat ca cac van:\r\n Ma lenh : " + actor.Command, tbShow);
                        }
                        else
                        {
                            actor.Command = actor.commandOffActor(vanoff, "0000");
                            comPort.DisplayData("(" + comPort.showTime() + "): Tat van so " + vanoff + ":\r\n Ma lenh : " + actor.Command, tbShow);

                        }

                    }
                    if (actor.Command.Length == 8)
                    {
                        cbMalenh.SelectedIndex = -1;
                        cbnode.Items.Clear();
                        cbnode.Text = "";
                        byte[] commandbyte = comPort.ConvertTobyte(actor.Command);
                        comPort.writeByteData(commandbyte);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Ban chua chon du thong tin o Commnad hoac Node", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
        }
 private void btSend_Click(object sender, EventArgs e)
 {
     try
     {
         Database myDatabase = new Database();
         int timenow = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second;
         if (cbMalenh.SelectedIndex == 0)
         {
             mac = cbnode.Text.Substring(7, 2);
             comPort.timeDapung.Remove(mac);
             comPort.timeDapung.Add(mac, timenow);
             if (mac[0] == '0')
             {
                 network_ip = myDatabase.getNetworkIpSensor(mac);
             }
             #if USE_DATABC
             else
             {
                 network_ip = myDatabase.getNetworkIpSensorBC(mac);
             }
             #endif
             command = network_ip + "000$";
             comPort.DisplayData("(" + DateTime.Now + "): Gui lenh lay du lieu sensor (" + mac+ "):\r\n Ma lenh : " + command, tbShow);
         }
         else
         {
             //mac = cbnode.Text.Substring(6, 2);
             network_ip = myDatabase.getNetworkIpActor(mac_actor);
             comPort.timeDapung.Remove(mac_actor);
             comPort.timeDapung.Add(mac_actor, timenow);
             switch (cbMalenh.SelectedIndex)
             {
                 case 1:
                     command = network_ip + "011$";
                     if (mac_actor == "00")
                     {
                         comPort.DisplayData("(" + DateTime.Now + "):Gui lenh bat van so 1\r\nMa lenh:" + command, tbShow);
                     }
                     else
                     {
                         comPort.DisplayData("(" + DateTime.Now + "): Gui lenh bat canh bao muc 1\r\nMa lenh:" + command, tbShow);
                     }
                     break;
                 case 2:
                     command = network_ip + "021$";
                     if (mac_actor == "00")
                     {
                         comPort.DisplayData("(" + DateTime.Now + "):Gui lenh bat van so 2\r\nMa lenh:" + command, tbShow);
                     }
                     else
                     {
                         comPort.DisplayData("(" + DateTime.Now + "): Gui lenh bat canh bao muc 2\r\nMa lenh:" + command, tbShow);
                     }
                     break;
                 case 3:
                     command = network_ip + "031$";
                     if (mac_actor == "00")
                     {
                         comPort.DisplayData("(" + DateTime.Now + "):Gui lenh bat van so 3\r\nMa lenh:" + command, tbShow);
                     }
                     else
                     {
                         comPort.DisplayData("(" + DateTime.Now + "): Gui lenh bat canh bao muc 3\r\nMa lenh:" + command, tbShow);
                     }
                     break;
                 case 4:
                     command = network_ip + "041$";
                     if (mac_actor == "00")
                     {
                         comPort.DisplayData("(" + DateTime.Now + "):Gui lenh bat van so 4\r\nMa lenh:" + command, tbShow);
                     }
                     else
                     {
                         comPort.DisplayData("(" + DateTime.Now + "): Gui lenh bat canh bao muc 4\r\nMa lenh:" + command, tbShow);
                     }
                     break;
                 case 5:
                     command = network_ip + "051$";
                     if (mac_actor == "00")
                     {
                         comPort.DisplayData("(" + DateTime.Now + "):Gui lenh bat van so 5\r\nMa lenh:" + command, tbShow);
                     }
                     else
                     {
                         comPort.DisplayData("(" + DateTime.Now + "): Gui lenh bat canh bao muc 5\r\nMa lenh:" + command, tbShow);
                     }
                     break;
                 case 6:
                     command = network_ip + "061$";
                     comPort.DisplayData("(" + DateTime.Now + "):Gui lenh bat van so 6\r\nMa lenh:" + command, tbShow);
                     
                     break;
                 case 7:
                     command = network_ip + "151$";
                     comPort.DisplayData("(" + DateTime.Now + "):Bat tat ca cac van\r\nMa lenh:" + command, tbShow);
                     break;
                 case 8:
                     command = network_ip + "010$";
                     comPort.DisplayData("(" + DateTime.Now + "):Gui lenh tat van so 1\r\nMa lenh:" + command, tbShow);
                     break;
                 case 9:
                     command = network_ip + "020$";
                     comPort.DisplayData("(" + DateTime.Now + "):Gui lenh tat van so 2\r\nMa lenh:" + command, tbShow);
                     break;
                 case 10:
                     command = network_ip + "030$";
                     comPort.DisplayData("(" + DateTime.Now + "):Gui lenh tat van so 3\r\nMa lenh:" + command, tbShow);
                     break;
                 case 11:
                     command = network_ip + "040$";
                     comPort.DisplayData("(" + DateTime.Now + "):Gui lenh tat van so 4\r\nMa lenh:" + command, tbShow);
                     break;
                 case 12:
                     command = network_ip + "050$";
                     comPort.DisplayData("(" + DateTime.Now + "):Gui lenh tat van so 5\r\nMa lenh:" + command, tbShow);
                     break;
                 case 13:
                     command = network_ip + "060$";
                     comPort.DisplayData("(" + DateTime.Now + "):Gui lenh tat van so 6\r\nMa lenh:" + command, tbShow);
                     
                     break;
                 case 14:
                     command = network_ip + "150$";
                     comPort.DisplayData("(" + DateTime.Now + "):Gui lenh tat tat ca cac van\r\nMa lenh:" + command, tbShow);
                     
                     break;
             }
             
         }
         
        
         cbMalenh.SelectedIndex = -1;
         cbnode.Items.Clear();
         cbnode.Text = "";
         if (command.Length == 8)
         {
             commandbyte = comPort.ConvertTobyte(command);
             comPort.WriteData(commandbyte);
         }
     }
     catch 
     {
         MessageBox.Show("Ban chua chon du thong tin o Commnad hoac Node", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
     }
 }