示例#1
0
        //车厅4
        private void DealHall4Sound()
        {
            hall4SoundControl = new SoundControl();
            try
            {
                hall4SoundControl.SearchSoundDevice();
            }
            catch (Exception ex)
            {
                CWSException.WriteError("车厅声音SearchSoundDevice异常:" + ex.ToString());
            }
            while (isStart)
            {
                try
                {
                    hall4SoundControl.MakeSound(14, Convert.ToInt32(hall4SoundCom));
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("车厅4声音MakeSound异常:" + ex.ToString());
                    Thread.Sleep(5000);
                }

                if (isStart)
                {
                    Thread.Sleep(1000);
                }
            }
        }
示例#2
0
 /// <summary>
 /// 查找服务器上的声卡设备
 /// </summary>
 public void SearchSoundDevice()
 {
     cycleSoundFile = IEGInterface.Properties.Settings.Default.CycleSound;
     try
     {
         DevicesCollection devColl = new DevicesCollection();
         Form frm = new Form();
         //正常情况下,服务器自带一个声卡设备,故设备号从1开始
         for (int i = 1; i < devColl.Count; i++)
         {
             DeviceInformation info = (DeviceInformation)devColl[i];
             if (string.IsNullOrEmpty(info.ModuleName))
             {
                 continue;
             }
             CWSException.WriteLog("声卡-" + (i - 1).ToString() + "    描述:" + info.Description, 4);
             Guid   Dguid = info.DriverGuid;
             Device dev   = new Device(Dguid);
             dev.SetCooperativeLevel(frm, CooperativeLevel.Normal);
             devs.Add(dev);
         }
     }
     catch (Exception ex)
     {
         CWSException.WriteError(ex.ToString());
     }
 }
示例#3
0
 /// <summary>
 /// 刷卡操作
 /// </summary>
 public void ICCardRead()
 {
     try
     {
         uint ICCardNo = 0;
         if (isConn)
         {
             int   nback   = 1;
             Int16 nICType = 0;
             nback = moICCard.RequestICCard(ref nICType);  //寻卡
             if (nback == 0)
             {
                 nback = moICCard.SelectCard(ref ICCardNo);   //选择卡
                 if (nback == 0)
                 {
                     //将读取的IC卡号传送到Web服务器上
                     Program.mng.DealCardMessage(mHallID, ICCardNo.ToString());
                     //记录
                     CWSException.WriteLog(mHallID.ToString() + "      " + ICCardNo.ToString(), 3);
                 }
             }
         }
         else
         {
             this.ConnectCom();
         }
     }
     catch (Exception ex)
     {
         throw new Exception("函数ICCardRead异常:" + ex.ToString());
     }
 }
示例#4
0
        static void Main()
        {
            mng      = new WSMng();
            TaskList = new List <int>();

            if (sysModel == 1)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new frmTest());
            }
            else if (sysModel == 0)
            {
                //WINDOWS服务启动
                try
                {
                    ServiceBase[] servicesToRun;
                    servicesToRun = new ServiceBase[] { new EqpService() };
                    ServiceBase.Run(servicesToRun);
                }
                catch (Exception ex)
                {
                    try
                    {
                        CWSException.WriteError(ex.ToString());
                    }
                    catch { }
                }
            }
            else
            {
                MessageBox.Show("参数SystemModel需要配置");
            }
        }
示例#5
0
        //消息处理
        private void DealMessage()
        {
            try
            {
                cmsgif.ConnectPLC();
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
                return;
            }

            while (isStart)
            {
                try
                {
                    cmsgif.TaskAssign();
                    cmsgif.ReceiveMessage();
                    cmsgif.SendMessage();
                    cmsgif.DealErrAlarmAndSMGStat();
                    cmsgif.UpdateHallType();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                    Thread.Sleep(2000);
                }

                if (isStart)
                {
                    Thread.Sleep(250);
                }
            }

            try
            {
                cmsgif.DisconnectPLC();
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
        }
示例#6
0
        private void DealRecordLog()
        {
            while (isStart)
            {
                try
                {
                    cmsgif.DealRecordErrLog();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("函数DealRecordLog发生异常:" + ex.ToString());
                    Thread.Sleep(10000);
                }

                if (isStart)
                {
                    Thread.Sleep(1000);
                }
            }
        }
示例#7
0
        //刷卡器1处理
        private void DealH1ICCardAction()
        {
            #region
            try
            {
                icrdOne.ConnectCom();
            }
            catch (Exception ex)
            {
                CWSException.WriteError("车厅刷卡器1连接异常: " + ex.ToString());
            }

            while (isStart)
            {
                try
                {
                    icrdOne.ICCardRead();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("车厅1 " + ex.ToString());
                    Thread.Sleep(10000);
                }
                if (isStart)
                {
                    Thread.Sleep(800);
                }
            }

            try
            {
                icrdOne.DisconnectCom();
            }
            catch (Exception ex)
            {
                CWSException.WriteError("刷卡器1断开异常:" + ex.ToString());
            }
            #endregion
        }
示例#8
0
        private void btnStop_Click(object sender, EventArgs e)
        {
            btnStart.Enabled = true;
            try
            {
                #region
                isStart = false;

                bool isStop = true;
                try
                {
                    isStop = isStop && DealMessageThread.Join(500);
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                }
                try
                {
                    isStop = isStop && ICCardH1Thread.Join(500);
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                }
                try
                {
                    isStop = isStop && ICCardH2Thread.Join(500);
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                }
                try
                {
                    isStop = isStop && ICCardH3Thread.Join(500);
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                }
                try
                {
                    isStop = isStop && ICCardH4Thread.Join(500);
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                }
                try
                {
                    isStop = isStop && SoundH1Thread.Join(500);
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                }
                try
                {
                    isStop = isStop && SoundH2Thread.Join(500);
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                }
                try
                {
                    isStop = isStop && SoundH3Thread.Join(500);
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                }
                try
                {
                    isStop = isStop && SoundH4Thread.Join(500);
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                }
                try
                {
                    isStop = isStop && LogThread.Join(500);
                }
                catch (Exception ex)
                {
                    CWSException.WriteError(ex.ToString());
                }
                //日志
                if (isStop == true)
                {
                    CWSException.WriteLog("服务已经停止!", 4);
                    btnStop.Enabled = false;
                }
                else
                {
                    CWSException.WriteLog("服务未全停止!", 4);
                }

                #endregion
            }
            catch (Exception ex)
            {
                CWSException.WriteError("windows服务停止异常:" + ex.ToString());
            }
        }
示例#9
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (isStart == false)
            {
                try
                {
                    #region
                    isStart = true;
                    cmsgif  = new CMessageInterface();

                    icrdOne   = new ICCardReader(11, Convert.ToInt32(hall1Com));
                    icrdTwo   = new ICCardReader(12, Convert.ToInt32(hall2Com));
                    icrdThree = new ICCardReader(13, Convert.ToInt32(hall3Com));
                    icrdFour  = new ICCardReader(14, Convert.ToInt32(hall4Com));

                    //消息线程
                    try
                    {
                        DealMessageThread = new Thread(new ThreadStart(DealMessage));
                        DealMessageThread.Start();
                    }
                    catch (Exception ex)
                    {
                        CWSException.WriteError("PLC线程启动异常:" + ex.ToString());
                    }

                    //刷卡器1线程
                    try
                    {
                        ICCardH1Thread = new Thread(new ThreadStart(DealH1ICCardAction));
                        ICCardH1Thread.Start();
                    }
                    catch (Exception ex)
                    {
                        CWSException.WriteError("刷卡器1线程启动异常:" + ex.ToString());
                    }

                    //刷卡器2线程
                    try
                    {
                        ICCardH2Thread = new Thread(new ThreadStart(DealH2ICCardAction));
                        ICCardH2Thread.Start();
                    }
                    catch (Exception ex)
                    {
                        CWSException.WriteError("刷卡器2线程启动异常:" + ex.ToString());
                    }

                    //刷卡器3线程
                    try
                    {
                        ICCardH3Thread = new Thread(new ThreadStart(DealH3ICCardAction));
                        ICCardH3Thread.Start();
                    }
                    catch (Exception ex)
                    {
                        CWSException.WriteError("刷卡器3线程启动异常:" + ex.ToString());
                    }

                    //刷卡器4线程
                    try
                    {
                        ICCardH4Thread = new Thread(new ThreadStart(DealH4ICCardAction));
                        ICCardH4Thread.Start();
                    }
                    catch (Exception ex)
                    {
                        CWSException.WriteError("刷卡器4线程启动异常:" + ex.ToString());
                    }

                    //车厅1声音线程
                    try
                    {
                        SoundH1Thread = new Thread(new ThreadStart(DealHall1Sound));
                        SoundH1Thread.Start();
                    }
                    catch (Exception ex)
                    {
                        CWSException.WriteError("车厅1声音线程启动异常:" + ex.ToString());
                    }

                    //车厅2声音线程
                    try
                    {
                        SoundH2Thread = new Thread(new ThreadStart(DealHall2Sound));
                        SoundH2Thread.Start();
                    }
                    catch (Exception ex)
                    {
                        CWSException.WriteError("车厅2声音线程启动异常:" + ex.ToString());
                    }

                    //车厅3声音线程
                    try
                    {
                        SoundH3Thread = new Thread(new ThreadStart(DealHall3Sound));
                        SoundH3Thread.Start();
                    }
                    catch (Exception ex)
                    {
                        CWSException.WriteError("车厅3声音线程启动异常:" + ex.ToString());
                    }

                    //车厅4声音线程
                    try
                    {
                        SoundH4Thread = new Thread(new ThreadStart(DealHall4Sound));
                        SoundH4Thread.Start();
                    }
                    catch (Exception ex)
                    {
                        CWSException.WriteError("车厅4声音线程启动异常:" + ex.ToString());
                    }

                    //故障记录
                    try
                    {
                        LogThread = new Thread(new ThreadStart(DealRecordLog));
                        LogThread.Start();
                    }
                    catch (Exception ex)
                    {
                        CWSException.WriteError("故障记录线程启动异常:" + ex.ToString());
                    }

                    btnStop.Enabled  = true;
                    btnStart.Enabled = false;
                    this.WindowState = FormWindowState.Minimized;
                    #endregion
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("windows服务启动异常:" + ex.ToString());
                }
            }
        }
示例#10
0
        /// <summary>
        /// 发送数据至相应的声卡设备
        /// </summary>
        /// <param name="hallID">车厅号</param>
        /// <param name="soundCom">声卡端口</param>
        public void MakeSound(int hallID, int soundCom)
        {
            try
            {
                if (devs.Count >= soundCom)
                {
                    int idx = hallID - 11;
                    //从Web服务上获取相应车厅的声音文件,待写
                    string soundFile = Program.mng.GetCurrentSound(hallID);
                    //声音归类
                    if (soundFile != null)
                    {
                        hallsSound[idx] = soundFile;   //将各个车厅的声音进行集合
                    }
                    else
                    {
                        if (hallsSound[idx] == null)   //各个车厅没有要播放的声音
                        {
                            return;
                        }
                        //循环播放的声音文件
                        string[] sounds = cycleSoundFile.Split(new char[] { ',' });
                        if (!sounds.Contains(hallsSound[idx].Substring(0, hallsSound[idx].Length - 4)))
                        {
                            return;
                        }
                        else
                        {
                            Thread.Sleep(12000); //循环播放的间隔
                        }
                    }

                    //强制结束语音
                    if (hallsSound[idx] == "end")
                    {
                        hallsSound[idx] = null;
                        return;
                    }
                    try
                    {
                        //播放语音
                        string path = Application.StartupPath + @"\sound\" + hallsSound[idx];
                        if (File.Exists(path))
                        {
                            if (buf != null)
                            {
                                buf.Stop();
                                buf.Dispose();
                                buf = null;
                            }
                            using (BufferDescription desc = new BufferDescription())
                            {
                                desc.Flags = BufferDescriptionFlags.GlobalFocus;
                                buf        = new SecondaryBuffer(path, desc, devs[soundCom]); //向指定声卡号soundCom播放语音
                                buf.Play(0, BufferPlayFlags.Default);

                                CWSException.WriteLog(hallID.ToString() + "      " + "声卡-" + soundCom.ToString() + "    语音:" + hallsSound[idx], 2);
                                Thread.Sleep(1000);
                            }
                        }
                        else
                        {
                            CWSException.WriteError("缺少音频文件:" + path);
                        }
                    }
                    catch (Exception e1)
                    {
                        string mess = "异常1:" + e1.ToString();
                        try
                        {
                            buf.Dispose();
                            buf = null;
                        }
                        catch (Exception e2)
                        {
                            mess += "     异常2:" + e2.ToString();
                        }
                        throw new Exception(mess);
                    }
                }
            }
            catch (Exception ex)
            {
                CWSException.WriteError("车厅-" + hallID.ToString() + "  发声时异常:" + ex.ToString());
            }
        }
示例#11
0
        protected override void OnStart(string[] args)
        {
            if (isStart == false)
            {
                #region
                isStart = true;
                cmsgif  = new CMessageInterface();

                icrdOne   = new ICCardReader(11, Convert.ToInt32(hall1Com));
                icrdTwo   = new ICCardReader(12, Convert.ToInt32(hall2Com));
                icrdThree = new ICCardReader(13, Convert.ToInt32(hall3Com));
                icrdFour  = new ICCardReader(14, Convert.ToInt32(hall4Com));

                //消息线程
                try
                {
                    DealMessageThread = new Thread(new ThreadStart(DealMessage));
                    DealMessageThread.Start();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("PLC线程启动异常:" + ex.ToString());
                }

                //刷卡器1线程
                try
                {
                    ICCardH1Thread = new Thread(new ThreadStart(DealH1ICCardAction));
                    ICCardH1Thread.Start();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("刷卡器1线程启动异常:" + ex.ToString());
                }

                //刷卡器2线程
                try
                {
                    ICCardH2Thread = new Thread(new ThreadStart(DealH2ICCardAction));
                    ICCardH2Thread.Start();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("刷卡器2线程启动异常:" + ex.ToString());
                }

                //刷卡器3线程
                try
                {
                    ICCardH3Thread = new Thread(new ThreadStart(DealH3ICCardAction));
                    ICCardH3Thread.Start();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("刷卡器3线程启动异常:" + ex.ToString());
                }

                //刷卡器4线程
                try
                {
                    ICCardH4Thread = new Thread(new ThreadStart(DealH4ICCardAction));
                    ICCardH4Thread.Start();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("刷卡器4线程启动异常:" + ex.ToString());
                }

                //车厅1声音线程
                try
                {
                    SoundH1Thread = new Thread(new ThreadStart(DealHall1Sound));
                    SoundH1Thread.Start();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("车厅1声音线程启动异常:" + ex.ToString());
                }

                //车厅2声音线程
                try
                {
                    SoundH2Thread = new Thread(new ThreadStart(DealHall2Sound));
                    SoundH2Thread.Start();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("车厅2声音线程启动异常:" + ex.ToString());
                }

                //车厅3声音线程
                try
                {
                    SoundH3Thread = new Thread(new ThreadStart(DealHall3Sound));
                    SoundH3Thread.Start();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("车厅3声音线程启动异常:" + ex.ToString());
                }

                //车厅4声音线程
                try
                {
                    SoundH4Thread = new Thread(new ThreadStart(DealHall4Sound));
                    SoundH4Thread.Start();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("车厅4声音线程启动异常:" + ex.ToString());
                }

                //故障记录
                try
                {
                    LogThread = new Thread(new ThreadStart(DealRecordLog));
                    LogThread.Start();
                }
                catch (Exception ex)
                {
                    CWSException.WriteError("故障记录线程启动异常:" + ex.ToString());
                }

                CWSException.WriteLog("服务已经启动!", 4);
                #endregion
            }
        }
示例#12
0
        protected override void OnStop()
        {
            #region
            isStart = false;

            bool isStop = true;
            try
            {
                isStop = isStop && DealMessageThread.Join(500);
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
            try
            {
                isStop = isStop && ICCardH1Thread.Join(500);
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
            try
            {
                isStop = isStop && ICCardH2Thread.Join(500);
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
            try
            {
                isStop = isStop && ICCardH3Thread.Join(500);
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
            try
            {
                isStop = isStop && ICCardH4Thread.Join(500);
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
            try
            {
                isStop = isStop && SoundH1Thread.Join(500);
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
            try
            {
                isStop = isStop && SoundH2Thread.Join(500);
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
            try
            {
                isStop = isStop && SoundH3Thread.Join(500);
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
            try
            {
                isStop = isStop && SoundH4Thread.Join(500);
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
            try
            {
                isStop = isStop && LogThread.Join(500);
            }
            catch (Exception ex)
            {
                CWSException.WriteError(ex.ToString());
            }
            //日志
            if (isStop == true)
            {
                CWSException.WriteLog("服务已经停止!", 4);
            }
            else
            {
                CWSException.WriteLog("服务未全停止!", 4);
            }

            #endregion
        }