Control Builder C development using Sublime Text and GCC

Recently I started a project using ABB Control Builder to program a AC500 PM573 PLC.

I need to write a collection of C functions that can be used in CoDeSys as functions & function blocks so the end user (PLC Programmer) doesn’t need to use Structured Text (ST) to write what would be complicated Pascal.

Control Builder doesn’t provide a C editor, so I chose something light as I don’t need a full IDE – Sublime Text 2. This is the first time I’ve used it.

Control Builder is also a bit dated and doesn’t seem to have keyboard shortcuts for compiling, so I created my own build system for AC500 C development. This is the sublime-build file I used, thanks to sublimetext.info:

C.sublime-build

{
    "cmd" : [
    	"C:\\GCC\\4.7.0\\bin\\powerpc-elf-eabi-gcc.exe",
    	"-I", "C:\\Program Files (x86)\\Common Files\\CAA-Targets\\ABB_AC500\\AC500_FWAPI",
    	"-mcpu=860",
    	"-fno-common",
    	"-msdata=none",
    	"-fno-jump-tables",
    	"-fno-section-anchors",
    	"-fno-merge-constants",
    	"-fno-builtin",
    	"-nostdlib",
    	"-Werror-implicit-function-declaration",
    	"-Wconversion",
    	"-std=c99",
    	"-c", "C_Code_App_Shell.c",
    	"-o", "C_Code_App.obj"
	],
    "shell" : true,
    "working_dir" : "$file_path",
    "path" : "C:\\GCC\\4.7.0\\bin"
}

You’ll notice the following things about this build definition:

  • It won’t work with the “automatic” setting as I don’t want it picking up any other C projects
  • It compiles a specific file only – C_Code_App_Shell.c – which is the same file compiled by Control Builder so your other included files should be included properly

Use at your own risk, and I recommend using Control Builder to finally build your code when ready for testing and production, but this is a handy way of using a modern editor in the meantime.

SPMetal fields retuning null, internal field name exceeds 32 chars

SPMetal is a great tool, of you don’t know SPMetal it’s an ORM tool that maps SharePoint objects to entity classes, it abstracts all of that CAML ugliness with a nice linq provider and it sort of works nicely. But as with almost everything in SharePoint it has its glitches.

I just come across a pretty nasty one. I have this entity that for some reason one of the fields was always returning null, no custom mappings completely auto-generated like the rest of my entities.

I have checked the generated CAML and the field is part of the viewfields parameter as expected. After a bit of debugging i realised that the internal field name didn’t match the one SPMetal was using to build the CAML. The reason is that apparently SharePoint truncates the internal field name if its length exceeds 32 characters. Now this should be fine but apparently SPMetal developers decided to hardcode the logic of conversion from display to internal, instead of querying the internal name when generating the entities. So a field named “Tools and Websites Link”, will be named internally as “Tools_x0020_and_x0020_Websites_x1”, and SPMetal will generate it as “Tools_x0020_and_x0020_Websites_x0020_Link”. Yep nasty.

There is a couple of solutions here, the most obvious one is to make your field name smaller, bear in mind that if you have spaces in your field name SharePoint replaces them with _x0020_ so if you have a lot of spaces you are guaranteed to hit this limit.

Another workaround is to manually set the internal field name as show in this post.

SharePoint Continuous Integration – The type or namespace name ‘xxx’ does not exist in the namespace ‘Microsoft.SharePoint’

There are multiple posts about setting up a SharePoint project building in a continuous integration server. One of the challenges assuming that SharePoint is not installed on the build server (as it shouldn’t) is to provide the necessary SharePoint assemblies for the build to happen. This is where out problems begun.

We decided to copy the libraries from 14ISAPI and keep them under source control for better portability. We could have installed them in the GAC witch would allow us to run multiple SharePoint project builds without having to provide all the necessary dlls all the time.

After getting all the assemblies and changing the references in the project to point our local versions we got several compilation errors building the project:

The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?

The type or namespace name 'Publishing' does not exist in the namespace 'Microsoft.SharePoint' (are you missing an assembly reference?)

The type or namespace name 'Taxonomy' does not exist in the namespace 'Microsoft.SharePoint' (are you missing an assembly reference?)

What stumped us is that we are including all those references. After spending an entire day trying different things we came across the problem. Publishing has a dependency on

System.Web.DataVisualization

Nothing on the error messages refer to this namespace. So After including the following library:

C:Program Files (x86)Microsoft Chart ControlsAssembliesSystem.Web.DataVisualization.dll

The project compiled as expected.