Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions nixnet/nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def close(self):

self._handle = None

def start(self, scope):
"http://zone.ni.com/reference/en-XX/help/372841N-01/nixnet/nxstart/"
_funcs.nx_start(self, scope)

def read_frame(
self,
number_to_read=constants.READ_ALL_AVAILABLE,
Expand All @@ -77,6 +81,13 @@ def read_frame(
"""
raise NotImplementedError("Placeholder")

def write_frame(
self,
frames,
timeout=10):
"http://zone.ni.com/reference/en-XX/help/372841N-01/nixnet/nxwriteframe/"
raise NotImplementedError("Placeholder")

@property
def application_protocol(self):
return constants.AppProtocol(_props.get_session_application_protocol(self._handle))
Expand Down Expand Up @@ -826,14 +837,6 @@ def read_state(
raise NotImplementedError("Placeholder")


def write_frame(
session_ref,
buffer,
number_of_bytes_for_frames,
timeout):
raise NotImplementedError("Placeholder")


def write_signal_single_point(
session_ref,
value_buffer):
Expand Down Expand Up @@ -909,12 +912,6 @@ def flush(
_funcs.nx_flush(session_ref)


def start(
session_ref,
scope):
_funcs.nx_start(session_ref, scope)


def stop(
session_ref,
scope):
Expand Down
44 changes: 0 additions & 44 deletions nixnet_examples/can_frame_stream_input.py

This file was deleted.

95 changes: 95 additions & 0 deletions nixnet_examples/can_frame_stream_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pprint
import six
import time

from nixnet import constants
from nixnet import nx
from nixnet import types


pp = pprint.PrettyPrinter(indent=4)


def main():
database_name = ':memory:'
cluster_name = ''
list = ''
interface1 = 'CAN1'
interface2 = 'CAN2'
input_mode = constants.CreateSessionMode.FRAME_IN_STREAM
output_mode = constants.CreateSessionMode.FRAME_OUT_STREAM

with nx.Session(database_name, cluster_name, list, interface1, input_mode) as input_session:
with nx.Session(database_name, cluster_name, list, interface2, output_mode) as output_session:
print('Are you using a terminated cable? Enter Y or N')
terminated_cable = six.input()
if terminated_cable.lower() == "y":
output_session.intf_can_term = constants.CanTerm.OFF
input_session.intf_can_term = constants.CanTerm.ON
else:
input_session.intf_can_term = constants.CanTerm.ON
output_session.intf_can_term = constants.CanTerm.ON

input_session.intf_baud_rate = 125000
output_session.intf_baud_rate = 125000

# 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)

try:
id = int(six.input('Enter identifier (int): '))
except ValueError:
print('Not a number. Setting identifier to 1')
id = 1

try:
payload_list = [int(x) for x in six.input('Enter payload [int, int, ...]: ').split()]
except ValueError:
print('Not a valid list of numbers. Setting payload to [2, 4, 8, 16]')
payload_list = [2, 4, 8, 16]

payload = bytearray(payload_list)
extended = False
frame = types.CanFrame(id, extended, constants.FrameType.CAN_DATA, payload)
write_timeout = 10

print('The same values should be received. Press q to quit')
i = 0
while True:
for index, byte in enumerate(payload):
payload[index] = byte + i

frame.payload = payload
output_session.write_frame([frame], write_timeout)
print('Sent frame with ID %s payload: %s' % (id, list(payload)))

# Wait 1 s and then read the received values.
# They should be the same as the ones sent.
time.sleep(1)

count = constants.READ_ALL_AVAILABLE
read_timeout = constants.TIMEOUT_NONE
frames = input_session.read_frame(count, read_timeout)
for frame in frames:
print('Received frame: ')
pp.pprint(frame)

i += 1
if max(payload) + i > 0xFF:
i = 0

inp = six.input()
if inp == 'q':
break

print('Data acquisition stopped.')


if __name__ == '__main__':
main()