CAN Frame Stream IO Example + Relevant OOP layer changes#42
CAN Frame Stream IO Example + Relevant OOP layer changes#42
Conversation
nixnet/types.py
Outdated
|
|
||
|
|
||
| class CanFrame(object): | ||
| class CANFrame(object): |
There was a problem hiding this comment.
Please revert this back to standard PascalCase
| with nx.Session(database_name, cluster_name, list, interface1, input_mode) as input_session: | ||
| print('Input session created successfully.') | ||
| with nx.Session(database_name, cluster_name, list, interface2, output_mode) as output_session: | ||
| print('Output session created successfully.') |
There was a problem hiding this comment.
I don't think we need these "successful" prints
There was a problem hiding this comment.
I was following what XNET has for the C examples but maybe these are not necessary.
There was a problem hiding this comment.
I think it might make a little more sense in C which is compiled and doesn't have that great of error reporting mechanisms.
There was a problem hiding this comment.
I don't mind leaving the console output verbose. Having the extra output can't hurt a new user.
| # Start the input session manually to make sure that the first | ||
| # frame value sent before the initial read will be received. | ||
| input_session.start(constants.StartStopScope.NORMAL) | ||
| print('Input session started manually.') |
There was a problem hiding this comment.
Are we sure we need this print?
| try: | ||
| id = int(six.input('Enter identifier: ')) | ||
| except ValueError: | ||
| print('Not a number') |
There was a problem hiding this comment.
This will still crash when ValueError is thrown but instead because id is assigned never assigned in the except clause
There was a problem hiding this comment.
Maybe qualify the expected data format in the request. Something like 'Enter decimal identifier: 0d'
There was a problem hiding this comment.
I've formatted the request to incorporate the type we expect.
I'm now setting id in except as well.
| try: | ||
| payload_list = [int(x) for x in six.input('Enter payload: ').split()] | ||
| except ValueError: | ||
| print('Not a number') |
There was a problem hiding this comment.
Same as above. Elaborate on the expected format of the user input in the string.
| while True: | ||
| for byte in payload: | ||
| byte = byte + i | ||
| with types.CANFrame(id, extended, constants.FRAME_TYPE_CAN_DATA, payload) as frame: |
There was a problem hiding this comment.
why is this using a with-statement?
| for byte in payload: | ||
| byte = byte + i | ||
| with types.CANFrame(id, extended, constants.FRAME_TYPE_CAN_DATA, payload) as frame: | ||
| output_session.write_frame(list(frame), number_of_bytes_for_frames, 10) |
There was a problem hiding this comment.
- why
list(frame)? Do you mean[frame]? - Why are you passing the number of bytes?
- What is 10?
There was a problem hiding this comment.
- Yes I meant
[frame] - I thought I needed to based on incorrect assumption.
- timeout - I've added a variable for it now
nixnet/constants.py
Outdated
|
|
||
| TIMEOUT_NONE = _cconsts.NX_TIMEOUT_NONE | ||
| TIMEOUT_INFINITE = _cconsts.NX_TIMEOUT_INFINITE | ||
| FRAME_TYPE_CAN_DATA = _cconsts.NX_FRAME_TYPE_CAN_DATA |
There was a problem hiding this comment.
#43 is adding a constants.FrameType.CAN_DATA that you should instead be using
| i = 0 | ||
| while True: | ||
| for byte in payload: | ||
| byte = byte + i |
There was a problem hiding this comment.
Whats this loop trying to do?
There was a problem hiding this comment.
I've fixed the loop to do what I was intending. Increment the payload values before each write.
nixnet/nx.py
Outdated
|
|
||
| @intf_can_term.setter | ||
| def intf_can_term(self, value): | ||
| _props.set_session_intf_can_term(self._handle, value) |
There was a problem hiding this comment.
I've gone ahead and merged #45. Can you rebase this onto it and use my version of these properties?
| else: | ||
| input_session.intf_can_term = constants.CanTerm.ON | ||
| output_session.intf_can_term = constants.CanTerm.ON | ||
|
|
There was a problem hiding this comment.
We should explicitly set termination for both interfaces for clarity. I.e
if terminated_cable.lower() == "y":
output_session.intf_can_term = constants.CanTerm.OFF
input_session.intf_can_term = constants.CanTerm.ON
| for frame in frames: | ||
| print('Received frame: ') | ||
| pp.pprint(frame) | ||
|
|
There was a problem hiding this comment.
We may want to slow the loop down a bit so we don't have a wall of text in the output. 1 Second should be sufficient.
We can also format the output to be on a single line. Maybe have a initial line that is a header with the following lines formatted with data like so:
Data Transmitted | Data Received
FF FF FF 0A 1B CF FF 00 FF FF FF 0A 1B CF FF 00
FF FF FF 0A 1B CF FF 01 FF FF FF 0A 1B CF FF 01...
There was a problem hiding this comment.
I've slowed down the loop to 1 second.
I spoke to Jeff about changing the printing format and we decided that it's not critical at the moment and we'll handle example polishing in a different PR.
lilesj
left a comment
There was a problem hiding this comment.
The overall example structure looks good to use as a baseline for further examples.
b686b31 to
517d1c4
Compare
toxsuccessfully runs, including unit tests and style checks (see CONTRIBUTING.md).What does this Pull Request accomplish?
Adds Output to the CAN Frame Stream Input example and enhances the OOP API layer as needed.
Why should this Pull Request be merged?
This is a stepping stone to fleshing out the API.
What testing has been done?
None