Block check character: If you need to calulate the block check character, here is a simple example:

Non writeable characters can be used with \x within sprintf.

//<SOH>P1<STX>(00000000)<ETX>a

test=sprintf("\x01P1\x02(00000000)\x03");
dump(test);

bcc=0;
for(i=1; i < strlen(test); i++) {
    bcc ^= ord(explode(test)[i]);
}
    printf("0x%x\n", bcc);

printf("CHR: %s", chr(bcc));