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

Useful updates for future improvement #2

Merged
merged 17 commits into from
Sep 5, 2023

Conversation

dantonsa
Copy link
Contributor

Hello,

I have updated the pyOxygen package with new features:

  1. The fetchElog function, in case of an error from ':ELOG:FETCH?' would return an empty list (Can happen if elog has not yet started). I have modified it to return the value False, as is the case from 'NONE'.
  2. It is possible that, connecting to Oxygen, some transfer channels, as well as elog channels were already configured from a previous session. Therefore the attributes channelList and elogChannelList are updated at the __init__ using the helper functions _getTransferChannels and _getElogChannels.
  3. For the setElogTimestamp method, only the 'REL' and 'ABS´ arguments were available. the 'ELOG' was included.
  4. A new attribute called _localElogStartTime was created and included at __init__. This attribute is updated with the current datetime every time that the method startElog is called. The reason for that is to have a time reference to when the elog started so that functions in the future could be implemented, those functions will use this reference to stop the logging if a certain amount of time is reached.
  5. Added the elogContext method, which is a context manager that can be used in a with statement. The context manager starts the ELOG and stops it either when exiting the context or when an Exception occurs within the context. The following snipped exemplifies its usage:
with mDevice.elogContext():
    # Here elog is started, from here the fetchElog method can be called.
    time.sleep(10)
    data = mDevice.fetchElog()
    raise Exception
# Here stopElog is called even if the Exception is raised

I hope you find these changes useful. If so, I would like to improve more by creating another module containing functions that
record values from the Oxygen using multithreads or coroutines, while other instruments can be controlled and recorded as well.

Best regards
Danton

@dantonsa
Copy link
Contributor Author

dantonsa commented Sep 1, 2023

Hello,

With the new commits, I have changed/ included the following:

  • Issue with fetchElog() method: Previously, it fetched a big string and divided the comma-separated values evenly by the number of channels + 1 (timestamp), but if no elog timestamp is set (or "OFF"), this division makes was erroneous. I added a condition that the +1 should be there only if there are timestamps.
  • For the above-mentioned issue to be fixed, a new method called _getElogTimestamp() was created to get the timestamp from the command ":ELOG:TIM?" this saves the elog timestamp into an attribute called elogTimestamp. This method is also called at each connection.
  • A new private method called _convertElogArray() that converts a single array of string values from a fetchElog() list of arrays to an array of float values or datetime timestamps for the absolute timestamps. A new parameter was added to fetchElog(), called raw_string, which convert each row from the returned value using _convertElogArray() if False, the default is True for backwards compatibility.
  • A new method called fetchElogAccumulated() that blocks the execution and keeps calling fetchElog(), appending fetched values until a fetched timestamp is higher than the timestamp saved with the function call.

I hope you find these modifications useful and I am looking forward to keep contributing. Please let me know if there are any
questions.

Best regards
Danton

Copy link
Member

@matthiasstraka matthiasstraka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. Overall it looks very useful and I do not expect any problems for existing code based on this library. I added a few remarks that should be easy to fix.

oxygenscpi_example.py Outdated Show resolved Hide resolved
oxygenscpi_example.py Show resolved Hide resolved
pyOxygenSCPI/oxygenscpi.py Outdated Show resolved Hide resolved
pyOxygenSCPI/oxygenscpi.py Outdated Show resolved Hide resolved
pyOxygenSCPI/oxygenscpi.py Show resolved Hide resolved
pyOxygenSCPI/oxygenscpi.py Outdated Show resolved Hide resolved
@matthiasstraka matthiasstraka merged commit e9203cd into DEWETRON:main Sep 5, 2023
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants