Program.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using RTCommunicatorBase;
  2. using TLVProtocal;
  3. using UniversalNetFrame451.IO;
  4. namespace Test2;
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Test test = new();
  10. test.Initialize();
  11. test.Open("127.0.0.1", 50052);
  12. while (true)
  13. {
  14. byte mini8 = Convert.ToByte(Console.ReadLine());
  15. byte channel = Convert.ToByte(Console.ReadLine());
  16. test.Send(mini8,channel);
  17. }
  18. }
  19. }
  20. internal class Test : ITlvProvider
  21. {
  22. private ITlvCommunicatorServer? _server;
  23. public bool Initialize()
  24. {
  25. if (this._server is not null)
  26. return false;
  27. this._server = TlvFactory.GetTlvServer();
  28. this._server.Initialize(this);
  29. return true;
  30. }
  31. public bool Open(string IP, ushort port)
  32. {
  33. if (this._server is null)
  34. return false;
  35. return this._server.Open(IP, port);
  36. }
  37. public void Received(TlvData data)
  38. {
  39. }
  40. public TlvData RequestReply(TlvData tlvData)
  41. {
  42. return default!;
  43. }
  44. public void Connected(TcpConnection connection)
  45. {
  46. Console.WriteLine("Connected");
  47. }
  48. public void Disconnected(TcpConnection connection)
  49. {
  50. Console.WriteLine("Disconnected");
  51. }
  52. public bool Send(byte mini8, byte channel)
  53. {
  54. ST_ALARM alarm = new()
  55. {
  56. Mini8Index = mini8,
  57. ChannelIndex = channel,
  58. PV = 100,
  59. Caps = 120,
  60. Floor = 80,
  61. AlarmType = AlarmType.CapsOverFlow,
  62. };
  63. return this._server?.Send(1, alarm) == true;
  64. }
  65. }