# README Linux

The simplyCAN software package is delivered as .tar.gz archive, which includes the following components:

- simplyCAN library (so, static lib)

- Header file

- busmonitor

- Demo applications for C, C# and Python

- API documentation

- License

The instructions below are valid and tested for Ubuntu 22.04 LTS (Python 3.9). This may be different for other distributions.

## Installation Driver

- The USB interface is automatically installed when plugged in, without a driver installation. By default the device will be mapped to `/dev/ttyACMx`. The device name will be set by means of an udev rule in `60-simplyCAN.rules`.

- If the `modemmanager` is installed on your system, it may grab the device after plugged in. During this time, the device cannot be used by your application. This is prevented by a separate udev rule in `60-simplyCAN.rules`.

- To prevent both problems, copy the file `60-simplyCAN.rules` to the folder `/etc/udev/rules.d`

- To activate the new rules, execute the following command: `$ sudo udevadm control --reload-rules` and unplug the device and plug it back in.

- If user rights for using the simplyCAN device are missing, add your user name to the dialout group:

      $ sudo usermod -a -G dialout $USER

## Installation Bus Monitor

The simplyCAN Bus Monitor is installed with the following commands (tested for Ubuntu 20.04) If necessary, adapt the version number for `python3.9-tk` according to your Python version:

    $ sudo add-apt-repository universe
    $ sudo apt update
    $ sudo apt install python3-pip
    $ sudo pip3 install pyserial
    $ sudo apt install python3.9-tk
    $ cd busmonitor
    $ sudo pip3 install simplycan_busmonitor-1.3.0-py3-none-any.whl

The simplyCAN Bus Monitor can then be started with the following command:

    $ simplycan_busmonitor

​

## Usage of the Demo Applications

The demo applications are available for C, C# and Python. First the serial port has to be adapted according to your hardware setup. To determine the used serial port, you can:

- use the simplyCAN bus monitor

- use the command `ls -l /dev/serial/by-id`

- use a udev rule (see above)

- use the function `retrieve_serial_port()` (C and Python)

### C Demo

- Adapt the `k_SERIAL_PORT` and `k_BAUDRATE` defines in `demo.c` according to your hardware setup:

      #ifdef __unix__
      #define k_SERIAL_PORT      "/dev/ttyACM0"
      #else
      #define k_SERIAL_PORT      "COM1"
      #endif
      #define k_BAUDRATE         (250)

- Compile the demo with `make` and run the executable located in bin/

### C# Demo

- The C# demo is developed for .NET Core 2.0 from Microsoft. To run and build the demo application the .NET Core Runtime is required. .Net Core 2.x is currently not available for 32 bit Linux distributions.

- Adapt the name of the .so that provides the simplyCAN API in `simply.cs` according to your system:

      public const string SimplyCANlib = "simplyCAN.dll";    //  Windows 32bit
      public const string SimplyCANlib = "simplyCAN-64.dll"; //  Windows 64bit
      public const string SimplyCANlib = "simplyCAN.so";     //  ELF 64bit

- Adapt `mserial_port` and `mbitrate` in `demo.cs` according to your hardware setup:

      private static char[] mserial_port = "/dev/ttyACM0\0".ToCharArray();   // Linux
      //private static char[] mserial_port = "COM5\0".ToCharArray();   // Windows
      private static ushort mbitrate = 250;

- Before running the demo the `simplyCAN.so` has to be copied to `usr/lib/`

- Run the demo with `dotnet run demo.csproj`.

### Python Demo

- Adapt the COM port in `demo.py` according to your hardware setup:

      # main("/dev/ttyACM0", 250)    # for Linux
      main("COM6", 250)         # for Windows

  The value `250` is the used baudrate in kBaud.

- Run the demo with `python demo.py`.

## Copyright

(C) 2019-2022 HMS Technology Center Ravensburg GmbH
Helmut-Vetter-Strasse 2
88213 Ravensburg
Germany