Read Bytes with arduino uno from Computer

Hello, I am a student and I have a project with the arduino uno. For this program I what to read commands from the PC (labview) but more than one byte until a termination character comes. in the moment I am using this code (but this one only works for one byte):

void loop() { byte x; // check if data has been sent from the computer: if (Serial.available()) { // read the most recent byte (which will be from 0 to 255): x = Serial.read();

if( x == 'f' ){ myMotor->run(FORWARD); myMotor->setSpeed(255);} if( x == 'r' ){ myMotor->run(BACKWARD); myMotor->setSpeed(255);} if( x == 's' ){ myMotor->run(FORWARD); myMotor->setSpeed(0);} }}

Is this possible to realize it? if yes, how can I do this? And if not, is it possible to read more bytes (e.g. 4 bytes)? My aim is that I read a command from the computer which says the direction the motor should move and which speed! thank you very much for your help!

If you send the command “frs” for example out the serial port, it seems that it will function properly but the “f” and the “r” will set the direction and speed so fast you wont notice the change and only the final charachter “s” would set the mode long enough for the change to visibly take effect. You could use time delays, for example, or put the received chars into an array and work through them.
Even better:
You could make the first char the direction, and the next three the speed and the next three the duration of travel.

ex “f255100” forward full speed for 100 seconds.

Is this possible to realize it?

Yes. You mention reading serial input "until a termination character comes" but you are not doing it.

Have a look at http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=11425&page=1

When you post your code please post the whole program and not just part of it and put it in code tags as described in http://forum.arduino.cc/index.php?topic=97455.0 You should also consider using the Auto Format tool in the IDE to make it more redable.