OP7100 - Reading from serial port speed.

I have written a program that is positioning an onbject by driving a conveyor motor and reading the distance to the object from a laser sensor with a serial output.

It works, but the issue im having is that i cannot get it to run quite fast enough. Currently i am using the below code to read from the serial port until i encounter a CR (termination of lasers measurment).

while (temp != CR && timeout < 50) {
	if (aascReadChar(Laser,&temp)) {
		laserresult[count] = temp;
		count++;
	}
	else {
		timeout++;
	}
}

I trigger the measurment and wait 200ms as this is the quickest the laser will ever respond. This allows some time for the display and control costatements to run. Ideally i would like to have an interrupt routine run every time something new was received on the serial instead of wasting time waiting for the result. I cannot just wait a fixed time because the sensor takes a different amount of time to send its result from 200ms to 1000ms.

Any suggestions? Whole Source is attached.

yeah i think there are some overheads, but with some careful tuning of the costates waitfor times i was able to get acceptable results.

also was having some timing issues getting half readings from the sensor and added some lines to flush the buffer before asking for a measurement and this improved things alot.

final measuring section of code; certainly i think it could be faster, but this was acceptable, considering i was using a fairly cheap touchscreen controller to actually run a system when i probably should have been using a standalone controller and just use the rabbit for hmi.

costate{
		if (measureon) {
			aascFlushRdBuf(Laser);
			aascWriteBlk(Laser,laserread,5,0);
			waitfor(DelayMs(200));    //adjust for measuring priority (less than 200 is pointless as laser never measures faster than that)
			measure();
			if (!lasererror) {
				if (controlon) {
					CoBegin(&control);
					waitfor(aascWriteBlk(Laser,laserread,5,0) && isCoDone(&control));
					CoReset(&control);
				}
			}
		}
	}