/// <summary>
            /// Invoked when a ngMatt connects or disconnects to this software via usb or bluetooth.
            /// This method is the central point for new connections to ngMatts and is tasked to update any other part of this program concerning the newly connected device.
            /// </summary>
            private void Instance_NgMattDeviceConnected(object sender, CngMattSimulator device)
            {
                bNgMattConnected = true;
                Exception ex = CngMattServer.Instance.AddNewlyConnectedDevice(device);

                if (ex != null)
                {
                    Logger.AddLogEntry(Logger.LogEntryCategories.Error, "SimulatorControl.Instance_NgMattDeviceConnected(): exception while adding new device to CngMattServer", ex);
                    return;
                }

                List <string> connectedIds = new List <string>();

                connectedIds.Add(device.DeviceId);

                if (SimulatorConnectionChanged != null)
                {
                    SimulatorConnectionChanged(connectedIds);
                }
            }
            /// <summary>
            /// Searches for the specified simulator using its id in the list of the connected clients and returns it.
            /// </summary>
            /// <param name="id">The hardware device id of the simulator.</param>
            /// <returns>The CBaseSimulator object (either a CNetworkSimulator or a CSerialSimulator) or null.</returns>
            public SimulatorInterfaces.CBaseSimulator GetSimulatorById(string id)
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(null);
                }

                if (simulatorInstances.ContainsKey(id)) //check if the CNetworkSimulator for this id is already existing
                {
                    return(simulatorInstances[id]);
                }

                if (bSimulatorConncted)
                {
                    //try to return a CSerialSimulator
                    var serialDevice = from device in CSerialServer.Instance.GetConnectedSimulators() where device.DeviceId == id select device;

                    if (serialDevice.FirstOrDefault() != null)
                    {
                        simulatorInstances.Add(id, serialDevice.FirstOrDefault() as CSerialSimulator);
                        return(serialDevice.FirstOrDefault());
                    }
                }
                else if (bNgMattConnected) //ngMatt
                {
                    List <CngMattSimulator> ngMattDevices = ApiFunctions.Instance.GetConnectedDevices();

                    CngMattSimulator device = ngMattDevices.FirstOrDefault(d => d.DeviceId == id);

                    if (device == null)
                    {
                        return(null);
                    }

                    //map the ngMattDevice to CngMattSimulator (which derives from CBaseSimulator)
                    simulatorInstances.Add(id, device); //add it to the dictionary to make sure that always the same object is returned for the current id
                    return(device);
                }

                return(null);
            }