Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSPDevice should raise error on failed connection and cbsdk should return runlevel #7

Open
dkluger opened this issue Mar 11, 2024 · 2 comments

Comments

@dkluger
Copy link

dkluger commented Mar 11, 2024

cbhw. should throw an error when the true instrument IP is not as configured. For example, on my 257-512ch hub, the instrument IP is hard coded to 192.168.137.201. I then tell python to use the instrument address 192.168.137.200 in the hub object, call cbsdk.connect with the hub object, and got no connection error. Confirmed that an error should have been received because run_level = 0 after cbsdk.connect() ran with no errors.

@cboulay
Copy link
Contributor

cboulay commented Mar 12, 2024

Currently an error is logged. This is what I get when I try to cbsdk.connect(device_obj, startup_sequence=True) when device_obj params points to an IP that I know is not connected.

Did not receive SYSREPRUNLEV in expected timeout.
Device did not reply to startup sequence. This could be caused by a network problem or by a protocol mismatch.

However, this is just a printout and it's easy to miss if you aren't paying attention. It does not raise an error.

This is one of those quirks that arises as a result of the cbsdk serving as a prototype to a C interface. In C, it's quite normal for a failed connection to return some sort of int that the client must check and act accordingly, e.g. by exiting gracefully. Whereas in Python, it's the norm to raise an error, and the client can catch the error and respond accordingly.

I would like to keep the pseudo-C interface in cbsdk. I think that your Python code should instead interface with nsp.NSPDevice.

But... that object's connect doesn't raise an error either yet, but it could, and without breaking my design! That would be more pythonic and user-friendly. For the pseudo-C API, the thin cbsdk layer can catch the error and return an error int.

This will require a bit of refactoring on my part.
In the interim, I suggest you modify your code to check that .connect(...) == 50.

@cboulay cboulay closed this as completed Mar 12, 2024
@cboulay cboulay changed the title No error reported when configured instr-addr and actual instr-addr are different NSPDevice should raise error on failed connection and cbsdk should return runlevel Mar 12, 2024
@cboulay cboulay reopened this Mar 12, 2024
@cboulay
Copy link
Contributor

cboulay commented Mar 12, 2024

I renamed the issue to reflect the work that needs to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants