Example #1
0
        public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec)
            : base(key)
        {
            if (port == null)
            {
                Debug.Console(0, this, "ERROR: Invalid com port, continuing but comms will not function");
                return;
            }

            Port = port;
            Spec = spec;
            //IsConnected = new BoolFeedback(CommonBoolCue.IsConnected, () => true);

            if (Port.Parent is CrestronControlSystem)
            {
                var result = Port.Register();
                if (result != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    Debug.Console(0, this, "ERROR: Cannot register Com port: {0}", result);
                    return;                     // false
                }
            }
            var specResult = Port.SetComPortSpec(Spec);

            if (specResult != 0)
            {
                Debug.Console(0, this, "WARNING: Cannot set comspec");
                return;                 // false
            }
            Port.SerialDataReceived += new ComPortDataReceivedEvent(Port_SerialDataReceived);
        }
Example #2
0
        public NecComPortHandler(IComPortDevice comPort)
        {
            _comPort = comPort;
            RxQueue  = new CrestronQueue <byte>(1000);

            var port = _comPort as ComPort;

            if (port != null)
            {
                if (!port.Registered)
                {
                    if (port.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    {
                        ErrorLog.Error("Could not register com port {0}", _comPort.ID);
                    }
                }
            }

            var spec = new ComPort.ComPortSpec()
            {
                BaudRate          = ComPort.eComBaudRates.ComspecBaudRate9600,
                DataBits          = ComPort.eComDataBits.ComspecDataBits8,
                Parity            = ComPort.eComParityType.ComspecParityNone,
                StopBits          = ComPort.eComStopBits.ComspecStopBits1,
                Protocol          = ComPort.eComProtocolType.ComspecProtocolRS232,
                HardwareHandShake = ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone,
                SoftwareHandshake = ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone,
                ReportCTSChanges  = false
            };


            _comPort.SetComPortSpec(spec);
        }
Example #3
0
        public void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            var port = _comPort as PortDevice;

            if (port != null && !port.Registered)
            {
                var result = port.Register();
                if (result != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CloudLog.Error("Could not register {0} with ID {1}, {2}", port.GetType().Name, port.ID, result);
                }
            }

            var spec = new ComPort.ComPortSpec()
            {
                BaudRate          = ComPort.eComBaudRates.ComspecBaudRate9600,
                DataBits          = ComPort.eComDataBits.ComspecDataBits8,
                Parity            = ComPort.eComParityType.ComspecParityNone,
                StopBits          = ComPort.eComStopBits.ComspecStopBits1,
                Protocol          = ComPort.eComProtocolType.ComspecProtocolRS232,
                HardwareHandShake = ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone,
                SoftwareHandshake = ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone,
                ReportCTSChanges  = false
            };

            _comPort.SetComPortSpec(spec);

            _comPort.SerialDataReceived += (device, args) =>
            {
                var bytes = args.SerialData.ToByteArray();
#if DEBUG
                Debug.WriteSuccess("Samsung Rx",
                                   Debug.AnsiBlue + Tools.GetBytesAsReadableString(bytes, 0, bytes.Length, false) +
                                   Debug.AnsiReset);
#endif
                foreach (var b in bytes)
                {
                    _rxQueue.Enqueue(b);
                }

                if (_rxThread != null && _rxThread.ThreadState == Thread.eThreadStates.ThreadRunning)
                {
                    return;
                }
                _rxThread = new Thread(ReceiveBufferProcess, null, Thread.eThreadStartOptions.CreateSuspended)
                {
                    Priority = Thread.eThreadPriority.UberPriority,
                    Name     = string.Format("Samsung Display ComPort - Rx Handler")
                };
                _rxThread.Start();
            };
            _initialized = true;
        }
Example #4
0
        /// <summary>
        /// Constructor for COM
        /// </summary>
        public SamsungMDC(string key, string name, ComPort port, ComPort.ComPortSpec spec, string id)
            : base(key, name)
        {
            Communication = new ComPortController(key + "-com", port, spec);
            //Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived);

            ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
            Init();
        }
        public ComPortController(string key, IComPorts ComDevice, uint comPortNum, ComPort.ComPortSpec spec)
            : base(key)
        {
            Port = ComDevice.ComPorts[comPortNum];
            Spec = spec;

            Debug.Console(2, "Creating com port '{0}'", key);
            Debug.Console(2, "Com port spec:\r{0}", JsonConvert.SerializeObject(spec));
        }
Example #6
0
        /// <summary>
        /// Constructor for COM
        /// </summary>
        public AvocorDisplay(string key, string name, ComPort port, ComPort.ComPortSpec spec, string id)
            : base(key, name)
        {
            Communication = new ComPortController(key + "-com", port, spec);

            PortGather = new CommunicationGather(Communication, '\x0d');
            PortGather.IncludeDelimiter = true;
            PortGather.LineReceived    += new EventHandler <GenericCommMethodReceiveTextArgs>(PortGather_LineReceived);

            ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
            Init();
        }
Example #7
0
        public ComPortController(string key, Func <EssentialsControlPropertiesConfig, ComPort> postActivationFunc,
                                 ComPort.ComPortSpec spec, EssentialsControlPropertiesConfig config) : base(key)
        {
            Spec = spec;

            AddPostActivationAction(() =>
            {
                Port = postActivationFunc(config);

                RegisterAndConfigureComPort();
            });
        }
Example #8
0
        public override void InitializeSystem()
        {
            ComPort.ComPortSpec displayComSpec = new ComPort.ComPortSpec {
                BaudRate          = ComPort.eComBaudRates.ComspecBaudRate9600,
                DataBits          = ComPort.eComDataBits.ComspecDataBits8,
                Parity            = ComPort.eComParityType.ComspecParityNone,
                StopBits          = ComPort.eComStopBits.ComspecStopBits1,
                SoftwareHandshake = ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone,
                HardwareHandShake = ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone
            };

            try
            {
                if (this.SupportsEthernet)
                {
                    _dmRx     = new Am300(0x15, this);
                    _display  = new Display(_dmRx.ComPorts[1], displayComSpec);
                    _switcher = new AirMediaSwitcher(_dmRx);
                    if (_dmRx.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    {
                        ErrorLog.Error("Unable to register {0} on IP ID {1}!", _dmRx.Name, _dmRx.ID);
                    }

                    _dmTx = new DmTx201C(0x14, this);
                    _dmTx.HdmiInput.InputStreamChange += OnLaptopHDMI;
                    _dmTx.VgaInput.InputStreamChange  += OnLaptopVGA;
                    if (_dmTx.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    {
                        ErrorLog.Error("Unable to register {0} on IP ID {1}!", _dmTx.Name, _dmTx.ID);
                    }
                }

                if (this.SupportsCresnet)
                {
                    _occSensor = new GlsOdtCCn(0x97, this);
                    _occupancy = new RoomOccupancy(_occSensor, 15 * 60 * 60);   // 15 minutes
                    _occupancy.RoomOccupied = TurnSystemOn;
                    _occupancy.RoomVacant   = TurnSystemOff;
                    if (_occSensor.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                    {
                        ErrorLog.Error("Unable to register {0} on Cresnet ID {1}!", _occSensor.Name, _occSensor.ID);
                    }
                }
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in InitializeSystem: {0}", e.Message);
            }
        }
Example #9
0
        public ComPortController(string key, ComPort port, ComPort.ComPortSpec spec)
            : base(key)
        {
            if (port == null)
            {
                Debug.Console(0, this, "ERROR: Invalid com port, continuing but comms will not function");
                return;
            }

            Port = port;
            Spec = spec;
            //IsConnected = new BoolFeedback(CommonBoolCue.IsConnected, () => true);

            RegisterAndConfigureComPort();
        }
        public override void InitializeSystem()
        {
            try
            {
                // Currently only runs on DMPS architecture
                if (this.SystemControl == null)
                {
                    // Eventually we'll handle external switchers, too
                    ErrorLog.Error("Sorry, this program only runs on DMPS3 processors!");
                }
                else
                {
                    var control = this.SystemControl as Dmps3SystemControl;
                    control.SystemPowerOn();

                    // Samsung MDC = 9600 baud, 8 data bits, no parity, 1 stop bit
                    var displayComSettings = new ComPort.ComPortSpec();
                    displayComSettings.Protocol          = ComPort.eComProtocolType.ComspecProtocolRS232;
                    displayComSettings.BaudRate          = ComPort.eComBaudRates.ComspecBaudRate9600;
                    displayComSettings.DataBits          = ComPort.eComDataBits.ComspecDataBits8;
                    displayComSettings.Parity            = ComPort.eComParityType.ComspecParityNone;
                    displayComSettings.StopBits          = ComPort.eComStopBits.ComspecStopBits1;
                    displayComSettings.HardwareHandShake = ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone;
                    displayComSettings.SoftwareHandshake = ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone;

                    // Assume DM transmitter is connected to DM input 6
                    _source[0] = this.SwitcherInputs[6] as DMInput;
                    _tx1       = new DmTx200C2G(0x14, _source[0]);
                    _tx1.HdmiInput.InputStreamChange += new EndpointInputStreamChangeEventHandler((input, args) => tx_InputStreamChange(0, input, args));
                    _tx1.VgaInput.InputStreamChange  += new EndpointInputStreamChangeEventHandler((input, args) => tx_InputStreamChange(0, input, args));

                    // Assume DM transmitter is connected to DM input 7
                    _source[1] = this.SwitcherInputs[7] as DMInput;
                    _tx2       = new DmTx200C2G(0x15, _source[1]);
                    _tx2.HdmiInput.InputStreamChange += new EndpointInputStreamChangeEventHandler((input, args) => tx_InputStreamChange(1, input, args));
                    _tx2.VgaInput.InputStreamChange  += new EndpointInputStreamChangeEventHandler((input, args) => tx_InputStreamChange(1, input, args));

                    // Assume DM roombox is connected to DM output 3
                    _rmc1 = new DmRmcScalerC(0x16, this.SwitcherOutputs[3] as DMOutput);
                    _rmc1.ComPorts[1].SetComPortSpec(displayComSettings);
                }
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in InitializeSystem: {0}", e.StackTrace);
            }
        }
Example #11
0
        public ComPortHandler(IComPortDevice comPort)
        {
            _bytes   = new byte[10000];
            _port    = comPort;
            _rxQueue = new CrestronQueue <byte[]>();

            var cp = _port as ComPort;

            if (cp != null && !cp.Registered)
            {
                var result = cp.Register();
                if (result != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CloudLog.Warn("Registering comport for {0} result: {1}", GetType().Name, result);
                }
            }

            try
            {
                var spec = new ComPort.ComPortSpec()
                {
                    BaudRate          = ComPort.eComBaudRates.ComspecBaudRate38400,
                    DataBits          = ComPort.eComDataBits.ComspecDataBits8,
                    StopBits          = ComPort.eComStopBits.ComspecStopBits1,
                    Parity            = ComPort.eComParityType.ComspecParityNone,
                    HardwareHandShake = ComPort.eComHardwareHandshakeType.ComspecHardwareHandshakeNone,
                    SoftwareHandshake = ComPort.eComSoftwareHandshakeType.ComspecSoftwareHandshakeNone,
                    Protocol          = ComPort.eComProtocolType.ComspecProtocolRS232,
                    ReportCTSChanges  = false
                };
                _port.SetComPortSpec(spec);
            }
            catch (Exception e)
            {
                CloudLog.Error("Error could not set comport spec for {0}, {1}", GetType().Name, e.Message);
            }
        }
Example #12
0
 /// <summary>
 /// Constructor for COM
 /// </summary>
 public PanasonicThDisplay(string key, string name, ComPort port, ComPort.ComPortSpec spec)
     : base(key, name)
 {
     Communication = new ComPortController(key + "-com", port, spec);
     Init();
 }
        /// <summary>
        /// Creates a ComPort if the parameters are correct. Returns and logs errors if not
        /// </summary>
        public static ComPortController GetComPortController(string key,
                                                             IComPorts comDevice, uint comPortNum, ComPort.ComPortSpec spec)
        {
            Debug.Console(1, "Creating com port '{0}'", key);
            if (comDevice == null)
            {
                throw new ArgumentNullException("comDevice");
            }
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }
            if (comPortNum > comDevice.NumberOfComPorts)
            {
                Debug.Console(0, "[{0}] Com port {1} out of range on {2}",
                              key, comPortNum, comDevice.GetType().Name);
                return(null);
            }
            var port = new ComPortController(key, comDevice, comPortNum, spec);

            return(port);
        }
Example #14
0
 public Display(ComPort port, ComPort.ComPortSpec comspec)
 {
     _port = port;
     _port.SetComPortSpec(comspec);
     _port.SerialDataReceived += onDataReceived;
 }