How does a plug and play system know a device was connected. Polling?

83 Views Asked by At

In short, when a plug and play device is connected to a machine, how does the system realize it has been connected?

Is there basically an infinite loop that keeps looking for devices? Something like this:

std::vector<string> device_array; //ID's of all connected devices
main(){
    while(true){
        SetDevices();
        //Do whatever with the connected devices.
    }
}

void SetDevices(){
    int n = RS232_PollComport(cport_nr, buf, 4095); //get all connected devices

    //Add or remove devices from device_array list 
}

I'm just thinking USB as an example, I know it doesn't use an IRQ for the connected devices, but polling doesn't really seem right either. All other P&P details seem available, but I can't find the logic of how it knows a device is connected (Or has been disconnected).

Probably doesn't matter, but... I'm tasked with creating a bunch of plug and play sensors that will connect to a RaspberryPi and communicate over an rs232 connection using standard RX/TX communication with a pic16 for the P&P devices. The current code I am taking over is written with the constant polling and want to make sure there is not a better way before continuing.

Thanx ahead of time.

0

There are 0 best solutions below