コード例 #1
0
        private void SendToBoard(string messageData)
        {
            LogBook.Write("Enter send to board method");
            //to communicate using TCP/IP
            NetworkClient client = new NetworkClient();
            //to communicate using serial port
            IOPort ioPort = new IOPort();

            if (_isNetworkAttached)
            {
                //send message to message board using TCP/IP
                //client.TcpClient(_ipAddress, _port, messageData);
            }
            else
            {
                string[]           settingsArray = _commSettings.Split(',');
                IOPort.ComSettings commSettings  = new IOPort.ComSettings();
                commSettings.BaudRate  = settingsArray[0].ToInt();
                commSettings.ParityBit = Parity.None;
                commSettings.DataBits  = settingsArray[3].ToInt16();
                commSettings.StopBit   = StopBits.One;

                ioPort.Handshake(_port.ToString(), commSettings, DataRecievedFromCom);
                ioPort.SerialPortOutput(messageData);

                //send message to message board using serial port
                //ioPort.SerialPort(_port.ToString(),commSettings, messageData,null);
            }
            LogBook.Write("Message sent to message board.");
            LogBook.Write("Exit send to board method");
        }
コード例 #2
0
        public void WriteBytes(byte[] data)
        {
            //create instance for the TCP/IP and Serial port classes
            NetworkClient client  = new NetworkClient(); //for TCP
            IOPort        comPort = new IOPort();        //for COMM port

            //get the comm settings for the connection
            string[]           settingsArray = _commSettings.Split(',');
            IOPort.ComSettings commSettings  = new IOPort.ComSettings();
            commSettings.BaudRate  = settingsArray[0].ToInt();
            commSettings.ParityBit = Parity.Even;
            commSettings.DataBits  = settingsArray[2].ToInt16();
            commSettings.StopBit   = StopBits.One;
            try
            {
                //if the device is attached to network
                if (_isNetworkAttached)
                {
                    //send data using TCP/IP
                    client.TcpClient(_ipAddress, _port, data);
                }
                else
                {
                    //send data using Serial port
                    LogBook.Write(this.SensorFactoryID + " " + this.SensorAlarmID + " " + "Sending data using UDP Port: " + _port.ToString());
                    comPort.Handshake("COM" + _port.ToString(), commSettings, DataRecievedFromCom);
                    comPort.SerialPortOutput(data);
                }
            }
            catch (Exception ex)
            {
                LogBook.Write(ex, this.SensorFactoryID + " " + this.SensorAlarmID + " " + "NotifyEngine-MessageBoard");
                throw ex;
            }
        }
コード例 #3
0
        /// <summary>
        /// Send Mail
        /// </summary>
        /// <returns></returns>
        public NotifyComResponse Send(INotifyObject notifyObject)
        {
            notifyComResponse = new NotifyComResponse();
            try
            {
                _snppServer     = notifyObject.NotifierSettings["SNPPServer"].ToStr();
                _snppPort       = notifyObject.NotifierSettings["SNPPPort"].ToInt();
                _pagerSubject   = notifyObject.NotifierSettings["PagerSubject"].ToStr();
                _pagerToAddress = notifyObject.NotifierSettings["ToAddress"].ToStr();
                _name           = notifyObject.NotifierSettings["Name"].ToStr();
                _pagerBody      = notifyObject.NotificationData.ToStr();



                /*Send notification to Pager using SNPP Server*/
                try
                {
                    if (notifyObject.NotifierSettings["DeliveryMethod"].ToInt() != 1)
                    {
                        string phone        = notifyObject.NotifierSettings["ToAddress"].ToStr();
                        int    pagerDelay   = notifyObject.NotifierSettings["PagerDelay"].ToInt();
                        string pagerMessage = notifyObject.NotifierSettings["PagerMessage"].ToStr();
                        string comPortId    = notifyObject.NotifierSettings["PagerComPort"].ToStr();

                        Int16 attemptCount = notifyObject.NotifierSettings["AttemptCount"].ToInt16();
                        attemptCount++;
                        notifyObject.NotifierSettings["AttemptCount"] = attemptCount;
                        notifyObject.NotifierSettings["LastSentTime"] = DateTime.Now;

                        Message = " Attempt: " + attemptCount.ToString();

                        sendPageTime = DateTime.Now;

                        /*
                         * "2400,n,8,1"
                         * 1st baud rate
                         * 2nd parity
                         * 3rd data bits
                         * 4th stop bit*/


                        IOPort.ComSettings comSettings = new IOPort.ComSettings();
                        comSettings.BaudRate  = 2400;
                        comSettings.ParityBit = System.IO.Ports.Parity.Even;
                        comSettings.DataBits  = 8;
                        comSettings.StopBit   = System.IO.Ports.StopBits.One;



                        int n = 0;
                        //COMcmds[n++] = "1~+~.1";
                        //COMcmds[n++] = ".3~+~.1";
                        //COMcmds[n++] = ".3~+~.1";

                        //COMcmds[n++] = ".5~ATH~3";          // Hang-up if connected
                        COMcmds[n++] = ".5~ATH~3";          // Hang-up if connected
                        COMcmds[n++] = ".5~ATZ~3";          // Reset modem
                        COMcmds[n++] = ".5~ATL0M0~3";       // Disable modem speaker / sounds
                        COMcmds[n++] = ".5~ATE0~3";         //Turn off echoing

                        if (notifyObject.NotifierSettings["COMportInitString"].ToStr().Length > 0)
                        {
                            COMcmds[n++] = ".5~" + notifyObject.NotifierSettings["COMportInitString"].ToStr() + "~1";
                        }

                        //If Len(InitString) Then COMcmds[n] = ".5~" & InitString & "~1";
                        COMcmds[n++] = ".5~ATDT" + phone + new System.Text.StringBuilder().Append(',', pagerDelay).ToString() + pagerMessage + "~40";
                        //COMcmds[n++] = "0~+~.1";
                        //COMcmds[n++] = ".3~+~.1";
                        //COMcmds[n++] = ".3~+~.1";
                        COMcmds[n++] = ".5~ATH~3";
                        nCOMcmds     = n;

                        comPort = new IOPort();//for COMM port


                        //ping the com port
                        comPort.Handshake("COM" + comPortId, comSettings, DataRecieveFromCom);


                        SendCommand();
                    }
                    else
                    {
                        //snnpObj = new KTGUtil.SNPP();
                        using (SNPPWrapper snppObj = new SNPPWrapper())
                        {
                            /*SNPP Host*/
                            snppObj.Host = _snppServer;

                            /*SNPP Port Number*/
                            snppObj.Port = _snppPort;

                            /*Subject*/
                            snppObj.Subject = _pagerSubject;

                            /*Body*/
                            snppObj.Body = _pagerBody;

                            /*Pager To Address*/
                            snppObj.SendTo = _pagerToAddress;

                            /*Send information to pager*/
                            int res = snppObj.Send();
                            ProcessCompleted = true;



                            if (res == 0)
                            {
                                /*Record notify response*/
                                notifyComResponse.IsError         = false;
                                notifyComResponse.IsSucceeded     = true;
                                notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", sent successfully.";
                            }
                            else
                            {
                                notifyComResponse.IsError         = true;
                                notifyComResponse.IsSucceeded     = false;
                                notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Error:." + snppObj.LastErrorText;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    /*Record notify response*/
                    notifyComResponse.IsError         = true;
                    notifyComResponse.IsSucceeded     = false;
                    notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Failed.";
                    Message         += "Page to [" + _name + "] " + _pagerToAddress + ", Failed (" + ex.Message + ").";
                    ProcessCompleted = true;
                    /*Debug Object values for reference*/
                    LogBook.Debug(notifyComResponse, this);

                    /*Write exception log*/
                    LogBook.Write("Error has occurred while sending pager to ." + _pagerToAddress, ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper");
                }
            }
            catch (Exception ex)
            {
                /*Record notify response*/
                notifyComResponse.IsError         = true;
                notifyComResponse.IsSucceeded     = true;
                notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Failed.";
                Message         += "Page to [" + _name + "] " + _pagerToAddress + ", Failed (" + ex.Message + ").";
                ProcessCompleted = true;
                /*Debug Object values for reference*/
                LogBook.Debug(notifyComResponse, this);

                /*Write exception log*/
                LogBook.Write("Error has occurred while preparing SNPP setting.", ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper");
            }
            return(notifyComResponse);
        }