You could just set your BytesAvailableFcnCount to 1. Then use a variable like global serialmode = 1;
to switch between different modes:
function testdummyfunction(testdummy,BytesAvailable)
global serialcom;
if (serialmode==1 && get(serialcom,'BytesAvailable')>=2)
data_string=fscanf(serialcom,'%c',2); %Reads the data sent from serialcom
elseif (serialmode==2 && get(serialcom,'BytesAvailable')>=8)
data_string2=fscanf(serialcom,'%c',8); %Reads the data sent from serialcom
end
Alternatively, a quicker solution if you always send 10 bytes is simply to set BytesAvailableFcnCount to 10, then read 2 then 8 bytes.
Another quick solution would be to set your remote device to send 8 bytes instead of 2 (you just send 6 zeros after the initial 2 sync bytes), and just use BytesAvailableFcnCount = 8 for everything.