Beispiel #1
0
        /// <summary>
        /// Pulls data in from an Omnik Solar Converter by connecting to it. Subscribe to the OmnikStatisticsAvailable event to retrieve the statistics once it completes.
        /// </summary>
        /// <param name="omnikAddress">IP Address or DNS name of the Omnik Solar Inverter to connect to</param>
        /// <param name="omnikPort">Port number of the Omnik Solar Inverter to connect on</param>
        /// <param name="serialNumber">Serial number of the Omnik Solar Inverter to which the connection will be made</param>
        public async Task PullData(string omnikAddress, string serialNumber, int omnikPort = DefaultOmnikPortNumber)
        {
            // Create a new data pull session and initiate it
            var dataPullSession = new DataPullSession(omnikAddress, omnikPort, serialNumber);

            dataPullSession.DataReceived          += HandlePullSessionDataReceived;
            dataPullSession.DataPullSessionFailed += HandleDataPullSessionFailed;
            await dataPullSession.RetrieveData();
        }
Beispiel #2
0
        /// <summary>
        /// Triggered when data is received based on a pull request
        /// </summary>
        /// <param name="receivedData">Byte array with the received data</param>
        /// <param name="session">The data pull session through which data has been received</param>
        private void HandlePullSessionDataReceived(byte[] receivedData, DataPullSession session)
        {
            // Check if there are subscribers for the raw Omnik data and signal them
            RawPullDataReceived?.Invoke(receivedData, session);

            // Check if there are subscribers to the completed data pull sessions and signal them. Allow for some variations in the received data length due to different firmware versions using different transmission lengths.
            if (OmnikStatisticsAvailable != null && receivedData.Length >= 130)
            {
                // Create the statistics
                var statistics = new Statistics(receivedData);
                OmnikStatisticsAvailable(statistics);
            }
        }