Skip to content

*Session attributes handling enhancement and TcpSocketSession cleanup#116

Merged
bors[bot] merged 21 commits into
pyvisa:masterfrom
AnritsuSolutionsSK:session_attributes_handling
Dec 5, 2017
Merged

*Session attributes handling enhancement and TcpSocketSession cleanup#116
bors[bot] merged 21 commits into
pyvisa:masterfrom
AnritsuSolutionsSK:session_attributes_handling

Conversation

@skrchnavy

@skrchnavy skrchnavy commented Nov 30, 2017

Copy link
Copy Markdown
Contributor
  • Session.attrs table enhanced to support getter and setter methods, not only values
  • VI_ATTR_TMO_VALUE attribute handling unified to setup also self.timeout as value holder (can be used in sessions and is set to 'python' timeout - seconds as float or None for infinite)
    • _get_timeout/_set_timeout methods added and updated for places where external lib timeout is setup.
    • GPIBInstrSessiontimeout handling corrected (tested without HW if correct value is calculated in different conditions)
  • TCPIP Socket Session supports additional attributes (were not implemented)
    • Session.attrs table used for implementation with getters and setters
    • code cleanup to remove class attributes and use instance attributes
    • _pending_buffer is main buffer for handling received data, removed copying from temp buffer (out) and pending buffer

@skrchnavy skrchnavy changed the title Session attributes handling enhancement Session attributes handling enhancement and TcpSocketSession cleanup Nov 30, 2017
@skrchnavy

Copy link
Copy Markdown
Contributor Author

@MatthieuDartiailh code tested and ready for final review

@MatthieuDartiailh

Copy link
Copy Markdown
Member

I may need some time to review this. Hopefully I will merge sometimes next week.

@MatthieuDartiailh MatthieuDartiailh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall this looks really good. I left some minor comments. I will try to make a more thorough review later.

Comment thread pyvisa-py/sessions.py
@@ -181,7 +184,8 @@ def __init__(self, resource_manager_session, resource_name, parsed=None, open_ti
self.attrs = {constants.VI_ATTR_RM_SESSION: resource_manager_session,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you expand the above description to detail the possible values in the dictionary ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment added into after_parsing method of Session

Comment thread pyvisa-py/sessions.py Outdated
# therefore we must handle the case that the termination character is in the middle of the block
# or that the maximum number of bytes is exceeded
timeout = self.get_attribute(constants.VI_ATTR_TMO_VALUE)[0] / 1000.
timeout, _ = self.get_attribute(constants.VI_ATTR_TMO_VALUE)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why split this on two lines ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unified form of reading timeout in all *Session object

But now I seethis shall be changed to use `self.timeout, it is now properly filled containing python way of timeout (seconds + None) so can be used directly without double conversion.

Comment thread pyvisa-py/tcpip.py Outdated

ret_status = self._connect()
if ret_status != constants.StatusCode.success:
if ret_status != SUCCESS:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this change ?

@skrchnavy skrchnavy Dec 1, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is unification of return codes in this file with previous implementation, when SUCCESS was used, one way shall be followed, so which of these 3 options (see line 25 and 26 of this file):

  • SUCCES
  • StatusCode.success
  • constants.StatusCode.success

it is related other return codes in the file, when second form is used.

@MatthieuDartiailh

Copy link
Copy Markdown
Member

One stupid question: shouldn't timeout on the TCPIP session be a private attribute rather than a public one ? From my understanding it should only be set through the visa attribute and not directly.

@skrchnavy

skrchnavy commented Dec 1, 2017

Copy link
Copy Markdown
Contributor Author

Further changes / fixes in timeout handling added, some comments applied).

Regarding Session.timeout attribute: it is protected but also 'Session.attrs, Session.interfaceorSession.parsed` are protected. Candidate for writing new issue for this kind of refactoring.

How to cope with the SUCCESS naming convention? spread across Sessions. Which is prefered? (I like StatusCode.success way as it is used for reast of status codes and short enough.)

@skrchnavy skrchnavy changed the title Session attributes handling enhancement and TcpSocketSession cleanup *Session attributes handling enhancement and TcpSocketSession cleanup Dec 1, 2017
@skrchnavy

Copy link
Copy Markdown
Contributor Author

@MatthieuDartiailh #118 have to be resolved (merged or closed) before this issue (in conflict)

Comment thread pyvisa-py/tcpip.py
return bytes(out[:count]), constants.StatusCode.success_max_count_read
if term_char_en and term_byte in self._pending_buffer:
term_byte_index = self._pending_buffer.index(term_byte) + 1
if term_byte_index > count:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this check improves handling of case when requested less data then recevied and also terchar received. (#101)

# Conflicts resolved manualy:
#	pyvisa-py/sessions.py
#	pyvisa-py/tcpip.py

@MatthieuDartiailh MatthieuDartiailh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe that one comment is wrong but apart from this this is good to go for me.

Comment thread pyvisa-py/gpib.py Outdated
TIMETABLE = (0, 1e-2, 3e-2, 1e-1, 3e-1, 1e0, 3e0, 1e1, 3e1, 1e2, 3e2, 1e3, 3e3,
1e4, 3e4, 1e5, 3e5, 1e6)

# linux-gpib timeout constants, in milliseconds. See GPIBSession._set_timeout.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Those numbers are in second now no ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, i forgot to change comment properly

@MatthieuDartiailh

Copy link
Copy Markdown
Member

Merging. Thanks again @skrchnavy

bors r+

bors Bot added a commit that referenced this pull request Dec 5, 2017
116: *Session attributes handling enhancement and TcpSocketSession cleanup r=MatthieuDartiailh a=skrchnavy

* `Session.attrs` table enhanced to support getter and setter methods, not only values
* `VI_ATTR_TMO_VALUE` attribute handling unified to setup also self.timeout as value holder (can be used in sessions and is set to 'python' timeout - seconds as float or None for infinite)
  * `_get_timeout`/`_set_timeout` methods added and updated for places where external lib timeout is setup.
  * GPIBInstrSessiontimeout handling corrected (tested without HW if correct value is calculated in different conditions)
* TCPIP Socket Session supports additional attributes (were not implemented)
  * `Session.attrs` table used for implementation with getters and setters
  * code cleanup to remove class attributes and use instance attributes
  * `_pending_buffer` is main buffer for handling received data, removed copying from temp buffer (`out`)  and pending buffer
@bors

bors Bot commented Dec 5, 2017

Copy link
Copy Markdown
Contributor

Build succeeded

@bors bors Bot merged commit 1e05128 into pyvisa:master Dec 5, 2017
@skrchnavy skrchnavy deleted the session_attributes_handling branch December 6, 2017 08:47
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