我尝试使用 python 3 和 pyvisa 1.8 与 GPIB 设备进行通信。
但是如何区分不同类型的例外。
例如:
try:
visa.ResourceManager().open_resources('COM1')
exception visa.VisaIOError:
<some code>
当打开失败时,它会生成一个一般异常 VisaIOError,但我怎么知道是端口忙还是端口不存在或其他什么?
喜欢:
try:
visa.ResourceManager().open_resources('COM1')
exception <1>:
# device busy
exception <2>:
# device does not exist
exception ...
我应该在 <1><2> 等位置正确捕获不同类型的异常?
谢谢