SwatInc / SwatInc.Lis.Lis01A2

This library is an OO implementation of the CLSI LIS01-A2 standard. Specification for Low-Level Protocol to Transfer Messages Between Clinical Laboratory Instruments and Computer Systems
GNU General Public License v3.0
17 stars 15 forks source link

Cannot send items to lis #4

Closed mgbee8 closed 2 years ago

mgbee8 commented 2 years ago

When calling LISParser.Connection.Connect(); the method never returns just sits in the ReceiveLoop and so never can call the send records method. Am I doing something incorrect. Just modified the example to separate order creation from order transmission and found this.

ibrahimhuycn commented 2 years ago

Will test and get back to you on this

ibrahimhuycn commented 2 years ago

I could not reproduce this issue. I have used the libraries from this repo in the project CD4.AstmInterface. Can you please check whether you can reproduce the issue with this project.

What settings are you using. Serial or ethernet(client or server)?

Here is some example code from CD4.AstmInterface. If you decide to check out CD4.AstmInterface, please use the branch named EvidenceInvestigator-RandoxLaboratories in this repo or use the updated master branch.


private async Task InitializeAstmAsync()
{
    switch (Settings.ConnectionMode)
    {
        case ConnectionMode.Ethernet: //if using ethernet
            var isPortValid = ushort.TryParse(Settings.Port.ToString(), out var uShortPort);
            if (!isPortValid) { _logger.Error($"Invalid port defined: {Settings.Port}. Max value allowed for port is 65535"); return; }

            _lowLevelConnection = new Lis01A02TCPConnection(Settings.IpAddress, uShortPort);
            _lisConnection = new Lis01A2Connection(_lowLevelConnection);

            await ConnectAsync();

            break;
        case ConnectionMode.Serial: // if using serial port
            _lowLevelConnection = new Lis01A02RS232Connection(Settings.SerialPort);
            _lisConnection = new Lis01A2Connection(_lowLevelConnection);
            await ConnectAsync();

            break;
        default:
            break;
    }
}

private async Task ConnectAsync()
{
    _lisParser = new LISParser(_lisConnection);

    _lisParser.OnSendProgress += LISParser_OnSendProgress; //Send data progress will trigger this event
    _lisParser.OnReceivedRecord += LISParser_OnReceivedRecord; //incoming LIS frames will trigger this event
    try
    {
        //open a socket and listen if physical layer is ethernet and configured as listener
        if (Settings.IsSever && Settings.ConnectionMode == ConnectionMode.Ethernet)
        {
            await ((Lis01A02TCPConnection)_lowLevelConnection).StartListeningAsync();
        }
        else //if the connection is serial or TCPIP and configured as client then just connect
        {
            _lisParser.Connection.Connect();
        }
    }
    catch (Exception ex)
    {
        _logger.Error($"Error connecting: {ex.Message}\n{ex.StackTrace}");
        MessageBox.Show(ex.Message);
    }
}
ibrahimhuycn commented 2 years ago

Sorry, closed by mistake, re-opened. Please feel free to comment again

ibrahimhuycn commented 2 years ago

I just understood your question, it is suppose to sit there in the ReceiveLoop. You just have to put it in another thread. It will raise events as data is received on socket. The above code and the AstmInterface should give you an idea.

Thanks for the issue.

mgbee8 commented 2 years ago

Thanks was able to get it working, have a different isue with the ENQ not responding. Not related to this project.

J4dJad commented 2 years ago

@mgbee8 i'v the same issue can you share how did you make it work plz ? ty