I have posted numerous times around this issue.
You will need to use the adb command set to query currently connected devices (there is a -s and -e switch I believe to limit the query to emulators and real devices)
Once you have run this query, you can collect the results and re-query on them, specifically trying to query against a returned OS version, serial number, model name, or whatever.
I urge people to use resources like stack overflow or the web to do a little research :)