Skip to content

Working with the Source Code

JosiCoder edited this page Jan 27, 2019 · 16 revisions

Introduction

The C# projects available here are currently being developed mainly on Xubuntu 16.04, based on Mono and using the MonoDevelop IDE. They also work on the Raspberry Pi and can be built there as well. The same applies to Windows using Visual Studio and the .NET framework (tested recently with Visual Studio 2012 on Windows 7). As an exception, the frontend part using Gtk# 3 hasn't been tested on Windows so far (needs Gtk3 installed).

For creating the UI views' XML description files, Glade is recommended.

Some diagrams are being created with Dia (optional).

For all products mentioned so far, the versions from the repository of Xubuntu 16.04 are sufficient. Installing the packages git, monodevelop, monodevelop-nunit, monodevelop-versioncontrol, monodoc-browser, glade, and dia is recommended. The versions used here are as follows (slightly older versions work as well):

  • Mono 4.2.1 (can be obtained with mono --version or mcs --version. More details on Mono versioning.
  • MonoDevelop 5.10
  • Glade 3.18

The software was also tested on the Raspberry Pi. As .NET assemblies are portable, you can build the software either on your PC or on the Raspberry Pi. The versions used on the Raspberry Pi are:

  • Raspbian 8 (Jessie)
  • Mono 3.2.8
  • MonoDevelop 4.0.12
  • Glade 3.18

The VHDL projects are currently being developed using Xilinx ISE 11.1 on Xubuntu 16.04 (Xilinx ISE is also available for Windows).

Dependencies

3rd party components used within the C# projects are installed from NuGet. They will be downloaded automatically as soon as you open a solution for the first time (thus, loading takes a bit longer then). These dependencies are:

  • StructureMap
  • SpecsFor (including NUnit, Moq, ExpectedObjects, and Should), only for unit test projects
  • GtkSharp, only for the project containing the frontend views

Build

Clone the repository recursively as it contains Git submodules: git clone --recursive https://github.com/JosiCoder/CtLab.git

Building the FPGA Configuration

To build the programming file for the FPGA, do the following steps:

  • Load the "FPGA SigGen" project (FPGA SigGen.xise) into Xilinx ISE.

  • Ensure that the SPI connections (internal and/or external) that you intend to use are activated within the main VHDL module (Main.vhd). There are two constant definitions for this (use_internal_spi and use_external_spi). When you work with the c't-Lab FPGA device via its on-board controller, you typically only need the internal connection. The external connection can be used to connect an SPI master (e.g. a Raspberry Pi) directly to the board's FPGA.

  • Generate the programming file.

Building the Client Software

To build the software running on the PC side (i.e. not the VHDL part), do the following steps:

Build the CtLab library

  • Load the library solution (CtLabLibrary.sln), this also downloads all its dependencies from NuGet as necessary.
  • Build the solution and run all its unit tests.
  • Optionally, do some manual tests using the included Display.Demo and Signal.Demo programs.
  • The output of the solution is copied to a folder named Deployment.

Build the scope library

  • Load the library solution (ScopeLib.sln), this also downloads all its dependencies from NuGet as necessary.
  • Build the solution and run all its unit tests.
  • Optionally, do some manual tests using the included TestConsole. You might have to adjust the name of the serial port (see below).
  • The output of the solution is copied to a folder named Deployment.

Build the frontend

  • The frontend solution (CtLabFrontend.sln) depends on the output of the library solutions mentioned above, thus ensure that they are available via the paths Dependencies/CtLabLibrary and Dependencies/ScopeLibrary relative to the folder containing CtLabFrontend.sln. The easiest way to achieve this on Linux: Create a folder named Dependencies, change into it, and create symbolic links:
    ln -s ../../Library/Deployment/ CtLabLibrary
    ln -s ../../submodules/ScopeLib/Deployment/ ScopeLibrary
  • Load the frontend solution (CtLabFrontend.sln), this also downloads all its dependencies from NuGet as necessary. For the first time, you will get a notification that the Gtk# designer of MonoDevelop will be deactivated. As you do not need it, accept this and proceed.
  • Build the solution and run all its unit tests.
  • Optionally, do some manual tests using the included UI. You might have to adjust the name of the serial port (see below).
  • The output of the solution is copied to a folder named Deployment.

Instead of building from within MonoDevelop, you also can use the build scripts located in the solutions' folders. Build and deploy the library solution first, followed by the frontend solution.

If you run the client software on a Raspberry Pi, you can connect it directly to the FPGA using its SPI interface. In this case, there are some additional steps to do:

  • In the SpiNativeWrapper folder, use the Makefile to build a native wrapper library by simply typing: make
  • Copy the resulting libinterop.so file to the folder where your executables reside. This library uses the SPI device files of your Raspberry Pi to access the SPI interface. You must connect the MOSI, MISO, SCLK as well as the CE0 and CE1 pins properly. CE0 must be connected to RS and CE1 to DS. Ensure that your FPGA configuration matches that wiring.

Problems when compiling on a Raspberry Pi

Depending on your locale, you might get a CS0589 compiler error. In this case, ensure that your LANG environment variable is not set, then run your build or IDE. E.g.:

me@raspberrypi ~/ctlab $ echo $LANG
de_DE.UTF-8
me@raspberrypi ~/ctlab $ unset LANG
me@raspberrypi ~/ctlab $ monodevelop &

You can gain more information e.g. from this Xamarin Bugzilla Item (especially comment 46).

Configuration

You have to set the name of the serial port according to your local environment in order to access your c't-Lab hardware. Typical port names are COM1 on Windows or /dev/ttyS0 on Linux. Even if you connect your c't-Lab via USB, it is accessed via a virtual serial port. Thus, from the software's perspective, there is no difference between a USB and a serial connection. When using USB, you will often see COM3 on Windows or /dev/ttyUSB0 on Linux. Within the software, the serial port is set to /dev/ttyUSB0 by default. If you do not want to use hardware at all, you can set the serial port to Simulated.


Clone this wiki locally