Main Site Documentation

Conditional compilation tricks?


#1

Hi again, I have built a working system based on a Spider mainboard. I have now ported the code the Cobra II and it seems to be a good fit. But I would like to keep it all in one codebase. 20 years ago I rememer having some conditional compilations (it was the time of makefile bonanza).

I have looked at http://typecastexception.com/post/2012/08/18/Visual-Studio-Use-Conditional-Compilation-to-Control-Runtime-Settings-for-Different-Deployment-Scenarios.aspx

But none of that seems to work.

Anyone has any tips and tricks to share regarding multi-board compatibility in the code-base??


#2

I’m using configuration files on SD.
By this I initialize Network and IO’s.
To do so I made a HW-Library which loads it’s GPIO’s and other IO related channels from an XML file.
The file contains the Pin, glitchfilter, … for GPIO’s.
I can also define a channel type, by which I can add special implementations for an SPI Analog in chip, …
Each board gets a different file and I can access the IO channels by name.
This should work at least over most/all premium or OSHW boards, but mixing this would be more complicated.

Alternatively you can use classic #if #else #endif
unfortunately there is no way to add multiple release configurations anymore as in VS6 (at least not that I know. But you can have multiple VS projects using the same code files, if the project files are in the same folder. You can define the defines in the project settings then. I use this if I need a library for NETMF and Windows.


#3

The best way is to make your classes as generic as possible… and use a project file per board…

You can also use partial classes kind of like what gadgeteer does with the pre-generated code and programStarter…

Cheers,


#4

Another option is to make hardware specific classes and work with interfaces

see c# doc http://msdn.microsoft.com/en-us/library/87d83y5b(v=vs.110).aspx

at runtime you can set an interface to for example the FezSpider specific code or Cobra


#5

@ njbuch - You could use the technique I used in this solution:

https://www.ghielectronics.com/community/codeshare/entry/713

This solution supports two versions of the same application: full NET and a NETMF. I use file linking to share common “library” files between the two applications.