Skip to content

Latest commit

 

History

History
182 lines (109 loc) · 3.81 KB

usage.rst

File metadata and controls

182 lines (109 loc) · 3.81 KB

Usage

Quick start

  1. Set up the frame parser:

    from nxslib.proto.parse import Parser
    parse = Parser()
  2. Initialize the communication interface.

    For a quick start, you can use a simulated NxScope device built into the library:

    from nxslib.intf.dummy import DummyDev
    intf = DummyDev()

    Alternatively, connect to the real NxScope serial device:

    serial_path = "/dev/ttyACM0"
    serial_buad = 100000
    intf = SerialDevice(serial_path, serial_baud)

    or device that support NxScope over Segger RTT interface:

    target_device = "STM32G431CB"
    buffer_index = 1
    upsize = 2048
    intf = RTTDevice(target_device, buffer_index, upsize)
  3. Create a NxScope instance and connect:

    from nxslib.nxscope import NxscopeHandler
    
    nxscope = NxscopeHandler(intf, parse)
    nxscope.connect()
    print(nxscope.dev)
  1. Subscribe to the channel data stream:

    q0 = nxscope.stream_sub(0)
    q1 = nxscope.stream_sub(1)
  2. Configure channels individually:

    # default configuration
    nxscope.channels_default_cfg()
    
    # enable channels
    nxscope.ch_enable(0)
    nxscope.ch_enable(1)
    
    # configure divider if supportd
    if nxscope.dev.div_supported:
        nxscope.ch_divider(0, 10)
        nxscope.ch_divider(1, 20)

    Channels configuration is buffered, so we have to explicitly write it to the device:

    nxscope.channels_write()

    You can verify channels configuration:

    print(nxscope.dev_channel_get(0).en)
    print(nxscope.dev_channel_get(1).en)
    print(nxscope.dev_channel_get(0).div)
    print(nxscope.dev_channel_get(1).div)
  3. Start the data stream and get data from queue:

    # start stream
    nxscope.stream_start()
    
    # get data from channel 0 queue
    data0 = q0.get(block=True, timeout=1)
    
    # get data from channel 1 queue
    data1 = q1.get(block=True, timeout=1)
    
    print(data0)
    print(data1)
  1. We done now, unsubscribe from queues:

    nxscope.stream_unsub(q0)
    nxscope.stream_unsub(q1)
  1. And disconnect from the device:

    nxscope.disconnect()

    IMPORTANT: this must be done manually ! Garbage collector will not help us.

Communication handler

Parser

For now only standard NxScope frames are supported.

It should be easy to implemented a custom protocol parser by providing a class derived from ICommFrame:

class OurCustomFrame(ICommFrame):
    pass # custom implementation

frame = OurCustomFrame()
parse = Parser(frame=frame)

Interfaces

If your NxScope device support DMA RX, you have to align data sending from client interface to the smallest value that will trigger DMA trasfer.

For this purpose there is intf.write_padding property that configure data padding for write method.

Dummy device interface

At default, dummy interface implements set of channels that generate various types of data.

You can define your own device, including channel implementation. Just use DummyDev class parameters: chmax, flags and channels.

Serial port interface

You can use socat to connect to a simulated NuttX target:

SERIAL_HOST={PATH}/ttyNX0
SERIAL_NUTTX={PATH}/ttySIM0

# run socat in background
socat PTY,link=$SERIAL_NUTTX PTY,link=$SERIAL_HOST &
stty -F $SERIAL_NUTTX raw
tty -F $SERIAL_HOST raw
stty -F $SERIAL_NUTTX 115200
stty -F $SERIAL_HOST 115200