All sorts of nitty-gritty technical things.

Visual Studio, #pragma once not working?

Software development can sometimes be a comical affair, I have just been caught out badly by a strange gotcha – it appeared that #pragma once stopped working on a Visual Studio C++ project on which I have been working.  I was getting plenty of error messages about redefined classes! 


Well it turns out that I had left a copy of one of my header files lying around in one of the project folders.  As pragma once uses a header file’s full path to figure out if it has already opened it, a situation arose whereby both files were included and compile errors flooded in (despite the pragma onces)!


Well removing the (accidential) copy of the header file fixed the problem – boy do I feel stupid, I hope this post may help someone with a similar problem in the future!

.NET Convert.ToDecimal() and Scientific Notation

I ran into a problem the other day with .NET’s Convert.ToDecimal() , it turns out that it doesn’t handle scientific Notation! Pass it something like “8E-5” and the poor thing just throws an exception…


The software in which the problem surfaced was developed as a web application that must deal with numbers read from an Excel chart and so the formats encountered are many and varied!


This post points out that you can use this instead:


Decimal.Parse(val, System.Globalization.NumberStyles.AllowExponent);


But just to be safe I am now using:


Decimal.Parse(val, System.Globalization.NumberStyles.Any);


And it does work for Exponents, hopefully along with everything else!

Drupal – Radar/Polar charts with Chart API Module

I have been developing a web application for one of our clients using drupal, it’s a dashboard type data visualisation system that consumes and displays data over an intranet from their software systems.  I have been using google charts with great success.


The Chart API module for drupal is very nice, it lets you quite easily incorporate google charts into your web site or application without having to get into the details of the google chart API itself, and the charts themselves look great – just the kind of thing to cheer up a busy software developer.  However it deosn’t seem to support Radar or Polar charts.  There is no mention of them in the documentation, no example on the examples page.  There is also no symbol such as ‘CHART_TYPE_RADAR’ defined in the module as there is for the other chart types, for example ‘CHART_TYPE_LINE’ defined for line charts.


So is it possible to plot radar charts using the Chart API module?  I consulted the google chart api and found that the radar chart type is donated as ‘r’, so I tried creating a simple chart and just set it’s type to ‘r’ (rather than say CHART_TYPE_LINE) and it worked just fine!


$chart = array(
'#chart_id' => 'sink_radar',
'#title' => chart_title(t('Failures by Sink'), '001334', 15),
'#type' => 'r',
'#size' => chart_size(400, 240),
$chart['#data'][] = array(20, 30, 15, 70, 90, 20);
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] =
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] =
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] =
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] =
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] =
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] =
echo chart_render($chart);

 This code yileds a chart like this:


Radar Chart

Debian external disks – /dev/sda1 /dev/sdb1 randomly swapping

I ran into a funny problem recently with Ridge’s debian fileserver – I connected a second external USB drive to it and it stopped working! It always had one external USB drive connected, this was mapped to /dev/sda1 and auto-mounted in /etc/fstab along the lines of:


/dev/sda1    /mnt/usb   auto    rw    0       0


Everything was running nicely until I introduced a second usb device, this time a large flash disk onto which our automatic backup script is going to periodically dump an encrypted tarball (to provide an easy way for us to move encrypted backups off-site.)


Anyway, I saw that the second disk was mapped to /dev/sdb1 and I optimistically modified /etc/fstab to cater for the new flash disk along the lines of:


/dev/sda1    /mnt/usb   auto    rw    0       0
/dev/sdb1   /mnt/flash  vfat  rw,users,umask=0   0    0


So far so good, after reboot both file systems successfully mounted. But after the next reboot things were not as expected, the original disk was mounted onto the new ‘flash’ mount point and the FAT flash disk was not mounted at all!


With the second USB disk connected the way in which the disks were mapped to Linux devices would change randomly every time the system was rebooted – sometimes a disk would appear as /dev/sda1 and sometimes as /dev/sdb1.  As you can imagine this completely ruined the file system setup as configured in /etc/fstab!!


I had never encountered this before, but after a little research I found a work around – this involved mounting the disks by label rather than by the more traditional device name.


All labelled disks/volumes can be found in /dev/disk/by-label/ , these labels are static and can be used to mount their volumes (instead of using the non-static /dev/sda1 etc.).  Only labelled device appear in the by-label directory, so if you don’t see a disk you may have to give it a label using the tune2fs command. I had to give my original USB disk’s volume a label, I determined that it was currently mapped to /dev/sdb1 and issued the following command to label it as ‘external’:


tune2fs -L external /dev/sdb1


Now with both disks labelled I modified /etc/fstab as follows:


/dev/disk/by-label/external    /mnt/usb   auto    rw    0       0
/dev/disk/by-label/CORSAIR    /mnt/flash  vfat  rw,users,umask=0   0    0


And thankfully that fixed the problem! – with the IT systems purring along I can get back to the many more mundane aspects of running a software development consultancy…

Problem Debugging ASP with VS2005 and IE8

I was making some mods to an old ASP .NET web app today when I discovered that I could no longer properly debug it – when I started the debugger, VS2005 would launch IE8 and load the app but would then just detach and exit debug mode!  I have been running IE8 for a few months now and figured that the problem might have something to do with IE8 and sure enough it did!!


I found this excellent post which details a simple fix for the problem – I can now happily debug again!  It seems that the fix prevents IE8 from spreading itself across multiple processes this was confusing the poor VS2005 debugger..

Ubercart style add to cart button

Just in case I forget how to do it – here a link to a post that tells you how to change the add to cart button in ubercart,

very handy indeed!

.NET Remoting Events & Multihomed Host

I was on-site with a client at a pharamacutical production facility last week and they they showed me a strange problem that they were having with .NET Remoting running on a sub-network configured with a multihomed host that sits on both the sub-net and the factory ethernet.


The sub-network consisted of 11 Machine Vision inspection station PCs that happily inspect product on the production line and report their results and status asynchronously to a single ‘dashboard’ system running on the multi-homed host. We had developed the inspection stations with vanilla C++ and the ‘dashboard’ system in C# .NET, they all communicate via .NET Remoting.


The dashboard system connects to each of the inspection stations in turn and passes a remoting object of a shared interface, the inspection stations raise events across the sub-net by calling back on this shared interface.


All was well with tonnes of nice events being raised and received, until one day they all just stopped! The client was sure that nothing could have changed to cause this as the whole system was under qualification and therefore everything (software/configuration etc.) must stay static. However on further investigation it turned out that the dashboard PC had recently been added to the factory ethernet – and sure enough, once the factory network was whipped out and the dashboard restarted the events came flooding back!


Anyway it seems that when the dashboard system was connected to the factory network it communicated to the inspection stations using its factory NIC identity and IP address.  When the stations tried to callback they used this factory IP address and the callback events were lost as the PC knew of no  way to route the traffic onto the factory network (and hence back to the dashboard system).  On further investigation we found that the inspection station PCs (which were given static IP addresses) did not have a default gateway configured so we configured the dashboard’s local IP address as the gateway for each and the problem was solved!  This change ment that any network traffic destined for any network other than the local sub-net would be automatically sent to the dashboard system.

So, to cut a long and boring story short, if you’re having .NET remoting callback problems with a multihomed host take a look at the network configuration and make sure that t he PCs that raise the events are able to route them back to the receiver PC no matter which network it initially calls on..

Changing the ‘Home’ breadcrumb in Drupal 6

Here’s something I was googling last week – How do you change the text of Drupal’s ‘Home’ breadcrumb to something else? Well, it turns out that a small mod to your theme may be required…


While using Drupal 6 to develop a web application we ran into a little snag with Drupal’s breadcrumbs, the app is to integrate in with our client’s existing web site, it will look and feel the same and the visitor should not really know that it is separate from the main website (which is not implemented with drupal).  With drupal this was all easy enough to achieve, but we hit a speed bump when it came to the web app’s breadcrumbs.  Breadcrumb navigation is very important for the new web application, but Drupal always calls the first breadcrumb ‘Home’ – this was a problem as ‘Home’ did not refer to the larger web site’s home page as would be expected, but instead to the first page of the web application.


So how do we change the ‘Home’ breadcrumb text to something else, say the title of our web application?  It turns out that there’s no easy way to do this through settings, but thanks to this thread we can see that it is possible via a small change to the active theme. The modification hooks into phptemplate_breadcrumb(), it removes the existing primary breadcrimb (‘Home’) and then inserts a replacement with the new text.


So to make the change, edit your theme’s template.php file, and search for the function called:


[code lang="php"]phptemplate_breadcrumb() [/code]

rename it to:

[code lang="php"]original_phptemplate_breadcrumb() [/code]

Then paste in the following, changing ‘New Home Text’ to what ever you want your ‘Home’ breadcrumb to be called.

[code lang="php"]
function phptemplate_breadcrumb($breadcrumb)
  if (!empty($breadcrumb))
    // remove the exisitng Home link
    $old_home_link = array_shift($breadcrumb);
    // insert the new link
                   l(t('New Home Text'), ''));
    // Get the original function to
    // output the breadcrumb
    return original_phptemplate_breadcrumb($breadcrumb);

With this theme modification in place the breadcrumbs should display with the new text in place, bit of a pain but at least it’s do-able!



Hats off to gwen for the tip & code!

Editor Background – TinyMCE & Drupal 6

If you’re using the TinyMCE wsywig editor in drupal then you may find that the editor’s background color gets set to that of your website rather than being the more normal white-ish color – this can cause the wysiwyg editor look like the proverbial dog’s dinner and depending on your websites background color/image, can make reading the text very difficult.


Well, the good news is that it’s easily fixed – in Drupal, go to Adminsiter/Wysiwyg menu and for each import format with which you are using TinyMCE, click ‘edit’. Once in the settings editor click on the ‘CSS’ section and in the ‘Editor CSS’ drop-down choose ‘Editor default CSS’ and save. Do this for each import format and the editor’s background should revert to a calming white.

Auxiliary Display with Matrox Solios & Millenium P650

I ran into a problem while attempting to get an Auxiliary display to work on a Machine Vision system I was developing with a Matrox Solios Frame Grabber and a (dual head) Matrox Millenium P650 graphics card.  The plan was to have each vision station (in a Parmacutical AOI setup) output all of the images it acquired from its cameras to a massive 15 input digital video recorder (DVR) via its Auxiliary display port – in this way the client would have a record of all image acquired and processed on each of their 11 inspection stations   Anyway, while trying to initialise the display from code via a call to:

[code lang="cpp"] MdispAlloc(milSys, M_DEFAULT, "M_PAL", M_AUXILIARY,&milAuxDisplay); [/code]

Matrix Mil always reported that no system capable of supporting an Auxiliary display could be found – no matter how I changed the millions of possible settings, the auxiliary display would always fail to initialise – loads of hours later I became seriously worried that the Millenium P-Series graphics cards do not provide Auxiliary display support to Matrox Mil!


Mil Auxiliary Display Error


Well, it turns out that the P-Series graphics cards do provide Auxiliary display support to Mil, but in order to get it to work (in my case) an update needed to be applied to the Matrox graphics card driver – In my case I installed the update contained within, once applied the Auxiliary display worked just fine!


So anyway the moral of this story is that if you’re trying to get an Auxiliary display to work with Mil and you’re getting this error message no matter what you do – get on to Matrox and ask if there are any updates for your graphics card drivers and install them straight away!


PS  As the Mil documentation says, in order to get the Auxiliary display to work you will first have to disable the ‘dual-head’ functionality of your Matrox graphics card.  Now, with the newer Matrox graphics software ‘dual-head support’ is no longer called ‘dual-head support’, instead go into the Matrox ‘Power Desktop’ settings, and set the ‘Multi-Display Setup’ option to ‘1 Display (no feature display)’.


PPS It seems that where the Auxiliary display is concerned, the Matrox drivers are not very good at cleaning up their resources when the calling process ends – it is very important that you call MdispFree() on the Aux. display when your process is shutting down otherwise when you try to re-launch the process you will get the above error message every time you try to allocate the display until you reboot your system!