mkjeff/secs4net

State remains in Connected and not going into Selected

Mihai-BB opened this issue · 0 comments

Hi and thanks for sharing this secs library.
I am trying to use secs4net in testing with xunit. Basically just sending commands to a client and receiving the reply.
Your demo app works great but importing the code to a async xunit fact is not working.
I just used the code you wrote on the Enable button event and the connector state will not change to Selected and remains in Connected.
The options that Im using are:
Active:true
Ip: 127.0.0.1
DeviceId:0

Should I try setting also a custom T7 timeout?
Below is the code I am using (xunit test)
`
[Fact(DisplayName = "Check Host -> Client Connect")]
public async void Verify_SECS_HostConnection()
{
_secsGem?.Dispose();

        if (_connector is not null) await _connector.DisposeAsync();

        var options = Options.Create(new SecsGemOptions
        {
            IsActive = true,
            IpAddress = "127.0.0.1",
            Port = 5000,
            SocketReceiveBufferSize = 65535,
            DeviceId = 0,
        });

        _connector = new HsmsConnection(options, _logger);
        _secsGem = new SecsGem(options, _connector, _logger);

        _connector.ConnectionChanged += delegate
        {
            Console.WriteLine(_connector.State.ToString());
        };

        _ = _connector.StartAsync(_cancellationTokenSource.Token);

        try
        {
            await foreach (var primaryMessage in _secsGem.GetPrimaryMessageAsync(_cancellationTokenSource.Token))
            {
                recvBuffer.Add(primaryMessage);
            }
        }
        catch (OperationCanceledException)
        {

        }

}`

UPDATE:
After reviewing more detailed your code, I think this issue can be moved to closed: There was an exception generated by T7 timer which generated the problem and I was able to fix it myself