public UartControllerApiWrapper(NativeApi api) { this.Api = api; this.impl = api.Implementation; this.Acquire(); this.clearToSendChangedDispatcher = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.Uart.ClearToSendChanged"); this.dataReceivedDispatcher = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.Uart.DataReceived"); this.errorReceivedDispatcher = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.Uart.ErrorReceived"); this.clearToSendChangedDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => { if (this.Api.Name == apiName) { this.clearToSendChangedCallbacks?.Invoke(null, new ClearToSendChangedEventArgs(d0 != 0, ts)); } }; this.dataReceivedDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => { if (this.Api.Name == apiName) { this.dataReceivedCallbacks?.Invoke(null, new DataReceivedEventArgs((int)d0, ts)); } }; this.errorReceivedDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => { if (this.Api.Name == apiName) { this.errorReceivedCallbacks?.Invoke(null, new ErrorReceivedEventArgs((UartError)d0, ts)); } }; }
public UsbHostControllerApiWrapper(NativeApi api) { this.Api = api; this.impl = api.Implementation; this.Acquire(); this.onConnectDispatcher = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.UsbHost.OnConnectionChanged"); this.onConnectDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => { if (this.Api.Name == apiName) { var id = (uint)d0; var connection = (DeviceConnectionStatus)d3; var interfaceIndex = (byte)d1; var deviceType = (DeviceType)d2; GetDeviceInformation(id, out var vendor, out var product, out var port); var deviceConnectedEventArgs = new DeviceConnectionEventArgs(id, interfaceIndex, deviceType, vendor, product, port, connection); this.onConnectionChangedCallbacks?.Invoke(null, deviceConnectedEventArgs); } }; }
public SerialPort(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits) { m_portName = portName; m_config = new Configuration(portName, baudRate, parity, dataBits, stopBits); m_fDisposed = false; m_fOpened = false; m_evtErrorEvent = new NativeEventDispatcher("SerialPortErrorEvent", (ulong)m_config.PortIndex); m_evtDataEvent = new NativeEventDispatcher("SerialPortDataEvent", (ulong)m_config.PortIndex); }
/// <summary> /// Start this controller /// </summary> /// <returns></returns> public bool Start() { if (_dispatcher != null) { return(true); } _dispatcher = new NativeEventDispatcher("Community_Hardware_UsbHost_Driver", 0); _dispatcher.OnInterrupt += Dispatcher_OnInterrupt; return(NativeStart()); }
/// <summary> /// Stop this controller /// </summary> /// <returns></returns> public bool Stop() { if (_dispatcher == null) { return(true); } _dispatcher.OnInterrupt -= Dispatcher_OnInterrupt; _dispatcher.Dispose(); _dispatcher = null; return(NativeStop()); }
/// <summary> /// Dispose native resources /// </summary> public void Dispose() { if (_dispatcher == null) { return; } _dispatcher.OnInterrupt -= Dispatcher_OnInterrupt; _dispatcher.Dispose(); _dispatcher = null; Uninitialize(); }
/// <summary> /// Initialize a new <see cref="QuadratureEncoder"/> /// </summary> public QuadratureEncoder(QuadratureEncoderChannel channel, CountMode mode) { //Do not use HardwareProvider to keep the feature independant : //no HardwareProvider.HwProvider.GetQuadratureEncoderChannelCount(); //no HardwareProvider.HwProvider.GetQuadratureEncoderPinsForChannel(...); //-> if a solution doesn't need this feature, no stub is required _channel = channel; _mode = mode; GetQuadratureEncoderPinsForChannel(channel, out _pin_A, out _pin_B); Initialize(); _dispatcher = new NativeEventDispatcher("Community_QuadratureEncoder_Driver", 0); _dispatcher.OnInterrupt += Dispatcher_OnInterrupt; }
public NetworkControllerApiWrapper(NativeApi api) { this.Api = api; this.impl = api.Implementation; this.Acquire(); this.networkLinkConnectedChangedDispatcher = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.Network.NetworkLinkConnectedChanged"); this.networkAddressChangedDispatcher = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.Network.NetworkAddressChanged"); this.networkLinkConnectedChangedDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => { if (this.Api.Name == apiName) { this.networkLinkConnectedChangedCallbacks?.Invoke(null, new NetworkLinkConnectedChangedEventArgs(d0 != 0, ts)); } }; this.networkAddressChangedDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => { if (this.Api.Name == apiName) { this.networkAddressChangedCallbacks?.Invoke(null, new NetworkAddressChangedEventArgs(ts)); } }; }
public UsbClientControllerApiWrapper(NativeApi api) { this.Api = api; this.impl = api.Implementation; this.Acquire(); this.dataReceivedDispatcher = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.UsbClient.DataReceived"); this.dataReceivedDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => { if (this.Api.Name == apiName) { this.dataReceivedCallbacks?.Invoke(null, (uint)d0); } }; this.deviceStateChangedDispatcher = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.UsbClient.DeviceStateChanged"); this.deviceStateChangedDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => { if (this.Api.Name == apiName) { this.deviceStateChangedCallbacks?.Invoke(null, (DeviceState)d0); } }; }
/// <summary> /// Dispose native resources /// </summary> public void Dispose() { _dispatcher.OnInterrupt -= Dispatcher_OnInterrupt; _dispatcher.Dispose(); _dispatcher = null; }
/// <summary> /// Initialize a new <see cref="QuadratureEncoder"/> /// </summary> public QuadratureEncoder() { _dispatcher = new NativeEventDispatcher("QuadratureEncoder_Driver", 0); _dispatcher.OnInterrupt += Dispatcher_OnInterrupt; }
public static void EnableReceiveInterrupt() { m_evtDataEvent = new NativeEventDispatcher("Angelos_PacketReceivedEvent", 0); m_evtDataEvent.OnInterrupt += m_evtDataEvent_OnInterrupt; }