public static CommunicationInstance getInstance() { if (instance == null) { instance = new CommunicationInstance(); return instance; } return instance; }
public static CommunicationInstance getInstance() { if (instance == null) { instance = new CommunicationInstance(); return(instance); } return(instance); }
public static bool searchGunStatus() { Communication comm = CommunicationInstance.getInstance().getCommunication(); char[] cc = null; char[] data1 = { '\x02', '0', 'A', '0', '0', '2', '0', 'D', 'A', 'T', 'A', '6', '3', '\x03', '\x0D' }; comm.send_message(Port.Get_ComGun(), data1); cc = comm.getAlarmCC(); //System.Windows.Forms.MessageBox.Show(cc[7].ToString()); if (cc[7] == '0') { return(false); } else { return(true); } //return true; }
/// <summary> /// 同步枪柜信息 /// </summary> /// <param name="guanrk_ip"></param> public static void syn_gunark_info(string guanrk_ip) { BLL.gunark gunark_bll = new Gunark.BLL.gunark(); WebService.gunServices webService = SingleWebService.getWebService(); WebService.gunArk gunark_syn = webService.getGunarkInfo(guanrk_ip); if (gunark_syn != null) { Model.gunark gunark = new Gunark.Model.gunark(); gunark.GUNARK_ID = gunark_syn.gunarkId; gunark.GUNARK_IP = gunark_syn.gunarkIp; gunark.GUNARK_ENTERTIME = gunark_syn.enterTime.ToString(); gunark.GUNARK_GATEWAY = gunark_syn.gunarkGateway; gunark.GUNARK_SUBNET = gunark_syn.gunarkSubnet; gunark.GUNARK_TYPE = gunark_syn.gunarkType; gunark.GUNARK_NAME = gunark_syn.gunarkName; gunark.GUNARK_NUMOFGUN = gunark_syn.numOfGun; gunark.GUNARK_NUMOFBULLETWAREHOUSE = gunark_syn.numOfBulletWarehouse; gunark.UNITINFO_CODE = gunark_syn.unitInfo.unitInfoCode; gunark.GUNARK_STATUS = gunark_syn.gunarkStatus; if (!gunark_bll.Exists(gunark_syn.gunarkId)) { Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); cfa.AppSettings.Settings["gunark_id"].Value = gunark.GUNARK_ID; cfa.AppSettings.Settings["unit_id"].Value = gunark.UNITINFO_CODE; cfa.Save(); ConfigurationManager.RefreshSection("appSettings"); ConfigurationManager.RefreshSection("appSettings"); gunark_bll.Add(gunark); //使能弹柜 Communication comm = CommunicationInstance.getInstance().getCommunication(); comm.enableBullet(); } else { gunark_bll.Update(gunark); } } }
/// <summary> /// 控制柜子公共类 /// </summary> /// <param name="task_info">任务对象</param> /// <param name="gun_number">枪位号集合</param> /// <param name="magazine_number">弹仓号集合</param> /// <returns></returns> public static bool control(Model.task_info task_info, byte[] gun_number, byte[] magazine_number) { Communication comm = CommunicationInstance.getInstance().getCommunication(); //WebService接口调用工具 WebService.gunServices webService = SingleWebService.getWebService(); if (gun_number.Length > 0 || task_info.task_BigType == 14) { //标识发完开门指令后多少秒还未开门 int count = 0; //开枪柜门(枪支封存解封不开柜门) if (task_info.task_BigType != 4 && task_info.task_BigType != 10) { comm.send_message(Port.Get_ComGun(), Communication.open); } //枪支封存 if (task_info.task_BigType == 4) { PlaySound.paly(Properties.Resources._29); return(true); } //枪支解封 if (task_info.task_BigType == 10) { PlaySound.paly(Properties.Resources._30); return(true); } //语音提示 PlaySound.paly(Properties.Resources._9); //如果柜门已经打开,再发解锁枪位指令 while (PubFlag.gunark_control_isAile) { //将此循环设置为1秒执行一次,判断25秒之后还未将门打开,此时柜门已重新锁上 //查询枪柜门状态 bool gunDoorStatus = SearchDoorStatus.searchGunStatus(); System.Threading.Thread.Sleep(1000); count++; if (count > 20) { return(false); } //判断枪柜门是否已经打开 if (gunDoorStatus) { GunarkDoorStatus gds = new GunarkDoorStatus(task_info, gun_number, magazine_number); gds.pictureBox1.Image = Properties.Resources.gun_open; gds.pictureBox2.Image = Properties.Resources.openDoor; gds.Flag = 1; //gds.openBackgroundWorker(); gds.ShowDialog(); break; } } ////判断是否已经关闭枪柜门,检测关闭枪柜门之后再开启弹柜门 //while (PubFlag.gunark_control_isAile) //{ // //查询枪柜门状态 // bool doorStatus = SearchDoorStatus.searchGunStatus(); // System.Threading.Thread.Sleep(1000); // //////假设已经关闭枪柜门,测试用,以后要删除下边这行代码 // ////doorStatus = false; // //if (!doorStatus) // if (true) // { // GunarkDoorStatus gds = new GunarkDoorStatus(task_info, gun_number, magazine_number); // gds.pictureBox1.Image = Properties.Resources.gun_close; // gds.pictureBox2.Image = Properties.Resources.closeDoor; // gds.Flag = 2; // gds.openBackgroundWorker(); // gds.ShowDialog(); // break; // } //} } //结束取枪后,判断是否有子弹,若有在进行下面对弹柜的操作 if (magazine_number.Length > 0) { //开弹柜门 //comm.send_message(Port.Get_ComBullet(), Communication.open); //语音提示 PlaySound.paly(Properties.Resources._10); //如果弹柜门已打开,再发弹开弹仓指令 while (PubFlag.gunark_control_isAile) { //查询弹柜门状态 //bool bulletDoorStatus = SearchDoorStatus.searchBulletStatus(); System.Threading.Thread.Sleep(1000); //判断弹柜门是否已经打开(假设已经打开) //if (bulletDoorStatus) if (true) { GunarkDoorStatus gds = new GunarkDoorStatus(task_info, gun_number, magazine_number); gds.pictureBox1.Image = Properties.Resources.bullet_open; gds.pictureBox2.Image = Properties.Resources.openDoor; gds.Flag = 3; //gds.openBackgroundWorker(); gds.ShowDialog(); break; } } /////判断弹柜门是否已经关闭 //while (PubFlag.gunark_control_isAile) //{ // //查询弹柜门状态 // //bool doorStatus = SearchDoorStatus.searchBulletStatus(); // System.Threading.Thread.Sleep(1000); // ////假设应经关闭 // //if (!doorStatus) // if(true) // { // GunarkDoorStatus gds = new GunarkDoorStatus(task_info, gun_number, magazine_number); // gds.pictureBox1.Image = Properties.Resources.bullet_close; // gds.pictureBox2.Image = Properties.Resources.closeDoor; // gds.Flag = 4; // gds.openBackgroundWorker(); // gds.ShowDialog(); // break; // } //} } return(true); }