public async Task <int> SendAsync(byte[] buffer, ConnectionType type, CancellationToken token) { return(type switch { ConnectionType.WiFi => await Task.Run(() => Connection.Send(buffer), token).ConfigureAwait(false), ConnectionType.USB => ConnectionUSB.SendUSB(buffer), _ => throw new NotImplementedException(), });
public void Disconnect() { if (Config.ConnectionType == ConnectionType.WiFi) { Log("Disconnecting from device..."); Connection.Shutdown(SocketShutdown.Both); Connection.BeginDisconnect(true, DisconnectCallback, Connection); Connected = false; Log("Disconnected!"); } else { Log("Disconnecting from USB device..."); ConnectionUSB.DisconnectUSB(); ConnectedUSB = false; Log("Disconnected!"); } }
public void Connect() { if (Config.ConnectionType == ConnectionType.WiFi) { if (Connected) { Log("Already connected prior, skipping initial connection."); return; } Log("Connecting to device..."); Connection.Connect(IP, Port); Connected = true; Log("Connected!"); } else { Log("Connecting to USB device..."); ConnectionUSB.ConnectUSB(); ConnectedUSB = true; Log("Connected!"); } }