Example #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);
     }
 }
Example #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);
     }
 }
Example #3
0
 public string GetProtocol(int deviceId)
 {
     unsafe
     {
         return((!_isWin)
             ? AsString(LinuxInterop.tdGetProtocol(deviceId))
             : AsString(WinInterop.tdGetProtocol(deviceId)));
     }
 }
Example #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())));
     }
 }
Example #5
0
 public string GetErrorString(int errorNo)
 {
     unsafe
     {
         return((!_isWin)
             ? AsString(LinuxInterop.tdGetErrorString(errorNo))
             : AsString(WinInterop.tdGetErrorString(errorNo)));
     }
 }
Example #6
0
 public string LastSentValue(int deviceId)
 {
     unsafe
     {
         return((!_isWin)
             ? AsString(LinuxInterop.tdLastSentValue(deviceId))
             : AsString(WinInterop.tdLastSentValue(deviceId)));
     }
 }
Example #7
0
 public bool SetName(int deviceId, string name)
 {
     unsafe
     {
         char *ptr    = name.ToCharPointer();
         bool  result = (!_isWin) ? LinuxInterop.tdSetName(deviceId, ptr) : WinInterop.tdSetName(deviceId, ptr);
         Marshal.FreeHGlobal((IntPtr)ptr);
         Thread.Sleep(0);
         return(result);
     }
 }
Example #8
0
        //Interops

        public void Init()
        {
            if (_isWin)
            {
                WinInterop.tdInit();
            }
            else
            {
                LinuxInterop.tdInit();
            }
            _isInitialized = true;
        }
Example #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);
     }
 }
Example #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);
     }
 }
Example #11
0
        public void Close()
        {
            if (!_isInitialized)
            {
                return;
            }

            if (_isWin)
            {
                WinInterop.tdClose();
            }
            else
            {
                LinuxInterop.tdClose();
            }
            _isInitialized = false;
        }
Example #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);
        }
Example #13
0
 public int AddDevice()
 {
     return((!_isWin)
         ? LinuxInterop.tdAddDevice()
         : WinInterop.tdAddDevice());
 }
Example #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());
     }
 }
Example #15
0
 public int TurnOff(int deviceId)
 {
     return((!_isWin)
         ? LinuxInterop.tdTurnOff(deviceId)
         : WinInterop.tdTurnOff(deviceId));
 }
Example #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));
        }
Example #17
0
 public bool RemoveDevice(int deviceId)
 {
     return((!_isWin)
         ? LinuxInterop.tdRemoveDevice(deviceId)
         : WinInterop.tdRemoveDevice(deviceId));
 }
Example #18
0
 public int Learn(int deviceId)
 {
     return((!_isWin)
         ? LinuxInterop.tdLearn(deviceId)
         : WinInterop.tdLearn(deviceId));
 }
Example #19
0
 public int GetDeviceId(int order)
 {
     return((!_isWin) ? LinuxInterop.tdGetDeviceId(order) : WinInterop.tdGetDeviceId(order));
 }
Example #20
0
 public int Bell(int deviceId)
 {
     return((!_isWin)
         ? LinuxInterop.tdBell(deviceId)
         : WinInterop.tdBell(deviceId));
 }
Example #21
0
 public int LastSentCommand(int deviceId, int methods)
 {
     return((!_isWin)
         ? LinuxInterop.tdLastSentCommand(deviceId, methods)
         : WinInterop.tdLastSentCommand(deviceId, methods));
 }
Example #22
0
 public int GetDeviceType(int deviceId)
 {
     return((!_isWin) ? LinuxInterop.tdGetDeviceType(deviceId) : WinInterop.tdGetDeviceType(deviceId));
 }
Example #23
0
 public int GetNumberOfDevices()
 {
     return((!_isWin)
         ? LinuxInterop.tdGetNumberOfDevices()
         : WinInterop.tdGetNumberOfDevices());
 }
Example #24
0
 public int Methods(int deviceId, int methodsSupported)
 {
     return((!_isWin)
         ? LinuxInterop.tdMethods(deviceId, methodsSupported)
         : WinInterop.tdMethods(deviceId, methodsSupported));
 }