Esempio n. 1
0
        public DeviceStates GetPenState()
        {
            ushort[]     usageList = GetButtonList(_hPreparsedData.DangerousGetHandle(), _pRawData, 0, _dwSizHid);
            DeviceStates state     = DeviceStates.None;

            foreach (var u in usageList)
            {
                switch (u)
                {
                case NativeMethods.TipId:
                    state |= DeviceStates.Tip;
                    break;

                case NativeMethods.InRangeId:
                    state |= DeviceStates.InRange;
                    break;

                case NativeMethods.BarrelButtonId:
                    state |= DeviceStates.RightClickButton;
                    break;

                case NativeMethods.InvertId:
                    state |= DeviceStates.Invert;
                    break;

                case NativeMethods.EraserId:
                    state |= DeviceStates.Eraser;
                    break;

                default:
                    break;
                }
            }
            return(state);
        }
Esempio n. 2
0
        public void UpdateVacuumStatus(params ValueType[] data)
        {
            try {
                var temp  = State;
                var temp2 = temp;
                temp = SwitchState(temp, DeviceStates.Turbo, (bool)(data[0]));
                bool relay1 = (bool)(data[1]);
                temp = SwitchState(temp, DeviceStates.SEMV1, relay1);

                // TODO: use ConsoleWriter logging
                if (relay1 == false)
                {
                    Console.WriteLine("Vacuum unit (TIC) relay 1 is off. Check TIC settings if this message appears constantly.");
                }

                temp  = SwitchState(temp, DeviceStates.Relay2, (bool)(data[2]));
                temp  = SwitchState(temp, DeviceStates.Relay3, (bool)(data[3]));
                temp  = SwitchState(temp, DeviceStates.Alert, (int)(data[4]) != 0);
                State = temp;
                if (temp2 != temp)
                {
                    // TODO: proper data!
                    OnVacuumStateChanged();
                }
            } catch (InvalidCastException) {
            };
        }
Esempio n. 3
0
 DeviceStates SwitchState(DeviceStates state, DeviceStates flag, bool on)
 {
     if ((state & flag) != 0)
     {
         state ^= flag;
     }
     state |= on ? flag : DeviceStates.None;
     return(state);
 }
Esempio n. 4
0
        private void addDeviceStateLogRecord(Devices device, DeviceStates state)
        {
            var insertCommand = new SqlCommandInfo("INSERT INTO DeviceStateLog(device, state) VALUES (@device, @state)");

            insertCommand.Parameters.Add("device", device);
            insertCommand.Parameters.Add("state", state);

            _sqlExecutionHelper.ExecuteNonQuery(insertCommand);
        }
Esempio n. 5
0
 /// <summary>
 ///  STATIC CONTRUCTOR FOR OptecPyxis CLASS
 /// </summary>
 public OptecPyxis()
     : base(DeviceTypes.TwoInch)
 {
     currentDeviceState = DeviceStates.Disconnected;
     #if DEBUG
     //  EventLogger.LoggingLevel = TraceLevel.Info;
     #else
     EventLogger.LoggingLevel = this.LoggerTraceLevel;
     #endif
 }
Esempio n. 6
0
        /// <summary>
        /// Makes a new instance of <see cref="InputEngine"/> class.
        /// </summary>
        /// <param name="host">Game host owner.</param>
        /// <param name="moduleLoop">Running loop.</param>
        public InputEngine(GameHost host, GameLoop moduleLoop)
            : base(host, moduleLoop)
        {
            InputStates = new DeviceStates();
            bindings    = new List <Binding>();

            Keyboard = new VirtualKeyboard(null);
            Mouse    = new VirtualMouse(null);
            Joypads  = new List <VirtualJoypad>();
        }
Esempio n. 7
0
        public void UpdateRegistration()
        {
            _ignoreTouchInputWhenUsingPen = AppConfig.IgnoreTouchInputWhenUsingPen;
            var penSetting = AppConfig.PenGestureButton;

            _penGestureButton = penSetting & (DeviceStates.Invert | DeviceStates.RightClickButton);

            UpdateRegisterState(true, NativeMethods.TouchScreenUsage);
            UpdateRegisterState(_ignoreTouchInputWhenUsingPen || _penGestureButton != 0 && (penSetting & (DeviceStates.InRange | DeviceStates.Tip)) != 0, NativeMethods.PenUsage);
            UpdateRegisterState(AppConfig.RegisterTouchPad, NativeMethods.TouchPadUsage);
        }
Esempio n. 8
0
        private void onDeviceStateChanged(Devices device, DeviceStates state)
        {
            DeviceStates currentDeviceState = _controlPanelService.GetDeviceState(device);

            if (state == currentDeviceState)
            {
                return;
            }

            _controlPanelService.SetDeviceCurrentState(device, state);
            addDeviceStateLogRecord(device, state);
        }
Esempio n. 9
0
    public IReadOnlyList <IMMDevice> EnumAudioEndpoints(DataFlow dataFlow, DeviceStates states = DeviceStates.Active)
    {
        EnumAudioEndpoints(dataFlow, (int)states, out IMMDeviceCollection collection).CheckError();
        List <IMMDevice> result = new List <IMMDevice>(collection.Count);

        for (int i = 0; i < collection.Count; i++)
        {
            result.Add(collection.Item(i));
        }

        collection.Dispose();
        return(result);
    }
Esempio n. 10
0
        public static String getDeviceStatusString(DeviceStates status)
        {
            switch (status)
            {
            case DeviceStates.Created:
                return("已创建");

            case DeviceStates.Fault:
                return("故障");

            case DeviceStates.Running:
                return("正常");

            case DeviceStates.Stop:
                return("停止");
            }
            return(null);
        }
Esempio n. 11
0
 protected virtual void Stop()
 {
    this.deviceState = DeviceStates.stopped;
 }
Esempio n. 12
0
 protected virtual void Reset()
 {
    this.deviceState = DeviceStates.preop;
    this.transferActive = false;
 }
Esempio n. 13
0
        private static bool parseDeviceStateLine(string line, ModelBindingContext bindingContext, out Devices device, out DeviceStates state)
        {
            device = 0;
            state  = 0;
            const char separator = ':';

            string[] parts = line.Split(separator);
            if (parts.Length != 2)
            {
                addModelError(bindingContext, $"Device state lines should contain 2 parts divided by '{separator}'");
                return(false);
            }

            if (!Enum.TryParse(parts[0], out device))
            {
                addModelError(bindingContext, "Cannot parse device value");
                return(false);
            }
            if (!Enum.IsDefined(typeof(Devices), device))
            {
                addModelError(bindingContext, "Unknown device");
                return(false);
            }

            if (!Enum.TryParse(parts[1], out state))
            {
                addModelError(bindingContext, "Cannot parse device state value");
                return(false);
            }
            if (!Enum.IsDefined(typeof(DeviceStates), state))
            {
                addModelError(bindingContext, "Unknown device state");
                return(false);
            }

            return(true);
        }
Esempio n. 14
0
 public void OperationReady(bool on)
 {
     State = SwitchState(State, DeviceStates.HVE, on);
 }
Esempio n. 15
0
 DeviceStates SwitchState(DeviceStates state, DeviceStates flag, bool on)
 {
     if ((state & flag) != 0)
         state ^= flag;
     state |= on ? flag : DeviceStates.None;
     return state;
 }
Esempio n. 16
0
 public virtual string GetDashStyle(DeviceStates deviceState)
 {
     return(null);
 }
Esempio n. 17
0
 public override string GetColor(DeviceStates deviceState)
 {
     return(deviceState == DeviceStates.On ? null : "red");
 }
Esempio n. 18
0
 public void OperationBlock(bool on)
 {
     State = SwitchState(State, DeviceStates.PRGE, on);
 }
Esempio n. 19
0
 public void OperationReady(bool on)
 {
     State = SwitchState(State, DeviceStates.HVE, on);
 }
Esempio n. 20
0
        /// <summary>
        /// Disconnect from the Pyxis Rotator device
        /// </summary>
        public void Disconnect()
        {
            try
            {
                switch (currentDeviceState)
                {
                    case DeviceStates.Disconnected:
                        break;
                    case DeviceStates.Connected:
                        MarkInstanceInUse(false);
                        break;
                    case DeviceStates.Sleep:
                        MarkInstanceInUse(false);
                        wakeDevice();
                        break;
                }

                closeSerialPortandDispose();
            }
            catch
            {

            }
            finally
            {
                currentDeviceState = DeviceStates.Disconnected;
                TriggerAnEvent(ConnectionTerminated, null);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Puts the device into  a low power sleep state. Call the wake up method to wake the device.
        /// </summary>
        public void PutToSleep()
        {
            // 1. Check for connected
            if (checkDeviceState() != DeviceStates.Connected)
            {
                throw new ApplicationException("Device must be connected in order to enter sleep mode.");
            }

            // 2. Send the command to go to sleep
            string cmd = "CSLEEP";
            mySerialPort.DiscardInBuffer();
            mySerialPort.DiscardOutBuffer();
            mySerialPort.Write(cmd);
            mySerialPort.Write(cmd);
            mySerialPort.Write(cmd);
            mySerialPort.ReadTimeout = 500;
            try
            {
                string resp = mySerialPort.ReadLine();
                if (resp.Contains("S"))
                    currentDeviceState = DeviceStates.Sleep;
                else throw new TimeoutException();
            }
            catch (TimeoutException)
            {
                throw new ApplicationException("Device did not enter sleep mode.");
            }
        }
Esempio n. 22
0
        /// <summary>
        /// This method will attempt to get a response from the device.
        /// It will set the state based on the response and also return the current state.
        /// </summary>
        /// <returns></returns>
        private DeviceStates checkDeviceState()
        {
            if (mySerialPort == null) return DeviceStates.Disconnected;
            if (!mySerialPort.IsOpen)
            {
                currentDeviceState = DeviceStates.Disconnected;
                return DeviceStates.Disconnected;
            }
            else
            {
                // 1. Check if it's already moving.
                if (isMoving || isHoming)
                {
                    return DeviceStates.Connected;
                }

                // 2. Check if it responds
                try
                {
                    mySerialPort.DiscardInBuffer();
                    mySerialPort.DiscardOutBuffer();
                    mySerialPort.ReadTimeout = 1000;
                    mySerialPort.Write("CCLINK");
                    string resp = mySerialPort.ReadLine();
                    if (resp.Contains("!"))
                    {
                        currentDeviceState = DeviceStates.Connected;
                        return DeviceStates.Connected;
                    }
                    else if (resp.Contains("S"))
                    {
                        currentDeviceState = DeviceStates.Sleep;
                        return DeviceStates.Sleep;
                    }
                    else
                    {
                        throw new ApplicationException("Unexpected response from Pyxis. Response was " + resp);
                    }

                }
                catch (System.TimeoutException)
                {
                    Disconnect();   // Close the port
                    currentDeviceState = DeviceStates.Disconnected;
                    return DeviceStates.Disconnected;
                }

            }
        }
Esempio n. 23
0
        /// <summary>
        /// Processes WM_INPUT messages to retrieve information about any
        /// touch events that occur.
        /// </summary>
        /// <param name="LParam">The WM_INPUT message to process.</param>
        private void ProcessInputCommand(IntPtr LParam)
        {
            uint dwSize = 0;

            // First call to GetRawInputData sets the value of dwSize
            // dwSize can then be used to allocate the appropriate amount of memore,
            // storing the pointer in "buffer".
            NativeMethods.GetRawInputData(LParam, NativeMethods.RID_INPUT, IntPtr.Zero,
                                          ref dwSize,
                                          (uint)Marshal.SizeOf(typeof(RAWINPUTHEADER)));

            IntPtr buffer = Marshal.AllocHGlobal((int)dwSize);

            try
            {
                // Check that buffer points to something, and if so,
                // call GetRawInputData again to fill the allocated memory
                // with information about the input
                if (buffer == IntPtr.Zero ||
                    NativeMethods.GetRawInputData(LParam, NativeMethods.RID_INPUT,
                                                  buffer,
                                                  ref dwSize,
                                                  (uint)Marshal.SizeOf(typeof(RAWINPUTHEADER))) != dwSize)
                {
                    throw new ApplicationException("GetRawInputData does not return correct size !\n.");
                }

                RAWINPUT raw = (RAWINPUT)Marshal.PtrToStructure(buffer, typeof(RAWINPUT));

                ushort usage;
                if (!_validDevices.TryGetValue(raw.header.hDevice, out usage))
                {
                    usage = ValidateDevice(raw.header.hDevice);
                    _validDevices.Add(raw.header.hDevice, usage);
                }

                if (usage == 0)
                {
                    return;
                }
                if (usage == NativeMethods.PenUsage)
                {
                    if (_ignoreTouchInputWhenUsingPen)
                    {
                        _penLastActivity = Environment.TickCount;
                    }
                    else
                    {
                        _penLastActivity = null;
                    }

                    if (_penGestureButton == 0)
                    {
                        return;
                    }

                    switch (_sourceDevice)
                    {
                    case Devices.TouchScreen:
                    case Devices.None:
                    case Devices.Pen:
                        break;

                    default:
                        return;
                    }

                    uint pcbSize = 0;
                    NativeMethods.GetRawInputDeviceInfo(raw.header.hDevice, NativeMethods.RIDI_PREPARSEDDATA, IntPtr.Zero, ref pcbSize);
                    IntPtr pPreparsedData = Marshal.AllocHGlobal((int)pcbSize);
                    using (new SafeUnmanagedMemoryHandle(pPreparsedData))
                    {
                        NativeMethods.GetRawInputDeviceInfo(raw.header.hDevice, NativeMethods.RIDI_PREPARSEDDATA, pPreparsedData, ref pcbSize);
                        IntPtr pRawData = new IntPtr(buffer.ToInt64() + (raw.header.dwSize - raw.hid.dwSizHid * raw.hid.dwCount));

                        ushort[]     usageList = GetButtonList(pPreparsedData, pRawData, 0, raw.hid.dwSizHid);
                        DeviceStates state     = DeviceStates.None;
                        foreach (var u in usageList)
                        {
                            switch (u)
                            {
                            case NativeMethods.TipId:
                                state |= DeviceStates.Tip;
                                break;

                            case NativeMethods.InRangeId:
                                state |= DeviceStates.InRange;
                                break;

                            case NativeMethods.BarrelButtonId:
                                state |= DeviceStates.RightClickButton;
                                break;

                            case NativeMethods.InvertId:
                                state |= DeviceStates.Invert;
                                break;

                            case NativeMethods.EraserId:
                                state |= DeviceStates.Eraser;
                                break;

                            default:
                                break;
                            }
                        }
                        if (_sourceDevice == Devices.None || _sourceDevice == Devices.TouchScreen)
                        {
                            if ((state & _penGestureButton) != 0)
                            {
                                _currentScr = Screen.FromPoint(Cursor.Position);
                                if (_currentScr == null)
                                {
                                    return;
                                }
                                _sourceDevice = Devices.Pen;
                                GetCurrentScreenOrientation();
                            }
                            else
                            {
                                return;
                            }
                        }
                        else if (_sourceDevice == Devices.Pen)
                        {
                            if ((state & _penGestureButton) == 0 || (state & DeviceStates.InRange) == 0)
                            {
                                state = DeviceStates.None;
                            }
                        }
                        if (_physicalMax.IsEmpty)
                        {
                            _physicalMax = GetPhysicalMax(1, pPreparsedData);
                        }

                        int physicalX = 0;
                        int physicalY = 0;

                        HidNativeApi.HidP_GetScaledUsageValue(HidReportType.Input, NativeMethods.GenericDesktopPage, 0, NativeMethods.XCoordinateId, ref physicalX, pPreparsedData, pRawData, raw.hid.dwSizHid);
                        HidNativeApi.HidP_GetScaledUsageValue(HidReportType.Input, NativeMethods.GenericDesktopPage, 0, NativeMethods.YCoordinateId, ref physicalY, pPreparsedData, pRawData, raw.hid.dwSizHid);

                        int x, y;
                        if (_isAxisCorresponds)
                        {
                            x = physicalX * _currentScr.Bounds.Width / _physicalMax.X;
                            y = physicalY * _currentScr.Bounds.Height / _physicalMax.Y;
                        }
                        else
                        {
                            x = physicalY * _currentScr.Bounds.Width / _physicalMax.Y;
                            y = physicalX * _currentScr.Bounds.Height / _physicalMax.X;
                        }
                        x             = _xAxisDirection ? x : _currentScr.Bounds.Width - x;
                        y             = _yAxisDirection ? y : _currentScr.Bounds.Height - y;
                        _outputTouchs = new List <RawData>(1);
                        _outputTouchs.Add(new RawData(state, 0, new Point(x + _currentScr.Bounds.X, y + _currentScr.Bounds.Y)));
                    }
                }
                else if (usage == NativeMethods.TouchScreenUsage)
                {
                    if (_penLastActivity != null && Environment.TickCount - _penLastActivity < 100)
                    {
                        return;
                    }
                    if (_sourceDevice == Devices.None)
                    {
                        _currentScr = Screen.FromPoint(Cursor.Position);
                        if (_currentScr == null)
                        {
                            return;
                        }
                        _sourceDevice = Devices.TouchScreen;
                        GetCurrentScreenOrientation();
                    }
                    else if (_sourceDevice != Devices.TouchScreen)
                    {
                        return;
                    }

                    uint pcbSize = 0;
                    NativeMethods.GetRawInputDeviceInfo(raw.header.hDevice, NativeMethods.RIDI_PREPARSEDDATA, IntPtr.Zero, ref pcbSize);

                    IntPtr pPreparsedData = Marshal.AllocHGlobal((int)pcbSize);
                    using (new SafeUnmanagedMemoryHandle(pPreparsedData))
                    {
                        NativeMethods.GetRawInputDeviceInfo(raw.header.hDevice, NativeMethods.RIDI_PREPARSEDDATA, pPreparsedData, ref pcbSize);

                        int    contactCount = 0;
                        IntPtr pRawData     = new IntPtr(buffer.ToInt64() + (raw.header.dwSize - raw.hid.dwSizHid * raw.hid.dwCount));
                        HidNativeApi.HidP_GetUsageValue(HidReportType.Input, NativeMethods.DigitizerUsagePage, 0, NativeMethods.ContactCountId,
                                                        ref contactCount, pPreparsedData, pRawData, raw.hid.dwSizHid);
                        int linkCount = 0;
                        HidNativeApi.HidP_GetLinkCollectionNodes(null, ref linkCount, pPreparsedData);
                        HidNativeApi.HIDP_LINK_COLLECTION_NODE[] lcn = new HidNativeApi.HIDP_LINK_COLLECTION_NODE[linkCount];
                        HidNativeApi.HidP_GetLinkCollectionNodes(lcn, ref linkCount, pPreparsedData);

                        if (_physicalMax.IsEmpty)
                        {
                            _physicalMax = GetPhysicalMax(linkCount, pPreparsedData);
                        }

                        if (contactCount != 0)
                        {
                            _requiringContactCount = contactCount;
                            _outputTouchs          = new List <RawData>(contactCount);
                        }
                        if (_requiringContactCount == 0)
                        {
                            return;
                        }
                        int contactIdentifier = 0;
                        int physicalX         = 0;
                        int physicalY         = 0;
                        for (int dwIndex = 0; dwIndex < raw.hid.dwCount; dwIndex++)
                        {
                            for (short nodeIndex = 1; nodeIndex <= lcn[0].NumberOfChildren; nodeIndex++)
                            {
                                IntPtr pRawDataPacket = new IntPtr(pRawData.ToInt64() + dwIndex * raw.hid.dwSizHid);
                                HidNativeApi.HidP_GetUsageValue(HidReportType.Input, NativeMethods.DigitizerUsagePage, nodeIndex, NativeMethods.ContactIdentifierId, ref contactIdentifier, pPreparsedData, pRawDataPacket, raw.hid.dwSizHid);
                                HidNativeApi.HidP_GetScaledUsageValue(HidReportType.Input, NativeMethods.GenericDesktopPage, nodeIndex, NativeMethods.XCoordinateId, ref physicalX, pPreparsedData, pRawDataPacket, raw.hid.dwSizHid);
                                HidNativeApi.HidP_GetScaledUsageValue(HidReportType.Input, NativeMethods.GenericDesktopPage, nodeIndex, NativeMethods.YCoordinateId, ref physicalY, pPreparsedData, pRawDataPacket, raw.hid.dwSizHid);

                                ushort[] usageList = GetButtonList(pPreparsedData, pRawData, nodeIndex, raw.hid.dwSizHid);

                                int x, y;
                                if (_isAxisCorresponds)
                                {
                                    x = physicalX * _currentScr.Bounds.Width / _physicalMax.X;
                                    y = physicalY * _currentScr.Bounds.Height / _physicalMax.Y;
                                }
                                else
                                {
                                    x = physicalY * _currentScr.Bounds.Width / _physicalMax.Y;
                                    y = physicalX * _currentScr.Bounds.Height / _physicalMax.X;
                                }
                                x = _xAxisDirection ? x : _currentScr.Bounds.Width - x;
                                y = _yAxisDirection ? y : _currentScr.Bounds.Height - y;
                                bool tip = usageList.Length != 0 && usageList[0] == NativeMethods.TipId;
                                _outputTouchs.Add(new RawData(tip ? DeviceStates.Tip : DeviceStates.None, contactIdentifier, new Point(x + _currentScr.Bounds.X, y + _currentScr.Bounds.Y)));

                                if (--_requiringContactCount == 0)
                                {
                                    break;
                                }
                            }
                            if (_requiringContactCount == 0)
                            {
                                break;
                            }
                        }
                    }
                }
                else if (usage == NativeMethods.TouchPadUsage)
                {
                    if (_sourceDevice == Devices.None)
                    {
                        _currentScr = Screen.FromPoint(Cursor.Position);
                        if (_currentScr == null)
                        {
                            return;
                        }
                        _sourceDevice = Devices.TouchPad;
                    }
                    else if (_sourceDevice != Devices.TouchPad)
                    {
                        return;
                    }

                    uint pcbSize = 0;
                    NativeMethods.GetRawInputDeviceInfo(raw.header.hDevice, NativeMethods.RIDI_PREPARSEDDATA, IntPtr.Zero, ref pcbSize);
                    IntPtr pPreparsedData = Marshal.AllocHGlobal((int)pcbSize);
                    using (new SafeUnmanagedMemoryHandle(pPreparsedData))
                    {
                        NativeMethods.GetRawInputDeviceInfo(raw.header.hDevice, NativeMethods.RIDI_PREPARSEDDATA, pPreparsedData, ref pcbSize);

                        int    contactCount = 0;
                        IntPtr pRawData     = new IntPtr(buffer.ToInt64() + (raw.header.dwSize - raw.hid.dwSizHid * raw.hid.dwCount));
                        HidNativeApi.HidP_GetUsageValue(HidReportType.Input, NativeMethods.DigitizerUsagePage, 0, NativeMethods.ContactCountId,
                                                        ref contactCount, pPreparsedData, pRawData, raw.hid.dwSizHid);

                        int linkCount = 0;
                        HidNativeApi.HidP_GetLinkCollectionNodes(null, ref linkCount, pPreparsedData);
                        HidNativeApi.HIDP_LINK_COLLECTION_NODE[] lcn = new HidNativeApi.HIDP_LINK_COLLECTION_NODE[linkCount];
                        HidNativeApi.HidP_GetLinkCollectionNodes(lcn, ref linkCount, pPreparsedData);

                        if (_physicalMax.IsEmpty)
                        {
                            _physicalMax = GetPhysicalMax(linkCount, pPreparsedData);
                        }

                        if (contactCount != 0)
                        {
                            _requiringContactCount = contactCount;
                            _outputTouchs          = new List <RawData>(contactCount);
                        }
                        if (_requiringContactCount == 0)
                        {
                            return;
                        }

                        int contactIdentifier = 0;
                        int physicalX         = 0;
                        int physicalY         = 0;

                        for (int dwIndex = 0; dwIndex < raw.hid.dwCount; dwIndex++)
                        {
                            for (short nodeIndex = 1; nodeIndex <= lcn[0].NumberOfChildren; nodeIndex++)
                            {
                                IntPtr pRawDataPacket = new IntPtr(pRawData.ToInt64() + dwIndex * raw.hid.dwSizHid);
                                HidNativeApi.HidP_GetUsageValue(HidReportType.Input, NativeMethods.DigitizerUsagePage, nodeIndex, NativeMethods.ContactIdentifierId, ref contactIdentifier, pPreparsedData, pRawDataPacket, raw.hid.dwSizHid);
                                HidNativeApi.HidP_GetScaledUsageValue(HidReportType.Input, NativeMethods.GenericDesktopPage, nodeIndex, NativeMethods.XCoordinateId, ref physicalX, pPreparsedData, pRawDataPacket, raw.hid.dwSizHid);
                                HidNativeApi.HidP_GetScaledUsageValue(HidReportType.Input, NativeMethods.GenericDesktopPage, nodeIndex, NativeMethods.YCoordinateId, ref physicalY, pPreparsedData, pRawDataPacket, raw.hid.dwSizHid);

                                ushort[] usageList = GetButtonList(pPreparsedData, pRawData, nodeIndex, raw.hid.dwSizHid);

                                int x, y;
                                x = physicalX * _currentScr.Bounds.Width / _physicalMax.X;
                                y = physicalY * _currentScr.Bounds.Height / _physicalMax.Y;

                                bool tip = usageList.Length != 0 && usageList[0] == NativeMethods.TipId;
                                _outputTouchs.Add(new RawData(tip ? DeviceStates.Tip : DeviceStates.None, contactIdentifier, new Point(x + _currentScr.Bounds.X, y + _currentScr.Bounds.Y)));

                                if (--_requiringContactCount == 0)
                                {
                                    break;
                                }
                            }
                            if (_requiringContactCount == 0)
                            {
                                break;
                            }
                        }
                    }
                }

                if (_requiringContactCount == 0 && PointsIntercepted != null)
                {
                    PointsIntercepted(this, new RawPointsDataMessageEventArgs(_outputTouchs, _sourceDevice));
                    if (_outputTouchs.TrueForAll(rd => rd.State == DeviceStates.None))
                    {
                        _sourceDevice = Devices.None;
                        _physicalMax  = Point.Empty;
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
Esempio n. 24
0
 public override string GetDashStyle(DeviceStates deviceState)
 {
     return(deviceState == DeviceStates.On ? null : "ShortDot");
 }
Esempio n. 25
0
        public void UpdateStatus(params ValueType[] data)
        {
            byte flags   = (byte)data[13];
            bool HVEport = !CheckBit(flags, 8);
            bool HVE     = !CheckBit(flags, 7);
            bool PRGE    = CheckBit(flags, 6);
            bool EDCD    = CheckBit(flags, 5);
            bool SEMV1   = CheckBit(flags, 4);
            bool SEMV2   = CheckBit(flags, 3);
            bool SEMV3   = CheckBit(flags, 2);
            bool SPUMP   = CheckBit(flags, 1);

            var temp  = State;
            var temp2 = temp;

            temp = SwitchState(temp, DeviceStates.SEMV1, SEMV1);
            if (temp2 != temp)
            {
                // TODO: proper data!
                OnVacuumStateChanged();
            }
            temp  = SwitchState(temp, DeviceStates.HVE, HVE);
            temp  = SwitchState(temp, DeviceStates.PRGE, PRGE);
            State = temp;

            bool isFake = true;

            for (int i = 0; i < 13; ++i)
            {
                if ((ushort)data[i] != 0xFFF)
                {
                    isFake = false;
                    break;
                }
            }
            if (isFake)
            {
                OnDeviceStatusChanged(SEMV2,
                                      SEMV3,
                                      SPUMP && PRGE//actual state
                                      );
            }
            else
            {
                OnDeviceStatusChanged(SEMV2,
                                      SEMV3,
                                      SPUMP && PRGE,                           //actual state
                                      50.0 * (ushort)data[0] / 4096,           //eI
                                      100.0 * (ushort)data[1] / 4096,          //iV
                                      100.0 * (ushort)data[2] / 4096,          //fV1
                                      100.0 * (ushort)data[3] / 4096,          //fV2
                                      5000.0 * (ushort)data[4] / 4096,         //d1V
                                      5000.0 * (ushort)data[5] / 4096,         //d2V
                                      5000.0 * (ushort)data[6] / 4096,         //d3V
                                      500.0 * (ushort)data[7] / 4096,          //cVp ?!!!
                                      500.0 * (ushort)data[8] / 4096,          //cVm ?!!!
                                      5000.0 * (ushort)data[9] / 4096,         //sV
                                      5000.0 * (ushort)data[10] / 4096,        //psV
                                      1.25 * (ushort)data[11],                 //inV
                                      500.0 * (ushort)data[12] / 4096 - 273.15 //hT celtigrate
                                      );
            }
        }
Esempio n. 26
0
 public virtual string GetColor(DeviceStates deviceState)
 {
     return(null);
 }
Esempio n. 27
0
 public static String getDeviceStatusString(DeviceStates status)
 {
     switch (status)
     {
         case DeviceStates.Connected:
             return "刚连接";
         case DeviceStates.Fault:
             return "故障";
         case DeviceStates.Running:
             return "正常";
         case DeviceStates.Stop:
             return "停止";
     }
     return null;
 }
Esempio n. 28
0
        public void UpdateVacuumStatus(params ValueType[] data)
        {
            try {
                var temp = State;
                var temp2 = temp;
                temp = SwitchState(temp, DeviceStates.Turbo, (bool)(data[0]));
                bool relay1 = (bool)(data[1]);
                temp = SwitchState(temp, DeviceStates.SEMV1, relay1);

                // TODO: use ConsoleWriter logging
                if (relay1 == false)
                    Console.WriteLine("Vacuum unit (TIC) relay 1 is off. Check TIC settings if this message appears constantly.");

                temp = SwitchState(temp, DeviceStates.Relay2, (bool)(data[2]));
                temp = SwitchState(temp, DeviceStates.Relay3, (bool)(data[3]));
                temp = SwitchState(temp, DeviceStates.Alert, (int)(data[4]) != 0);
                State = temp;
                if (temp2 != temp) {
                    // TODO: proper data!
                    OnVacuumStateChanged();
                }
            } catch (InvalidCastException) {
            };
        }
 public Sprite(string i_AssetName, GameScreen i_GameScreen, int i_UpdateOrder, int i_DrawOrder)
     : base(i_AssetName, i_GameScreen.Game, i_UpdateOrder, i_DrawOrder)
 {
      r_SavedDeviceStates = new DeviceStates();
      r_GameScreen = i_GameScreen;
 }
Esempio n. 30
0
 public void OperationBlock(bool on)
 {
     State = SwitchState(State, DeviceStates.PRGE, on);
 }
Esempio n. 31
0
        /// <summary>
        /// Send the CWAKEx command to wake the device from sleep mode
        /// </summary>
        private void wakeDevice()
        {
            #if DEBUG
            // 1. Make sure the Port is open
            if (!mySerialPort.IsOpen) throw new ApplicationException("The Serial port must be opened before calling CheckIfInMotion");
            #endif
            // 2. Send the command to wake up
            mySerialPort.DiscardInBuffer();
            mySerialPort.DiscardOutBuffer();
            mySerialPort.Write("CWAKUP");
            mySerialPort.ReadTimeout = 1000;

            try
            {
                // 3. Check that the correct response was received
                string resp = mySerialPort.ReadLine();
                if (resp.Contains("!"))
                {
                    currentDeviceState = DeviceStates.Connected;
                    return;
                }
                else throw new ApplicationException("Device did not wake up properly.");
            }
            catch (Exception ex)
            {
                EventLogger.LogMessage(ex);
                throw;
            }
        }
Esempio n. 32
0
        public void UpdateStatus(params ValueType[] data)
        {
            byte flags = (byte)data[13];
            bool HVEport = !CheckBit(flags, 8);
            bool HVE = !CheckBit(flags, 7);
            bool PRGE = CheckBit(flags, 6);
            bool EDCD = CheckBit(flags, 5);
            bool SEMV1 = CheckBit(flags, 4);
            bool SEMV2 = CheckBit(flags, 3);
            bool SEMV3 = CheckBit(flags, 2);
            bool SPUMP = CheckBit(flags, 1);

            var temp = State;
            var temp2 = temp;
            temp = SwitchState(temp, DeviceStates.SEMV1, SEMV1);
            if (temp2 != temp) {
                // TODO: proper data!
                OnVacuumStateChanged();
            }
            temp = SwitchState(temp, DeviceStates.HVE, HVE);
            temp = SwitchState(temp, DeviceStates.PRGE, PRGE);
            State = temp;

            bool isFake = true;
            for (int i = 0; i < 13; ++i) {
                if ((ushort)data[i] != 0xFFF) {
                    isFake = false;
                    break;
                }
            }
            if (isFake) {
                OnDeviceStatusChanged(SEMV2,
                    SEMV3,
                    SPUMP && PRGE//actual state
                    );
            } else {
                OnDeviceStatusChanged(SEMV2,
                    SEMV3,
                    SPUMP && PRGE,//actual state
                    50.0 * (ushort)data[0] / 4096,//eI
                    100.0 * (ushort)data[1] / 4096,//iV
                    100.0 * (ushort)data[2] / 4096,//fV1
                    100.0 * (ushort)data[3] / 4096,//fV2
                    5000.0 * (ushort)data[4] / 4096,//d1V
                    5000.0 * (ushort)data[5] / 4096,//d2V
                    5000.0 * (ushort)data[6] / 4096,//d3V
                    500.0 * (ushort)data[7] / 4096,//cVp ?!!!
                    500.0 * (ushort)data[8] / 4096,//cVm ?!!!
                    5000.0 * (ushort)data[9] / 4096,//sV
                    5000.0 * (ushort)data[10] / 4096,//psV
                    1.25 * (ushort)data[11],//inV
                    500.0 * (ushort)data[12] / 4096 - 273.15//hT celtigrate
                );
            }
        }
Esempio n. 33
0
 public FingerPrintPacket(PacketTypes packetType, DeviceStates deviceState)
     : this(packetType)
 {
     this.DeviceState = deviceState;
 }
 public FingerPrintPacket(PacketTypes packetType, DeviceStates deviceState)
     : this(packetType)
 {
     this.DeviceState = deviceState;
 }
        private IEnumerable <MMDevice> GetAllDevices(IMMDeviceEnumerator deviceEnumerator, DeviceStates deviceStates)
        {
            // Collect default devices
            var communicationPlaybackId  = GetDefaultDeviceId(deviceEnumerator, DataFlows.Render, DeviceRoles.Communication);
            var communicationRecordingId = GetDefaultDeviceId(deviceEnumerator, DataFlows.Capture, DeviceRoles.Communication);
            var multimediaPlaybackId     = GetDefaultDeviceId(deviceEnumerator, DataFlows.Render, DeviceRoles.Multimedia);
            var multimediaRecordingId    = GetDefaultDeviceId(deviceEnumerator, DataFlows.Capture, DeviceRoles.Multimedia);

            IMMDeviceCollection deviceCollection;

            Marshal.ThrowExceptionForHR(deviceEnumerator.EnumAudioEndpoints(DataFlows.All, deviceStates, out deviceCollection));

            uint count;

            Marshal.ThrowExceptionForHR(deviceCollection.GetCount(out count));

            for (uint i = 0; i < count; i++)
            {
                IMMDevice result;
                deviceCollection.Item(i, out result);

                var mmDevice = new MMDevice(result,
                                            (int)i + 1,
                                            communicationPlaybackId,
                                            communicationRecordingId,
                                            multimediaPlaybackId,
                                            multimediaRecordingId);

                yield return(mmDevice);
            }
        }
Esempio n. 36
0
 protected virtual void Start()
 {
    this.deviceState = DeviceStates.running;
 }
Esempio n. 37
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public GXTransactionProgressEventArgs(object item, Int32 index, Int32 count, DeviceStates status)
 {
     Status = status;
     Cancel = false;
     this.Item = item;
     this.Current = index;
     this.Maximum = count;
 }
Esempio n. 38
0
 private void UpdateUIElements(DeviceStates state)
 {
     if (this.InvokeRequired)
     {
         this.Invoke((MethodInvoker) delegate
         {
             UpdateUIElements(state);
         });
     }
     else
     {
         if (state == DeviceStates.NotConnected)
         {
             cbDevices.Enabled    = true;
             btnRefresh.Enabled   = true;
             btnOpenClose.Text    = "Open";
             btnOpenClose.Enabled = true;
             btnStartStop.Text    = "Start";
             btnStartStop.Enabled = false;
             tbStreamName.Enabled = true;
         }
         else if (state == DeviceStates.Connecting)
         {
             cbDevices.Enabled    = false;
             btnRefresh.Enabled   = false;
             btnOpenClose.Text    = "Open";
             btnOpenClose.Enabled = false;
             btnStartStop.Text    = "Start";
             btnStartStop.Enabled = false;
             tbStreamName.Enabled = false;
         }
         else if (state == DeviceStates.Connected)
         {
             cbDevices.Enabled    = false;
             btnRefresh.Enabled   = false;
             btnOpenClose.Text    = "Close";
             btnOpenClose.Enabled = true;
             btnStartStop.Text    = "Start";
             btnStartStop.Enabled = true;
             tbStreamName.Enabled = false;
         }
         else if (state == DeviceStates.Acquiring)
         {
             cbDevices.Enabled    = false;
             btnRefresh.Enabled   = false;
             btnOpenClose.Text    = "Close";
             btnOpenClose.Enabled = true;
             btnStartStop.Text    = "Stop";
             btnStartStop.Enabled = true;
             tbStreamName.Enabled = false;
         }
         else
         {
             cbDevices.Enabled    = false;
             btnRefresh.Enabled   = false;
             btnOpenClose.Text    = "Open";
             btnOpenClose.Enabled = false;
             btnStartStop.Text    = "Start";
             btnStartStop.Enabled = false;
             tbStreamName.Enabled = false;
         }
     }
 }
Esempio n. 39
0
		/// <summary>
		/// Stops keepalive and closes the connection.
		/// </summary>
		public void Disconnect()
		{
			try
			{                
                this.m_Status |= DeviceStates.Disconnecting;                                
				Keepalive.Stop();
                StopMonitoring();
				GXClient.CloseMedia();
                if (Tracing)
                {
                    GXClient.OnTrace -= new Gurux.Common.TraceEventHandler(GXClient_OnTrace);
                    Tracing = false;
                }                
			}
			finally
			{
                IsCancelled = false;
                this.Status &= ~DeviceStates.Disconnecting;
                if (Statistics != null)
                {
                    Statistics.DisconnectTime = DateTime.Now;
                }
            }
		}
Esempio n. 40
0
 static internal bool CanExecute(DisabledActions disabledActions, DeviceStates status, bool read)
 {
     //If monitoring.
     if ((status & DeviceStates.Monitoring) != 0)
     {
         return (disabledActions & DisabledActions.Monitor) == 0;
     }
     //If scheduling.
     if ((status & DeviceStates.Scheduling) != 0)
     {
         return (disabledActions & DisabledActions.Schedule) == 0;
     }
     //Can read.
     if (read)
     {
         return (disabledActions & DisabledActions.Read) == 0;
     }
     //Can write.
     return (disabledActions & DisabledActions.Write) == 0;
 }
Esempio n. 41
0
        /// <summary>
        /// Processes WM_INPUT messages to retrieve information about any
        /// touch events that occur.
        /// </summary>
        /// <param name="LParam">The WM_INPUT message to process.</param>
        private void ProcessInputCommand(IntPtr LParam)
        {
            uint dwSize = 0;

            // First call to GetRawInputData sets the value of dwSize
            // dwSize can then be used to allocate the appropriate amount of memore,
            // storing the pointer in "buffer".
            NativeMethods.GetRawInputData(LParam, NativeMethods.RID_INPUT, IntPtr.Zero,
                                          ref dwSize,
                                          (uint)Marshal.SizeOf(typeof(RAWINPUTHEADER)));

            IntPtr buffer = Marshal.AllocHGlobal((int)dwSize);

            try
            {
                // Check that buffer points to something, and if so,
                // call GetRawInputData again to fill the allocated memory
                // with information about the input
                if (buffer == IntPtr.Zero ||
                    NativeMethods.GetRawInputData(LParam, NativeMethods.RID_INPUT,
                                                  buffer,
                                                  ref dwSize,
                                                  (uint)Marshal.SizeOf(typeof(RAWINPUTHEADER))) != dwSize)
                {
                    throw new ApplicationException("GetRawInputData does not return correct size !\n.");
                }

                RAWINPUT raw = (RAWINPUT)Marshal.PtrToStructure(buffer, typeof(RAWINPUT));

                ushort usage;
                if (!_validDevices.TryGetValue(raw.header.hDevice, out usage))
                {
                    if (ValidateDevice(raw.header.hDevice, out usage))
                    {
                        _validDevices.Add(raw.header.hDevice, usage);
                    }
                }

                if (usage == 0)
                {
                    return;
                }
                if (usage == NativeMethods.PenUsage)
                {
                    if (_ignoreTouchInputWhenUsingPen)
                    {
                        _penLastActivity = Environment.TickCount;
                    }
                    else
                    {
                        _penLastActivity = null;
                    }

                    if (_penGestureButton == 0)
                    {
                        return;
                    }

                    switch (_sourceDevice)
                    {
                    case Devices.TouchScreen:
                    case Devices.None:
                    case Devices.Pen:
                        break;

                    default:
                        return;
                    }

                    using (PenDevice penDevice = new PenDevice(buffer, ref raw))
                    {
                        DeviceStates state = penDevice.GetPenState();

                        if (_sourceDevice == Devices.None || _sourceDevice == Devices.TouchScreen)
                        {
                            if ((state & _penGestureButton) != 0)
                            {
                                _currentScr = Screen.FromPoint(Cursor.Position);
                                if (_currentScr == null)
                                {
                                    return;
                                }
                                _sourceDevice = Devices.Pen;
                                PenDevice.GetCurrentScreenOrientation();
                            }
                            else
                            {
                                return;
                            }
                        }
                        else if (_sourceDevice == Devices.Pen)
                        {
                            if ((state & _penGestureButton) == 0 || (state & DeviceStates.InRange) == 0)
                            {
                                state = DeviceStates.None;
                            }
                        }
                        penDevice.GetPhysicalMax(1);
                        Point point = penDevice.GetCoordinate(0, _currentScr);
                        _outputTouchs = new List <RawData>(1)
                        {
                            new RawData(state, 0, point)
                        };
                    }
                }
                else if (usage == NativeMethods.TouchScreenUsage)
                {
                    if (_penLastActivity != null && Environment.TickCount - _penLastActivity < 100)
                    {
                        return;
                    }
                    if (_sourceDevice == Devices.None)
                    {
                        _currentScr = Screen.FromPoint(Cursor.Position);
                        if (_currentScr == null)
                        {
                            return;
                        }
                        _sourceDevice = Devices.TouchScreen;
                        TouchScreenDevice.GetCurrentScreenOrientation();
                    }
                    else if (_sourceDevice != Devices.TouchScreen)
                    {
                        return;
                    }

                    using (TouchScreenDevice touchScreen = new TouchScreenDevice(buffer, ref raw))
                    {
                        int contactCount = touchScreen.GetContactCount();
                        HidNativeApi.HIDP_LINK_COLLECTION_NODE[] linkCollection = touchScreen.GetLinkCollectionNodes();
                        touchScreen.GetPhysicalMax(linkCollection.Length);

                        if (contactCount != 0)
                        {
                            _requiringContactCount = contactCount;
                            _outputTouchs          = new List <RawData>(contactCount);
                        }
                        if (_requiringContactCount == 0)
                        {
                            return;
                        }

                        touchScreen.GetRawDatas(linkCollection[0].NumberOfChildren, _currentScr, ref _requiringContactCount, ref _outputTouchs);
                    }
                }
                else if (usage == NativeMethods.TouchPadUsage)
                {
                    if (_sourceDevice == Devices.None)
                    {
                        _currentScr = Screen.FromPoint(Cursor.Position);
                        if (_currentScr == null)
                        {
                            return;
                        }
                        _sourceDevice = Devices.TouchPad;
                    }
                    else if (_sourceDevice != Devices.TouchPad)
                    {
                        return;
                    }

                    using (TouchPadDevice touchPad = new TouchPadDevice(buffer, ref raw))
                    {
                        int contactCount = touchPad.GetContactCount();
                        HidNativeApi.HIDP_LINK_COLLECTION_NODE[] linkCollection = touchPad.GetLinkCollectionNodes();
                        touchPad.GetPhysicalMax(linkCollection.Length);

                        if (contactCount != 0)
                        {
                            _requiringContactCount = contactCount;
                            _outputTouchs          = new List <RawData>(contactCount);
                        }
                        if (_requiringContactCount == 0)
                        {
                            return;
                        }

                        touchPad.GetRawDatas(linkCollection[0].NumberOfChildren, _currentScr, ref _requiringContactCount, ref _outputTouchs);
                    }
                }

                if (_requiringContactCount == 0 && PointsIntercepted != null)
                {
                    PointsIntercepted(this, new RawPointsDataMessageEventArgs(_outputTouchs, _sourceDevice));
                    if (_outputTouchs.TrueForAll(rd => rd.State == DeviceStates.None))
                    {
                        _sourceDevice = Devices.None;
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
Esempio n. 42
0
 public RawData(DeviceStates state, int contactIdentifier, Point rawPointsData)
 {
     this.State             = state;
     this.ContactIdentifier = contactIdentifier;
     this.RawPoints         = rawPointsData;
 }
Esempio n. 43
0
        /// <summary>
        /// Request the default move direction from the device.
        /// </summary>
        /// <returns></returns>
        private int getDirectionFlag()
        {
            // 1. Check for connected
            if (currentDeviceState != DeviceStates.Connected)
            {
                throw new ApplicationException("Device must be connected in order to getDirectionFlag");
            }

            // 1.5 Check if is moving
            if (isMoving || isHoming)
            {
                throw new ApplicationException("Cannot get Direction flag while device is moving/homing");
            }

            // 2. Send the getFlag command
            string cmd = "CMREAD";
            mySerialPort.DiscardInBuffer();
            mySerialPort.DiscardOutBuffer();
            mySerialPort.Write(cmd);
            mySerialPort.ReadTimeout = 1100;

            // 3. Check that the correct response was received
            try
            {
                string resp = mySerialPort.ReadLine();
                if (resp.Contains("1"))
                {
                    currentDeviceState = DeviceStates.Connected;
                    return 1;
                }
                else if (resp.Contains("0")) return 0;
                else throw new ApplicationException("Device did not respond properly to getDirectionFlag command.");
            }
            catch (Exception ex)
            {
                EventLogger.LogMessage(ex);
                throw;
            }
        }
Esempio n. 44
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public GXDeviceEventArgs(object device, DeviceStates status)
     : base(device)
 {
     Status = status;
 }
Esempio n. 45
0
 public void SetDeviceTargetState(Devices device, DeviceStates targetState)
 {
     _repository.MergeDeviceState(device, "target_state", targetState);
 }
Esempio n. 46
0
 public void SetDeviceTargetState(Devices device, DeviceStates targetState)
 {
     _service.SetDeviceTargetState(device, targetState);
 }
Esempio n. 47
0
 public DeviceStateLogRecord(DateTime utcDateTime, Devices device, DeviceStates state)
 {
     DateTime = utcDateTime.ToLocal();
     Device   = device;
     State    = state;
 }