0

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.

VirtualLife
  • 402
  • 5
  • 14
  • *"I know it doesn't use an IRQ"* - really? I understood that's exactly how USB host controllers worked, one interrupt if anything was connected/disconnected from the port, and then scan for changes. I guess one of us is mistaken? – Roger Rowland Dec 10 '15 at 05:48
  • From what I read, there is an IRQ used at the machine level, but not for each device. Details seem a bit sparse on this level tho. – VirtualLife Dec 10 '15 at 16:00
  • Yes that's my understanding too. One interrupt from the USB controller which triggers a scan for new or lost devices. I guess that doesn't help your question though. – Roger Rowland Dec 10 '15 at 16:22
  • It doesn't, at least not the way I am thinking, but may be wrong. The USB controller takes the IRQ, but when the USB device is added to the controller, it doesn't take an IRQ, but somehow the controller knows it's there. To me, the devices and how the controller knows there connected is separate from the IRQ. – VirtualLife Dec 11 '15 at 23:36

0 Answers0