コード例 #1
0
 public int RegisterDeviceChangeEvent(DeviceChangeEventCallbackFunction deviceEventFunc, object obj)
 {
     unsafe
     {
         if (deviceChangeEventList.Count == 0)
         {
             var deviceChangeEventFunctionDelegate = new DeviceChangeEventFunctionDelegate(deviceEventFunction);
             if (obj != null)
             {
                 deviceChangeEventContextHandle        = GCHandle.Alloc(obj);
                 registeredDeviceChangeEventFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterDeviceChangeEvent(deviceChangeEventFunctionDelegate,
                                                                (void *)GCHandle.ToIntPtr(deviceChangeEventContextHandle))
                     : WinInterop.tdRegisterDeviceChangeEvent(deviceChangeEventFunctionDelegate,
                                                              (void *)GCHandle.ToIntPtr(deviceChangeEventContextHandle)));
             }
             else
             {
                 registeredDeviceChangeEventFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterDeviceChangeEvent(deviceChangeEventFunctionDelegate, null)
                     : WinInterop.tdRegisterDeviceChangeEvent(deviceChangeEventFunctionDelegate, null));
             }
             if (!callbackFunctionReferenceList.ContainsKey(registeredDeviceChangeEventFunctionId))
             {
                 callbackFunctionReferenceList.Remove(registeredDeviceChangeEventFunctionId);
             }
             callbackFunctionReferenceList.Add(registeredDeviceChangeEventFunctionId,
                                               deviceChangeEventFunctionDelegate);
         }
         this.lastEventID++;
         int lastEventID = this.lastEventID;
         deviceChangeEventList.Add(lastEventID, deviceEventFunc);
         return(lastEventID);
     }
 }
コード例 #2
0
 public int RegisterSensorEvent(SensorCallbackFunction listeningFunc, object obj)
 {
     unsafe
     {
         if (sensorListenerList.Count == 0)
         {
             var sensorListeningDelegate = new SensorListeningDelegate(sensorListeningFunction);
             if (obj != null)
             {
                 sensorListenerContextHandle        = GCHandle.Alloc(obj);
                 registeredSensorListenerFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterSensorEvent(sensorListeningDelegate,
                                                          (void *)GCHandle.ToIntPtr(sensorListenerContextHandle))
                     : WinInterop.tdRegisterSensorEvent(sensorListeningDelegate,
                                                        (void *)GCHandle.ToIntPtr(sensorListenerContextHandle)));
             }
             else
             {
                 registeredSensorListenerFunctionId = ((!_isWin)
                     ? LinuxInterop.tdRegisterSensorEvent(sensorListeningDelegate, null)
                     : WinInterop.tdRegisterSensorEvent(sensorListeningDelegate, null));
             }
             if (!callbackFunctionReferenceList.ContainsKey(registeredSensorListenerFunctionId))
             {
                 callbackFunctionReferenceList.Remove(registeredSensorListenerFunctionId);
             }
             callbackFunctionReferenceList.Add(registeredSensorListenerFunctionId, sensorListeningDelegate);
         }
         this.lastEventID++;
         int lastEventID = this.lastEventID;
         sensorListenerList.Add(lastEventID, listeningFunc);
         return(lastEventID);
     }
 }
コード例 #3
0
 public string GetProtocol(int deviceId)
 {
     unsafe
     {
         return((!_isWin)
             ? AsString(LinuxInterop.tdGetProtocol(deviceId))
             : AsString(WinInterop.tdGetProtocol(deviceId)));
     }
 }
コード例 #4
0
 public string GetDeviceParameter(int deviceId, string name, string defaultValue)
 {
     unsafe
     {
         return((!_isWin)
             ? AsString(LinuxInterop.tdGetDeviceParameter(deviceId, name.ToCharPointer(), defaultValue.ToCharPointer()))
             : AsString(WinInterop.tdGetDeviceParameter(deviceId, name.ToCharPointer(), defaultValue.ToCharPointer())));
     }
 }
コード例 #5
0
 public string GetErrorString(int errorNo)
 {
     unsafe
     {
         return((!_isWin)
             ? AsString(LinuxInterop.tdGetErrorString(errorNo))
             : AsString(WinInterop.tdGetErrorString(errorNo)));
     }
 }
コード例 #6
0
 public string LastSentValue(int deviceId)
 {
     unsafe
     {
         return((!_isWin)
             ? AsString(LinuxInterop.tdLastSentValue(deviceId))
             : AsString(WinInterop.tdLastSentValue(deviceId)));
     }
 }
コード例 #7
0
 public bool SetProtocol(int deviceId, string protocol)
 {
     unsafe
     {
         char *ptr    = protocol.ToCharPointer();
         bool  result = (!_isWin) ? LinuxInterop.tdSetProtocol(deviceId, ptr) : WinInterop.tdSetProtocol(deviceId, ptr);
         Marshal.FreeHGlobal((IntPtr)ptr);
         Thread.Sleep(0);
         return(result);
     }
 }
コード例 #8
0
        //Interops

        public void Init()
        {
            if (_isWin)
            {
                WinInterop.tdInit();
            }
            else
            {
                LinuxInterop.tdInit();
            }
            _isInitialized = true;
        }
コード例 #9
0
 public int SendRawCommand(string command, int reserved)
 {
     unsafe
     {
         char *ptr    = command.ToCharPointer();
         int   result = (!_isWin)
             ? LinuxInterop.tdSendRawCommand(ptr, reserved)
             : WinInterop.tdSendRawCommand(ptr, reserved);
         Marshal.FreeHGlobal((IntPtr)ptr);
         return(result);
     }
 }
コード例 #10
0
 public bool SetDeviceParameter(int deviceId, string name, string value)
 {
     unsafe
     {
         char *ptr    = name.ToCharPointer();
         char *value2 = value.ToCharPointer();
         bool  result = (!_isWin)
             ? LinuxInterop.tdSetDeviceParameter(deviceId, ptr, value2)
             : WinInterop.tdSetDeviceParameter(deviceId, ptr, value2);
         Marshal.FreeHGlobal((IntPtr)ptr);
         Marshal.FreeHGlobal((IntPtr)value2);
         Thread.Sleep(0); //??
         return(result);
     }
 }
コード例 #11
0
        public void Close()
        {
            if (!_isInitialized)
            {
                return;
            }

            if (_isWin)
            {
                WinInterop.tdClose();
            }
            else
            {
                LinuxInterop.tdClose();
            }
            _isInitialized = false;
        }
コード例 #12
0
        private unsafe string AsString(char *input, bool release = true)
        {
            string text = Encoding.UTF8.GetString(Encoding.Unicode.GetBytes(new string(input)));

            if (text.Contains('\0'))
            {
                text = text.Substring(0, text.IndexOf('\0'));
            }
            if (release)
            {
                if (_isWin)
                {
                    WinInterop.tdReleaseString(input);
                }
                else
                {
                    LinuxInterop.tdReleaseString(input);
                }
            }
            return(text);
        }
コード例 #13
0
 public int AddDevice()
 {
     return((!_isWin)
         ? LinuxInterop.tdAddDevice()
         : WinInterop.tdAddDevice());
 }
コード例 #14
0
 public void CleanUp(bool closeAll)
 {
     try
     {
         if (registeredEventFunctionId != -1)
         {
             if (_isWin)
             {
                 WinInterop.tdUnregisterCallback(registeredEventFunctionId);
             }
             else
             {
                 LinuxInterop.tdUnregisterCallback(registeredEventFunctionId);
             }
             registeredEventFunctionId = -1;
         }
         if (registeredDeviceChangeEventFunctionId != -1)
         {
             if (_isWin)
             {
                 WinInterop.tdUnregisterCallback(registeredDeviceChangeEventFunctionId);
             }
             else
             {
                 LinuxInterop.tdUnregisterCallback(registeredDeviceChangeEventFunctionId);
             }
             registeredDeviceChangeEventFunctionId = -1;
         }
         if (registeredRawListenerFunctionId != -1)
         {
             if (_isWin)
             {
                 WinInterop.tdUnregisterCallback(registeredRawListenerFunctionId);
             }
             else
             {
                 LinuxInterop.tdUnregisterCallback(registeredRawListenerFunctionId);
             }
             registeredRawListenerFunctionId = -1;
         }
         if (registeredSensorListenerFunctionId != -1)
         {
             if (_isWin)
             {
                 WinInterop.tdUnregisterCallback(registeredSensorListenerFunctionId);
             }
             else
             {
                 LinuxInterop.tdUnregisterCallback(registeredSensorListenerFunctionId);
             }
             registeredSensorListenerFunctionId = -1;
         }
         eventList.Clear();
         deviceChangeEventList.Clear();
         rawListenerList.Clear();
         sensorListenerList.Clear();
         if (closeAll)
         {
             Close();
         }
         if (eventContextHandle.IsAllocated)
         {
             eventContextHandle.Free();
         }
         if (deviceChangeEventContextHandle.IsAllocated)
         {
             deviceChangeEventContextHandle.Free();
         }
         if (rawListenerContextHandle.IsAllocated)
         {
             rawListenerContextHandle.Free();
         }
         if (sensorListenerContextHandle.IsAllocated)
         {
             sensorListenerContextHandle.Free();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error during cleanup:" + e.ToString());
     }
 }
コード例 #15
0
 public int TurnOff(int deviceId)
 {
     return((!_isWin)
         ? LinuxInterop.tdTurnOff(deviceId)
         : WinInterop.tdTurnOff(deviceId));
 }
コード例 #16
0
        public int Dim(int deviceId, int percent)
        {
            byte level = Convert.ToByte(255m * (Convert.ToDecimal(percent) / 100m));

            return((!_isWin) ? LinuxInterop.tdDim(deviceId, level) : WinInterop.tdDim(deviceId, level));
        }
コード例 #17
0
 public bool RemoveDevice(int deviceId)
 {
     return((!_isWin)
         ? LinuxInterop.tdRemoveDevice(deviceId)
         : WinInterop.tdRemoveDevice(deviceId));
 }
コード例 #18
0
 public int Learn(int deviceId)
 {
     return((!_isWin)
         ? LinuxInterop.tdLearn(deviceId)
         : WinInterop.tdLearn(deviceId));
 }
コード例 #19
0
 public int GetDeviceId(int order)
 {
     return((!_isWin) ? LinuxInterop.tdGetDeviceId(order) : WinInterop.tdGetDeviceId(order));
 }
コード例 #20
0
 public int Bell(int deviceId)
 {
     return((!_isWin)
         ? LinuxInterop.tdBell(deviceId)
         : WinInterop.tdBell(deviceId));
 }
コード例 #21
0
 public int LastSentCommand(int deviceId, int methods)
 {
     return((!_isWin)
         ? LinuxInterop.tdLastSentCommand(deviceId, methods)
         : WinInterop.tdLastSentCommand(deviceId, methods));
 }
コード例 #22
0
 public int GetDeviceType(int deviceId)
 {
     return((!_isWin) ? LinuxInterop.tdGetDeviceType(deviceId) : WinInterop.tdGetDeviceType(deviceId));
 }
コード例 #23
0
 public int GetNumberOfDevices()
 {
     return((!_isWin)
         ? LinuxInterop.tdGetNumberOfDevices()
         : WinInterop.tdGetNumberOfDevices());
 }
コード例 #24
0
 public int Methods(int deviceId, int methodsSupported)
 {
     return((!_isWin)
         ? LinuxInterop.tdMethods(deviceId, methodsSupported)
         : WinInterop.tdMethods(deviceId, methodsSupported));
 }