/// <summary> /// Stops Receiving command from publisher. /// </summary> public static void StopReceiving() { IsSubscriberEnabled = false; if (Subscriber != null) { Subscriber.Stop(); } Subscriber = null; }
/// <summary> /// Starts receiving commands from publisher with given IP address. /// After calling this function, an event will be thrown every time a data received. /// Process this data either in a thread or in the event itself(not recommended for big data) /// </summary> /// <param name="ip">Ip Address of Publisher</param> public static void StartReceiving(string ip) { TargetIP = ip; if (!IsSubscriberEnabled) { Subscriber = new MQSubscriber(Topic, TargetIP, Port); Subscriber.OnDataReceived += Subscriber_OnDataReceived; Thread_Control = new Thread(Control_CoreFcn); Thread_Control.Start(); } IsSubscriberEnabled = true; }
public MQSubscriberTests() { IServiceCollection services = new ServiceCollection(); services.AddLogging(); services.AddSingleton(typeof(IKeyedServiceCollection <,>), typeof(KeyedServiceCollection <,>)); services.AddSingletonNamedService(providerName, (s, key) => eventSubscriber.Object); services.AddSingletonNamedService(providerName + "1", (s, key) => eventSubscriber.Object); IServiceProvider sp = services.BuildServiceProvider(); subscriber = new MQSubscriber(sp, internalConfiguration.Object, sp.GetRequiredService <ILogger <MQSubscriber> >()); }
public static void StartReceiving(string ip) { CommunicationPeriod = 1.0 / CommunicationFrequency; TargetIP = ip; Subscriber = new MQSubscriber(Topic, TargetIP, Port); Subscriber.OnDataReceived += Subscriber_OnDataReceived; TimeBaseSubscriber = new MQSubscriber(TimeBaseTopic, TargetIP, TimeBasePort); TimeBaseSubscriber.OnDataReceived += TimeBaseSubscriber_OnDataReceived; SubStopwatch = Stopwatch.StartNew(); CommunicationType = CommunicationTypes.Receiver; IsReceiverThreadEnabled = true; ReceiverThread = new Thread(ReceiverCoreFcn); ReceiverThread.Start(); }
public static void StopReceiving() { if (Subscriber != null) { Subscriber.OnDataReceived -= Subscriber_OnDataReceived; Subscriber.Stop(); Subscriber = null; } if (TimeBaseSubscriber != null) { TimeBaseSubscriber.OnDataReceived -= TimeBaseSubscriber_OnDataReceived; TimeBaseSubscriber.Stop(); TimeBaseSubscriber = null; } IsReceiverThreadEnabled = false; FPS = 0; TransferSpeed = 0; }