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); } }
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); } }
public string GetProtocol(int deviceId) { unsafe { return((!_isWin) ? AsString(LinuxInterop.tdGetProtocol(deviceId)) : AsString(WinInterop.tdGetProtocol(deviceId))); } }
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()))); } }
public string GetErrorString(int errorNo) { unsafe { return((!_isWin) ? AsString(LinuxInterop.tdGetErrorString(errorNo)) : AsString(WinInterop.tdGetErrorString(errorNo))); } }
public string LastSentValue(int deviceId) { unsafe { return((!_isWin) ? AsString(LinuxInterop.tdLastSentValue(deviceId)) : AsString(WinInterop.tdLastSentValue(deviceId))); } }
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); } }
//Interops public void Init() { if (_isWin) { WinInterop.tdInit(); } else { LinuxInterop.tdInit(); } _isInitialized = true; }
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); } }
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); } }
public void Close() { if (!_isInitialized) { return; } if (_isWin) { WinInterop.tdClose(); } else { LinuxInterop.tdClose(); } _isInitialized = false; }
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); }
public int AddDevice() { return((!_isWin) ? LinuxInterop.tdAddDevice() : WinInterop.tdAddDevice()); }
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()); } }
public int TurnOff(int deviceId) { return((!_isWin) ? LinuxInterop.tdTurnOff(deviceId) : WinInterop.tdTurnOff(deviceId)); }
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)); }
public bool RemoveDevice(int deviceId) { return((!_isWin) ? LinuxInterop.tdRemoveDevice(deviceId) : WinInterop.tdRemoveDevice(deviceId)); }
public int Learn(int deviceId) { return((!_isWin) ? LinuxInterop.tdLearn(deviceId) : WinInterop.tdLearn(deviceId)); }
public int GetDeviceId(int order) { return((!_isWin) ? LinuxInterop.tdGetDeviceId(order) : WinInterop.tdGetDeviceId(order)); }
public int Bell(int deviceId) { return((!_isWin) ? LinuxInterop.tdBell(deviceId) : WinInterop.tdBell(deviceId)); }
public int LastSentCommand(int deviceId, int methods) { return((!_isWin) ? LinuxInterop.tdLastSentCommand(deviceId, methods) : WinInterop.tdLastSentCommand(deviceId, methods)); }
public int GetDeviceType(int deviceId) { return((!_isWin) ? LinuxInterop.tdGetDeviceType(deviceId) : WinInterop.tdGetDeviceType(deviceId)); }
public int GetNumberOfDevices() { return((!_isWin) ? LinuxInterop.tdGetNumberOfDevices() : WinInterop.tdGetNumberOfDevices()); }
public int Methods(int deviceId, int methodsSupported) { return((!_isWin) ? LinuxInterop.tdMethods(deviceId, methodsSupported) : WinInterop.tdMethods(deviceId, methodsSupported)); }