pynetanalyzer 1.0.1
Python wrapper for netANALYZER driver API
Requires Python: >=3.6

# netANALYZER Package

This is the python implementation for netANALYZER driver API.

## Prerequisites

 - An installation of the netANALYZER driver found on the [DVD](https://www.hilscher.com/products/product-groups/analysis-and-data-acquisition/ethernet-analysis/nanl-b500g-re/).
 - Python version 3.9 or higher
 - A netANALYZER device. 
 - pyshark for the example 

## Installation

The module is available to be installed via pip. 
``` 
pip install pynetanalyzer 
```

Alternatively you can install this source without PIP into your project folder. <br>

### Install pyshark using pip
The following example uses pyshark for packed parsing

```
pip install pyshark 
```

## Usage Example

Following is an example describing how to use the pynetanayzer package. In addition there is also described how to parse a captured frame with pyshark. 

``` python
import time
import pyshark
from pynetanalyzer import Netana

class Example(): 
  """ 
  This is a basic example for using the pynetanalyzer module in a class 
  """
  # define a frame granular callback processing each frame
  def framecallback(self, frame):
    self.frames.append(frame)

  def test(self):
    # create an instance
    netana = Netana()

    # open a device
    netana.open()

    # prepare an array for incomming frames
    self.frames = []
    
    # start capturing
    netana.start(self.framecallback)

    # wait while capturing
    time.sleep(2)

    # stop capturing
    netana.stop()
    
    # close device
    netana.close()
```

Simply import the module *pynetanalyzer* and create an instance of the class Netana. 

Define a callback function that processes the frame. <br>

Open the device by calling the **open** function. <br>
Call the **start** function with the *framecallback* as the argument. Capture is now running. <br>
For each frame the callback will be called individually. <br> 
Stop capturing when tha data of interest is captured by calling the **stop** function. <br>
Close the device when the device is no longer needed by calling the **close** function.

## Pyshark Example
This causes currently an exception on exit
``` got Future <Future pending> attached to a different loop ```

```python
    # How to use pyshark with the netanalyzer frame
    # create a pyshark InMemCapture interface
    c = pyshark.InMemCapture()

    # parse all frames at once
    packets = c.parse_packets(self.frames)
    
    # print the first parsed packet
    print(packets[0])
```

Create an instance of **pyshark.InMemCapture**. <br>
We can now call its member function **parse_packets** and hand our *frames* array over. The result will be an array of parsed packets from tshark.

## Frame Class
The Frame Class will instantiate a captured frame. 
It is an unmutable object. 
Following are the class members described. 

  | Member            | Description |
  |-------------------|-------------|
  | Frame.timestamp   | Arrivel time stamp of the frame
  | Frame.payload     | Contains the captured frame
  | Frame.errors      | Contains frame errors of type api.FrameErrors which is an enum.IntFlag object.
  | Frame.type        | Contains an enum either ethernetFrame, gpioEvent, fifoState or timeTick
  | Frame.mode        | Contains an enum either ethernet or transparent
  | Frame.port        | Reception port of the netANALYZER
  | Frame.tap         | Reception tap