Esempio n. 1
0
        public static void SendCommand(Interface.ICommunicationChannel CommsChannel, ICBusCommand Command)
        {
            //Send Data, APPEND Telnet Flush characters
            var command      = Command.ToCBusString() + "\r\n";
            var commandBytes = CharacterEncoding.GetBytes(command);

            CommsChannel.SendBytes(commandBytes, commandBytes.Length);
        }
Esempio n. 2
0
        /// <summary>
        /// Do CAL Management  comms transaction, expecting local echo
        /// </summary>
        /// <param name="communicationChannel"></param>
        /// <param name="calCommand"></param>
        /// <returns></returns>
        bool DoCALCommsTransaction(Interface.Communication.ICommunicationChannel communicationChannel, ICBusCommand calCommand)
        {
            var rxBuffer      = new byte[128];
            var commandString = calCommand.ToCBusString();

            Logger.DebugFormat("TX {0}:{1}", calCommand, commandString);
            CBus.Protocol.CBusProtcol.SendCommand(communicationChannel, calCommand);

            Thread.Sleep(200);

            var rxLen        = communicationChannel.ReceiveBytes(rxBuffer, rxBuffer.Length);
            var rxDataString = GetReceivedString(rxBuffer, rxLen);

            if (rxDataString.StartsWith(commandString))
            {
                Logger.DebugFormat("RX:{0}", rxDataString.Substring(commandString.Length));
                return(true);
            }
            else
            {
                Logger.WarnFormat("RX:{0}", rxDataString);
                return(false);
            }
        }
Esempio n. 3
0
        private bool PerformLogon(Interface.Communication.ICommunicationChannel communicationChannel)
        {
            var    rxBuffer     = new byte[128];
            string rxString     = string.Empty;
            var    resetCount   = 3;
            var    resetSuccess = false;

            do
            {
                ICBusCommand calCommand = _configBuilder.ResetCommand();
                Logger.DebugFormat("TX {0}:{1}", calCommand, calCommand.ToCBusString());

                CBus.Protocol.CBusProtcol.SendCommand(communicationChannel, calCommand);
                CBus.Protocol.CBusProtcol.SendCommand(communicationChannel, calCommand);


                //Wait for response
                Thread.Sleep(200);

                var rxLen = communicationChannel.ReceiveBytes(rxBuffer, rxBuffer.Length);
                rxString = GetReceivedString(rxBuffer, rxLen);
                Logger.DebugFormat("RX:{0}", rxString);
                resetCount--;
                resetSuccess = rxString.Contains(CBus.Protocol.CBusProtcol.MODE_RESET_CHAR);
            } while (!resetSuccess && resetCount > 0);

            if (resetSuccess)
            {
                _ActiveApplications.Sort();
                for (int i = 0; i < _ActiveApplications.Count(); i++)
                {
                    var calCommand_App = _configBuilder.RegisterApplication1Monitor(_ActiveApplications[i]);
                    if (!DoCALCommsTransaction(communicationChannel, calCommand_App))
                    {
                        return(false);
                    }
                }
                var calCommand = _configBuilder.Set_CAL_Options3(CBusProtcol.Interface_Options_3.LOCAL_SAL);
                if (!DoCALCommsTransaction(communicationChannel, calCommand))
                {
                    return(false);
                }

                //See 4.3.3.1 CAL Reply, to under stand response (Long Form response as SMART selected)
                //Tx:@A3300059
                //Response: 86FAFA0032300024
                calCommand = _configBuilder.Set_CAL_Options1(
                    CBusProtcol.Interface_Options_1.CONNECT |
                    CBusProtcol.Interface_Options_1.SRCHK |
                    CBusProtcol.Interface_Options_1.SMART |
                    CBusProtcol.Interface_Options_1.IDIOM
                    );

                if (!DoCALCommsTransaction(communicationChannel, calCommand))
                {
                    return(false);
                }


                return(true);
            }


            return(false);
        }