private DacResponseDto Transmit(Span<byte> cmd) { _socket.Client.Send(cmd); var bytes = ReceiveResponse(); return DacResponse.ParseDacResponse(bytes); }
public DacResponseDto Begin(ushort pointRate = 30000) { BeginCommandDto cmd = new BeginCommandDto() { Command = COMMAND_BEGIN, LowWaterMark = 0, //not implemented PointRate = pointRate }; var serialized = Serialize<BeginCommandDto>(cmd); var response = Transmit(serialized); var ack = DacResponse.ParseAckCode(response.Response); return response; }
private void Heartbeat(object state) { if (!_socket.Connected && IsConnected) { DeviceDisconnected?.Invoke(); IsConnected = false; } if (!IsConnected) { // Try reconnect try { ConnectSocket(); DeviceConnected?.Invoke(); } catch (Exception e) { IsConnected = false; } } try { var response = Ping(); Span<byte> statusSpan = Serialize<DacStatusDto>(response.DacStatus); var dacStatus = DacStatus.ParseDacStatus(statusSpan); var ack = DacResponse.ParseAckCode(response.Response); StatusUpdated?.Invoke(ack, dacStatus.BufferFullness); } catch (Exception e) { } }