Well whist you guys were fighting I tried this and it seems to work. Thanks
template <class T> void sendAnything(const T& value)
{
const byte* p = (const byte*)(const void*)&value;
unsigned int i;
for (i = 0; i < sizeof(value); i++) {
if (*p == 0x7E || *p == 0x7D) { //byte stuffing
Serial.write(0x7D);
Serial.write(*p++ ^ 0x20);
} else {
Serial.write(*p++);
}
}
}