Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ComConnector
  9. {
  10.     public class Modul_I7044
  11.     {
  12.         private ComPort _comPort;
  13.  
  14.         public Modul_I7044(ComPort comPort)
  15.         {
  16.             _comPort = comPort;
  17.         }
  18.  
  19.         public int GetCountPort(int numberPort)
  20.         {
  21.             Thread.Sleep(100);
  22.             var result = _comPort.SendPort($"#0{numberPort.ToString()}0");
  23.             Thread.Sleep(100);
  24.             do
  25.             {
  26.                 result = _comPort.Answer;
  27.             } while (result == null);
  28.  
  29.             result = result.Substring(result.Length-3, 2);
  30.  
  31.             ClearCountPort(numberPort);
  32.             return int.Parse(result);
  33.         }
  34.  
  35.         public string ClearCountPort(int numberPort)
  36.         {
  37.             return _comPort.SendPort($"$0{numberPort}C0");
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement