Esempio n. 1
0
        public ReaJetComms(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits, int readTimeout, int writeTimeOut)
        {
            string appName = GUROCK_APP_NAME;
            if ((SiAuto.Si.AppName != appName) && (!SiAuto.Si.Enabled))
                LogHelperLib.Helper.InitializeLogger(appName, string.Format("{0}.sil", GUROCK_APP_NAME));

            if (!GurockSessionExists())
            {
                SiAuto.Si.AddSession(GUROCK_SESSION_NAME, true);
            }

            this.m_CommandValidator = new CommandValidator();

            this._portName = portName;
            if (serialPort == null)
                serialPort = new SerialPort(portName, baudRate, parity, dataBits, stopBits);

            serialPort.ReadTimeout = readTimeout;
            serialPort.WriteTimeout = writeTimeOut;
            //serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
            serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(serialPort_ErrorReceived);

            this.ACK_TIMEOUT = 150;
            this.REPLY_TELEGRAM_TIMEOUT = 150;

            this.Command = 0x00;
            this.CommandParams = null;

            this.m_Workflow = new CommandWorkflow(CmdWorklowStates.INITIAL_STATE);
            this.m_ReceivedTelegram = new REAjetTelegram();

            ConnectMethodsToWorkflow();
            this.m_Workflow.Configure();

               // OpenPort();
        }
Esempio n. 2
0
        public Int16 ExecuteCommand(byte command, byte[] parameters, out REAjetTelegram receivedTelegram)
        {
            Int16 ack = -127;
            receivedTelegram = null;
            try
            {
                LogSession.EnterMethod(string.Format("{0}.ExecuteCommand", this.GetType().Name));
                /*--------- Your code goes here-------*/
                receivedTelegram = null;
                if (command != null)
                {
                    this.m_ReaJetComms.ExecuteCommand(command, parameters);
                    receivedTelegram = this.m_ReaJetComms.ReceivedTelegram;
                    ack = Convert.ToInt16((int)this.m_ReaJetComms.LastError);
                }
                else
                    throw new Exception("Command is null");
                /*------------------------------------*/
            }
            catch (Exception ex)
            {
                LogSession.LogException(ex);
                LogSession.LogShort("ReaJetComms.LastError", Convert.ToInt16((int)this.m_ReaJetComms.LastError));
                ack = Convert.ToInt16((int)this.m_ReaJetComms.LastError);

            }
            finally
            {
                LogSession.LeaveMethod(string.Format("{0}.ExecuteCommand", this.GetType().Name));
            }

            return ack;
        }