Ejemplo n.º 1
0
        private dynamic ReadData(string dataRef, XPlanePluginIcd.DataRefDataType dataRefDataType, int valueCount)
        {
            _sharedMemoryCommand.Write(new XPlanePluginIcd.DynamicQuery
            {
                DataRef = dataRef,
                DataType = dataRefDataType,
                QueryType = XPlanePluginIcd.XplaneQueryType.Read,
                ValueCount = (byte)valueCount,
            });

            var didRespond = _signal.WaitOne(2000);

            if (didRespond)
            {
                switch (dataRefDataType)
                {
                    case XPlanePluginIcd.DataRefDataType.XplmTypeInt:
                        return _response.IntValues[0];
                    case XPlanePluginIcd.DataRefDataType.XplmTypeIntArray:
                        return _response.IntValues.Take(valueCount).ToArray();
                    case XPlanePluginIcd.DataRefDataType.XplmTypeFloat:
                        return _response.FloatValues[0];
                    case XPlanePluginIcd.DataRefDataType.XplmTypeFloatArray:
                        return _response.FloatValues.Take(valueCount).ToArray();
                    case XPlanePluginIcd.DataRefDataType.XplmTypeDouble:
                        return _response.DoubleValues[0];
                    case XPlanePluginIcd.DataRefDataType.XplmTypeData:
                        return _response.TextValue;
                    default:
                        break;
                }

            }
            return -999;
        }
Ejemplo n.º 2
0
        public void WriteDataRef(string dataRef, dynamic newValue, XPlanePluginIcd.DataRefDataType dataRefDataType)
        {
            var query = new XPlanePluginIcd.DynamicQuery
                            {
                                DataRef = dataRef,
                                DataType = dataRefDataType,
                                QueryType = XPlanePluginIcd.XplaneQueryType.Write,
                                IntValues = new int[256],
                                FloatValues = new float[256],
                                DoubleValues = new double[256]
                            };

            switch (dataRefDataType)
            {
                case XPlanePluginIcd.DataRefDataType.XplmTypeInt:
                    query.IntValues[0] = newValue;
                    query.ValueCount = 1;
                    break;
                case XPlanePluginIcd.DataRefDataType.XplmTypeIntArray:
                    newValue.CopyTo(query.IntValues, 0);
                    query.ValueCount = (byte)newValue.Length;
                    break;
                case XPlanePluginIcd.DataRefDataType.XplmTypeFloat:
                    query.FloatValues[0] = newValue;
                    query.ValueCount = 1;
                    break;
                case XPlanePluginIcd.DataRefDataType.XplmTypeFloatArray:
                    newValue.CopyTo(query.FloatValues, 0);
                    query.ValueCount = (byte)newValue.Length;
                    break;
                case XPlanePluginIcd.DataRefDataType.XplmTypeDouble:
                    query.DoubleValues[0] = newValue;
                    query.ValueCount = 1;
                    break;
                case XPlanePluginIcd.DataRefDataType.XplmTypeData:
                    query.TextValue = newValue;
                    query.ValueCount = (byte)newValue.Length;
                    break;
                default:
                    throw new NotSupportedException();
            }

            _sharedMemoryCommand.Write(query);
        }