예제 #1
0
        private void OpenSession(string channel, ushort mb_addr)
        {
            // See if we are supposed to connect to an existing session
              if (this.SessionId != null)
              {
            this.MbSlaveSession = (SMBSession)TMWSession.LookupSession(Convert.ToUInt32(this.SessionId));
            if (this.MbSlaveSession != null)
            {
              this.Channel = (MBChannel)this.MbSlaveSession.Channel;
              this.Channel.SessionCloseEvent += new TMWChannel.SessionCloseEventDelegate(SessionCloseEvent);
            }
            else
            {
              throw new Exception("Unable to load Modbus Slave Simulator. Unable to find session.");
            }
              }
              else
              {
            try
            {
              MbSlaveSession = new SMBSession(Channel);
              MbSlaveSession.SlaveAddress = mb_addr;
              MbSlaveSession.Name = "sMBSim_" + mb_addr;
              MbSlaveSession.OpenSession();
            }
            catch (Exception ex)
            {
              MessageBox.Show("Error Opening: " + ex.Message);
              Channel = null;
              MbSlaveSession = null;
              Close();

              return;
            }
              }
        }
예제 #2
0
        /// <summary>
        /// Closes the channel and session
        /// </summary>
        private void CloseSession()
        {
            if (this.MbSlaveSession != null)
              this.MbSlaveSession.CloseSession();

            this.MbSlaveSession = null;
        }