コード例 #1
0
ファイル: LampService.cs プロジェクト: Necat0r/Automation
        public LampService(ServiceCreationInfo info)
            : base(info)
        {
            uint port = uint.Parse(info.Configuration["port"]);

            mSerialHelper = SerialRepository.OpenPort("arduino", port, 115200);
        }
コード例 #2
0
        public static SerialHelper OpenPort(string name, uint port, uint baudrate)
        {
            SerialHelper helper;

            lock (mPortLookup)
            {
                bool exists = mPortLookup.TryGetValue(port, out helper);

                if (!exists)
                {
                    Log.Info("Opening COM{0} with handle '{1}' at {2} baud", port, name, baudrate);
                    helper = new SerialHelper(name, port, baudrate);
                    mPortLookup.Add(port, helper);
                }
                else
                {
                    if (helper.Baudrate != baudrate)
                        throw new ArgumentException(string.Format("Attempt to open COM{0} in {1} baud when it was previously opened in {2} baud. Original handle: {3}.", port, baudrate, helper.Baudrate, helper.Name));

                    Log.Info("Reusing COM{0} at {1} baud via handle '{2}'", port, baudrate, name);
                }
            }

            return helper;
        }
コード例 #3
0
ファイル: EpsonDevice.cs プロジェクト: Necat0r/Automation
 public EpsonDevice(DeviceCreationInfo creationInfo)
     : base(new EpsonState(), creationInfo)
 {
     int port = int.Parse(creationInfo.Configuration.port);
     mSerialHelper = new SerialHelper("epson", (uint)port, 9600);
     mSerialHelper.AddListener(this);
 }
コード例 #4
0
ファイル: CurtainService.cs プロジェクト: Necat0r/Automation
        protected override void Dispose(bool disposing)
        {
            if (mSerialHelper != null)
            {
                mSerialHelper.Dispose();
                mSerialHelper = null;
            }

            base.Dispose(disposing);
        }
コード例 #5
0
ファイル: CurtainService.cs プロジェクト: Necat0r/Automation
        public CurtainService(ServiceCreationInfo info)
            : base("curtain", info)
        {
            uint port = uint.Parse(info.Configuration.port);

            mSerialHelper = SerialRepository.OpenPort("arduino", port, 115200);
            mRadioLock = RadioLock.Instance;

            mLock = new Object();
        }
コード例 #6
0
ファイル: RfxComService.cs プロジェクト: Necat0r/Automation
        public RfxComService(ServiceCreationInfo info)
            : base("rfxcom", info)
        {
            mDeviceManager = info.DeviceManager;

            int port = int.Parse(info.Configuration["port"]);

            mSerialHelper = new SerialHelper("rfxcom", (uint)port, 38400);
            mRadioLock = RadioLock.Instance;
            mEvents = new EventWaitHandle[] { mActionEvent, mSerialEvent, mStopEvent };

            mRfxThread = new Thread(Tick);
            mRfxThread.Start();
        }
コード例 #7
0
ファイル: RfxComService.cs プロジェクト: Necat0r/Automation
        protected override void Dispose(bool disposing)
        {
            if (disposing && !mDisposed)
            {
                mDisposed = true;
                mRunning = false;

                mStopEvent.Set();

                mRfxThread.Join();
                mRfxThread = null;

                mSerialHelper.Dispose();
                mSerialHelper = null;

                mActionEvent.Dispose();
                mActionEvent = null;

                mSerialEvent.Dispose();
                mSerialEvent = null;

                mStopEvent.Dispose();
                mStopEvent = null;
            }

            base.Dispose(disposing);
        }