The PKCS11interop library is a .NET implementation of the PKCS#11 standard for accessing cryptographic devices, including hardware security modules (HSMs). The library does not itself decide which HSM to connect to; rather, the application that uses the library will determine which HSM to use.
Typically, the application will specify the HSM to use by providing the appropriate parameters to the library. These parameters might include the HSM's IP address, port number, authentication credentials, and so on. The PKCS11interop library provides a number of classes and interfaces for managing the connection to the HSM, including the Pkcs11 class, which represents the PKCS#11 API, and the Slot class, which represents a slot on the HSM.
To change the connected HSM programmatically, you would need to modify the application code that uses the PKCS11interop library to specify a different set of parameters for connecting to the new HSM. Alternatively, you could create multiple instances of the Pkcs11 class, each with different parameters, and switch between them as needed.
It's worth noting that different HSMs may have different capabilities and support different cryptographic algorithms, so you'll need to ensure that the HSM you choose is capable of performing the operations you require. Additionally, you'll need to ensure that the HSM is properly configured and that your application is authorized to access it.