ScanService.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Team.Communicate.Client;
  7. namespace LogoForceTestApp.Services
  8. {
  9. public class ScanService : IScanService
  10. {
  11. private TeamTcpClient _teamTcpClient;
  12. public event EventHandler<string> ScanCompleted;
  13. public ScanService()
  14. {
  15. }
  16. public async Task<bool> InitAsync(string ip, int port)
  17. {
  18. _teamTcpClient?.Dispose();
  19. _teamTcpClient = new TeamTcpClient(ip, port) { IsAutoConnect = true };
  20. return await _teamTcpClient.ConnectAsync();
  21. }
  22. public string Read(string command)
  23. {
  24. return _teamTcpClient.SendAndReceiveString(command);
  25. }
  26. public Task<string> ReadAsync(string command)
  27. {
  28. return _teamTcpClient.SendAndReceiveStringAsync(command);
  29. }
  30. public void Close()
  31. {
  32. try
  33. {
  34. _teamTcpClient?.DisConnect();
  35. _teamTcpClient?.Dispose();
  36. }
  37. catch (Exception)
  38. {
  39. }
  40. }
  41. }
  42. }