Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.5 kB
1
Indexable
Never
 public bool Connection()
    {
        if (Media.IsOpen)
        {
            Disconnect(false);
        }
        try
        {
            Media.Close();
            Media.Open();

            GXReplyData reply = new();

            byte[] data;
            data = Client.SNRMRequest();
            if (data != null)
            {
                if (!ReadDataBlock(data, reply)) return false;
                Client.ParseUAResponse(reply.Data);
            }

            foreach (var it in Client.AARQRequest())
            {
                reply.Clear();
                if (!ReadDataBlock(it, reply)) return false;
            }

            Client.ParseAAREResponse(reply.Data);
            reply.Clear();

            if (Client.IsAuthenticationRequired)
            {
                foreach (var it in Client.GetApplicationAssociationRequest())
                {
                    reply.Clear();
                    if (!ReadDataBlock(it, reply)) return false;
                }

                Client.ParseApplicationAssociationResponse(reply.Data);
            }
        }
        catch (Exception ex)
        {
            Media.Close();
            OnMessage($"Возникла ошибка при подключении к ПУ: {ex.Message}");
            return false;
        }

        OnMessage("Успешное подключение к ПУ!");
        return true;
    }
Leave a Comment