How can I make a window code work with linux?

Hay
I got this code

    /*Serial Control Test Program for Windows
    V 1.0
    Adam Borrell
    5/27/08*/

    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <conio.h>
    #include <time.h>

    //Function Prototypes
    HANDLE openPort(int);
    HANDLE comPort;

    //Global Variables
    int done=0;
    DWORD len;
    unsigned char buff[1];

    int main(){
       char input[32];
       int i;
       
       printf("Pololu Serial Servo Controller Test Program\n\n");
       
       comPort=openPort(1);//***PUT YOUR COM PORT NUMBER HERE!***
       if(done){
          printf("Program Terminated!\n");
          system("PAUSE");
          return -1;
       }
       
       printf("Commmands:\n");
       printf("F - Forward\n");
       printf("R - Reverse\n");
       printf("S - Stop\n");
       printf("BACKSPACE - Exit\n\n");

       while (!done) {//***Simple keyboard interface
          *input = getch();
          switch(*input){
             case 8://backspace
                done = 1;
                break;
             case'f':
             case'F':
                printf("FORWARD!\n");
                buff[0]=128;
                WriteFile(comPort,&buff,1,&len,0);
                break;
             case'r':
             case'R':
                printf("REVERSE!\n");
                buff[0]=129;
                WriteFile(comPort,&buff,1,&len,0);
                break;
             case's':
             case'S':
                printf("STOP!\n");
                buff[0]=130;
                WriteFile(comPort,&buff,1,&len,0);
                break;
             default:
                break;
          }
       }
       CloseHandle(comPort);
       printf("Program Terminated!\n");
       system("PAUSE");
       return 0;
    }

    HANDLE openPort(int portnum){
       char port[]="com", pnum[]="Error";
       itoa(portnum,pnum,10);
       strcat(port,pnum);
       
       HANDLE serial=CreateFile(port,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
       if(serial==INVALID_HANDLE_VALUE){
          if(GetLastError()==ERROR_FILE_NOT_FOUND){
             printf("Error, %s Not Found\n\a", port);
             done=1;
             return;
          }
          printf("Com Error\n\a");
          done=1;
          return;
       }

       DCB dcbSerialParams={0};
       dcbSerialParams.DCBlength=sizeof(dcbSerialParams);

       if(!GetCommState(serial, &dcbSerialParams)){
          printf("Com State Error\n\a");
          done=1;
          return;
       }

       dcbSerialParams.BaudRate=CBR_9600;//CBR_baudrate
       dcbSerialParams.ByteSize=8;
       dcbSerialParams.Parity=NOPARITY;//NOPARITY, ODDPARITY, EVENPARITY
       dcbSerialParams.StopBits=ONESTOPBIT;//ONESTOPBIT, ONE5STOPBITS, TWOSTOPBITS

       if(!SetCommState(serial, &dcbSerialParams)){
          printf("Serial Protocol Error\n\a");
          done=1;
          return;
       }
       
       COMMTIMEOUTS timeouts={0};
       timeouts.ReadIntervalTimeout=50;
       timeouts.ReadTotalTimeoutConstant=50;
       timeouts.ReadTotalTimeoutMultiplier=10;
       timeouts.WriteTotalTimeoutConstant=50;
       timeouts.WriteTotalTimeoutMultiplier=10;

       if(!SetCommTimeouts(serial,&timeouts)){
          printf("Timeout Setting Error\n\a");
          done=1;
          return;
       }
       
       return serial;
    }

and he was written for windows to connect the orangutan to a serial adapter.
when I try to make this code work in ubuntu I got lots of errors.
I know that the #include windows.h and #include conio.h are not in libs in ubuntu, but what can replace them?
Arbel

Hello Arbel,

The commands you use for accessing the serial port with C under Linux will be completely different from those that you use under Windows, unless you use a set of support libraries like WINE (for running Windows code under Linux) or Cygwin (for running Linux code under Windows), which is probably not worth the effort, since you are interested in using Linux only. I recommend that you study our Linux serial port control example which shows how to send bytes our to the serial port. The hard part to understand is the part that sets up the baud rate and various other parameters; after that it is straightforward to write bytes to the port.

Please let me know if you can’t get it to work!
-Paul

I got some questions:

  1. In the example you sent me, there is this function “sendcommand” that sends a command to the serial servo controller. in this function there is a nother function called “write”. I undarstend that is sending the data to the device. So, can I use only the write function?
/* write a message to the SSC */
void sendCommand(ssc *s, char id, char cmd, char servo, char data) {
  char buf[5];
  snprintf(buf,5,"%c%c%c%c%c",0x80,id,cmd,servo,data);
  write(s->fd,buf,5);
}
  1. this function sendes a stream of 5 bayets acording to the servo controller menual. I need to send a number to my orangutan. How can I use the write function to send a specific number, like 300?

Thanks
Arbel

Hello,
You can use just the write() function by itself; there’s no need to use my sendCommand() function if you aren’t connecting to a servo controller. To send the number 300, you’ll have to first decide how you want that represented as bytes. It may be that the easiest way is to send it as a string, just as you would in an email: the bytes ‘3’, ‘0’, ‘0’. The command would be write(s->fd, "300", 3).

-Paul

To open the connection, do I need to write connectSsc(ssc *s);?
Or do I have to put something else?
Arbel

I got a problem compiling the code…
this is the code:

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/select.h>
#include "ssc.h"

/* write a message to the SSC */
void sendCommand(ssc *s, char id, char cmd, char servo, char data) {
  char buf[5];
  snprintf(buf,5,"%c%c%c%c%c",0x80,id,cmd,servo,data);
  write(s->fd,buf,5);
}

void sendCommand6(ssc *s, char controller, char cmd, char servo, char data1, char data2) {
  char buf[6];
  servo += controller*16;
  snprintf(buf,6,"%c%c%c%c%c%c",0x80,0x01,cmd,servo,data1,data2);
  write(s->fd,buf,6);
}

int enable(ssc *s, int controller, int servo, int enabled) {
  if(!s->connected) { return 0; }

  if(enabled) {
    sendCommand(s,(char)controller,0,(char)servo,(char)0x40);
    printf("enabled %i\n",servo); fflush(stdout);
  } else {
    sendCommand(s,(char)controller,0,(char)servo,0x00);
    printf("disabled %i\n",servo); fflush(stdout);
  }

}

int stepTo(ssc *s, int controller, int servo, int pos) {
  if(!s->connected) { return 0; }

  sendCommand6(s,(char)controller,4,(char)servo,(char)(pos/128),(char)(pos%128));

  return 1;
}

void endSession(ssc *s) {
  if(!s->connected) return;
  close(s->fd);
}

int connectSsc(ssc *s) {
  struct termios options;
  int count,ret;

  s->connected=0; /* reset in case we fail to connect */

  s->fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY);
  if (s->fd == -1) return 0;
  else fcntl(s->fd, F_SETFL, 0);

  tcgetattr(s->fd, &options);

  /* go to 9600 baud */
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);

  options.c_cflag |= (CLOCAL | CREAD); /* enable */

  options.c_cflag &= ~PARENB; /* 8N1 */
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;

  /* set all of the options */
  tcsetattr(s->fd, TCSANOW, &options);

  s->connected=1;
  return 1;
}

const char *getId(ssc *s) {
  return s->idstring;
}
//Global variables
int done=0;
int main(void)
{
	char input[32];
	
	printf("Pololu serial adapter to orangutan program\n");
	//if we are done, don't continue
	if(done){
          printf("Program Terminated!\n");
          system("PAUSE");
          return -1;
	}
	
	printf("commands:\n\n");
	printf("Forward - w\n");
	printf("Reverse - s\n");
	printf("Stop - x\n");
	printf("Exit - Backspace\n\n");
	//connectSsc (ssc *s);//not sure its the right way to open the serialport
	while (!done)
	{
		*input=getch();
		switch(*input)
		{
			case 8://backspace
				done=1;
				break;
			case 'w':
				printf("Forward!\n");
				write(s->fd,"fwd",3);
				break;
			case 's':
				printf("Reverse!\n");
				write(s->fd,"back",4);
				break;
			case 'x':
				printf("Stop!\n");
				write(s->fd,"stop",4);
				break;
			default:
				break;
		}
	}
	//endSession (ssc,*s);//not sure that thats how I close connection
	return 1;
}

when I try to compile it I get this error:
arbelmichal@arbelmichal-desktop:~/Desktop/Documents/serial$ gcc -c serialport.c
serialport.c: In function ‘main’:
serialport.c:113: error: ‘s’ undeclared (first use in this function)
serialport.c:113: error: (Each undeclared identifier is reported only once
serialport.c:113: error: for each function it appears in.)

how do I define s?
Arbel

It looks like you have taken out part of the program: the code in ssc.c is where the serial port is initialized. What you need to do is remove any references to “s”, define your own variable “int fd” and initialize it using the commands described in detail in the tutorial here:

https://www.pololu.com/docs/0J4/4

If you can’t get them to work, please try going through the tutorial without modifications, and try to understand how every part works, before you make your own version.

I don’t understand, in the tutorial it says to initialize s->fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY);

I took nothing out from the original program, I just added a main function. and I understand that I need to use connectSsc function to open the connection to the serial port, and I need to use endSession to close the connection to the serial port. the thing is that these function needs parameters - *s & ssc. I don’t know what to put there. I couldn’t find anything about initializing fd or s in the tutorial. I must have missed it… :frowning:
Arbel

I took out the ‘s’, and added int fd;. this is my code at the moment:

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/select.h>
#include "ssc.h"

/* write a message to the SSC */
void sendCommand(ssc *s, char id, char cmd, char servo, char data) {
  char buf[5];
  snprintf(buf,5,"%c%c%c%c%c",0x80,id,cmd,servo,data);
  write(s->fd,buf,5);
}

void sendCommand6(ssc *s, char controller, char cmd, char servo, char data1, char data2) {
  char buf[6];
  servo += controller*16;
  snprintf(buf,6,"%c%c%c%c%c%c",0x80,0x01,cmd,servo,data1,data2);
  write(s->fd,buf,6);
}

int enable(ssc *s, int controller, int servo, int enabled) {
  if(!s->connected) { return 0; }

  if(enabled) {
    sendCommand(s,(char)controller,0,(char)servo,(char)0x40);
    printf("enabled %i\n",servo); fflush(stdout);
  } else {
    sendCommand(s,(char)controller,0,(char)servo,0x00);
    printf("disabled %i\n",servo); fflush(stdout);
  }

}

int stepTo(ssc *s, int controller, int servo, int pos) {
  if(!s->connected) { return 0; }

  sendCommand6(s,(char)controller,4,(char)servo,(char)(pos/128),(char)(pos%128));

  return 1;
}

void endSession(ssc *s) {
  if(!s->connected) return;
  close(s->fd);
}

int connectSsc(ssc *s) {
  struct termios options;
  int count,ret;

  s->connected=0; /* reset in case we fail to connect */

  s->fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY);
  if (s->fd == -1) return 0;
  else fcntl(s->fd, F_SETFL, 0);

  tcgetattr(s->fd, &options);

  /* go to 9600 baud */
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);

  options.c_cflag |= (CLOCAL | CREAD); /* enable */

  options.c_cflag &= ~PARENB; /* 8N1 */
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;

  /* set all of the options */
  tcsetattr(s->fd, TCSANOW, &options);

  s->connected=1;
  return 1;
}

const char *getId(ssc *s) {
  return s->idstring;
}
//Global variables
int done=0;
int fd;
int main(void)
{
	char input[32];
	
	printf("Pololu serial adapter to orangutan program\n\n");
	//if we are done, don't continue
	if(done){
          printf("Program Terminated!\n");
          system("PAUSE");
          return -1;
	}
	
	printf("commands:\n");
	printf("Forward - w\n");
	printf("Reverse - s\n");
	printf("Stop - x\n");
	printf("Exit - q\n\n");
	//connectSsc (ssc *s);//not sure its the right way to open the serialport
	while (!done)
	{
		*input=getchar();
		switch(*input)
		{
			case 'q'://exit program
				done=1;
				break;
			case 'w':
				printf("Forward!\n");
				write(fd,"fwd",3);
				break;
			case 's':
				printf("Reverse!\n");
				write(fd,"back",4);
				break;
			case 'x':
				printf("Stop!\n");
				write(fd,"stop",4);
				break;
			default:
				break;
		}
	}
	//endSession (ssc,*s);//not sure that thats how I close connection
	return 1;
}

When I run the program, every thing seem to be working (I didn’t connect the serial adapter yet…). But, when I write “w” to send the word “fwd” to the orangutan, the program prints the word that was supposed to been sent to the orangutan, to the terminal. I think I am not using the “write” function properly.
Arbel

Arbel,
Since you are just compiling your file alone, you are not using the code in ssc.c, which is where the serial port gets initialized. Take a look at that file, and the tutorial will make more sense.

Since you are not compiling ssc.c, you will need to take the initialization code out of there and put it into your main function.
-Paul

In my main function??? I put the code from ssc.c before my main function… Is there a way to link the ssc.c file to my program? or should I just add the entire code from ssc.c to the main function?
Arbel

I am sorry Paul, I went throw the tutorial over and over again. I cant understand what am I doing wrong!!!
I took what I thought that was the initializing part of the code and I putted it in the main function. I got the same error like in the first. I can’t compile the ssc.c code beacause there is no main function there, how will it work. And I don’t have a serial servo controller so I can’t try the code. Please tell me a something other then looking at the tutorial beacause I’ve done that for so many times!
how do I initialize the s->fd and how do I connect and disconnect to the serial port?

Okay, I think I understand a little better what you are trying to do now. I see that you’ve got the various functions from ssc.c copied into this file, but you are not calling ConnectSsc, which is the function containing the initialization code. If you don’t call it, it’s not going to run! Since you are not using a serial servo controller (SSC), I suggest that you rename everything containing the letters “SSC” to something more appropriate for your application. Then we’ll both be less confused. Next, finish changing s->fd to fd everywhere, and make sure you actually run the initialization code. You should totally remove the #include “ssc.h” and all references to s, which is of type ssc; it’s not necessary for you to deal with such a complicated data structure. The only other piece of data related to “s” in the code is s->connected, which you can just remove from the program. The main point is to get it to run those initialization commands to set up fd correctly.

-Paul

Will do, thanks! I’ll let you know how it goes :slight_smile:

Hay, steel compiling…
This is my new code:

/* functions for communicating with the pololu sadapter over a serial port */

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/select.h>

/* write a message to the SSC */
/*void sendCommand(Sadapter, char id, char cmd, char servo, char data) {
  char buf[5];
  snprintf(buf,5,"%c%c%c%c%c",0x80,id,cmd,servo,data);
  write(fd,buf,5);
}

void sendCommand6(Sadapter, char controller, char cmd, char servo, char data1, char data2) {
  char buf[6];
  servo += controller*16;
  snprintf(buf,6,"%c%c%c%c%c%c",0x80,0x01,cmd,servo,data1,data2);
  write(fd,buf,6);
}

int enable(Sadapter, int controller, int servo, int enabled) {
  if(!connected) { return 0; }

  if(enabled) {
    sendCommand((char)controller,0,(char)servo,(char)0x40);
    printf("enabled %i\n",servo); fflush(stdout);
  } else {
    sendCommand((char)controller,0,(char)servo,0x00);
    printf("disabled %i\n",servo); fflush(stdout);
  }

}

int stepTo(Sadapter, int controller, int servo, int pos) {
  if(!connected) { return 0; }

  sendCommand6((char)controller,4,(char)servo,(char)(pos/128),(char)(pos%128));

  return 1;
}
*/
int connected, fd, done=0;
char idstring[26];
void endSession(Sadapter) {
  if(!connected) return;
  close(fd);
}

int connectSadapter(Sadapter) {
  struct termios options;
  int count,ret;

  connected=0; /* reset in case we fail to connect */

  fd = open("/dev/ttyS1", O_RDWR | O_NOCTTY);
  if (fd == -1) return 0;
  else fcntl(fd, F_SETFL, 0);

  tcgetattr(fd, &options);

  /* go to 9600 baud */
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);

  options.c_cflag |= (CLOCAL | CREAD); /* enable */

  options.c_cflag &= ~PARENB; /* 8N1 */
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;

  /* set all of the options */
  tcsetattr(fd, TCSANOW, &options);

  connected=1;
  return 1;
}

int main()
{
	char input[32];
	
	if(done){
          printf("Program Terminated!\n");
          system("PAUSE");
          return -1;
       }
	
	printf("\n\nPololu Serial Adapter program\n\n");
	printf("Commands:\n");
	printf("Forward - w\n");
	printf("Reverse - s\n");
	printf("Stop - x\n");
	printf("Exit - q\n");
	//connect to serial adapter
	connectSadapter(Sadapter);
	
	while (!done)
	{
		*input=getchar();
		switch(*input)
		{
			case 'q'://exit the program
				done == 1;
				break;
			case 'w'://forward
				write(fd,"fwd",3);
				break;
			case 's'://reverse
				write(fd,"back",4);
				break;
			case 'x'://stop
				write(fd,"stop",4);
				break;
			default:
				break;
		}
	}
}
//const char *getId(Sadapter) {
  //return idstring;
//}

As you can see, there is no S, and I changed the ssc to Sadapter. Plus, Itook out all the functions besides the “connectSadapter” aka “connectSsc” and the end connection function. the problem is the argument in the connectSadapter function. I don’t know what to put there… in the original code I was supposed to put *s & ssc. Now that the s is gone and ssc was replaced by Sadapter, the argument I need to put there is Sadapter. But as I said, I don’t know what is it…

When you have something in a list of arguments to a function like “ssc *s” or “int i”, the “ssc” and the “int” are the types of the variables “ssc” and “int”. So if you are trying to stop using the variable s, you should remove the whole phrase “ssc *s”, not just the s part. Having an argument be named “Sadapter” with no type does not make any sense.

-Paul

So I should write connectSadapter(); and nothing more?

Yes, I think that would be a good start.

Hay
what about reading information from the orangutan to the computer? Is there a function like write, that reads information from the orangutan?

It’s not working!!!

Here is what I’ve done:
I connected the TX on the adapter to PD0 on the baby O.
I connected the RX on the adapter to PD1 on the baby O
I connected the GND on the adapter to the GNG on the baby O
I connected a led to PB0 and to GND on the baby O

here are the codes:

The baby O code:

    /*Serial Control Test Program for Orangutan or Baby Orangutan
    V 1.1
    Adam Borrell
    5/29/08*/

    #define F_CPU 20000000//CPU clock for Baby Orangutan
    //#define F_CPU 8000000//CPU clock for Orangutan
    //***Uncomment ONE of the above lines for the specific device***

    #define BAUD 9600//baud rate for UART
    #define MYUBRR (F_CPU/16/BAUD-1)//baud rate variable for UART hardware

    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <util/delay.h>

    unsigned volatile char dataIn,newSerCmd=0,wasPressedAlready=0;

    void USART_Init(unsigned int ubrr){//Initialize USART hardware & settings for Serial Radio
       UBRR0H=(unsigned char)(ubrr>>8);//set buad rate
       UBRR0L=(unsigned char) ubrr;
       UCSR0B=(1<<TXEN0)|(1<<RXEN0)|(1<<RXCIE0);//enable transmitter & receiver, receive complete interrupt
       UCSR0C=(3<<UCSZ00);//Set frame format for 8bit with 1 stop
    }

    void USART_Trans(unsigned char data){//Transmit a byte of data over USART
       while(!(UCSR0A&(1<<UDRE0)));//wait for transmition to complete
       UDR0=data;
    }

    ISR(USART_RX_vect){//USART Byte reieved
       dataIn=UDR0;//grab copy of serial byte
       newSerCmd=1;//indicate new byte received
    }

    int main(){
       DDRB|=(1<<PB0);//setup output pins
       

       USART_Init(MYUBRR);//Initialize USART
       sei();//enable global interrupts

       while(1){
          if(newSerCmd){//if new byte received
             switch(dataIn){
                case 'fwd'://forward
                   PORTB|=(1<<PB0);
				   //PORTD&=~(1<<PD5);
                   break;
                case 'stop'://reverse
                   PORTB&=~(1<<PB0);
                   //PORTD|=(1<<PD5);
                   break;
                case 130://stop
                   PORTB&=~(1<<PB1);
                   PORTD&=~(1<<PD5);
                   break;
                default:
                   break;
             }
             newSerCmd=0;
          }

          if((PINB&((1<<PB3)|(1<<PB4)|(1<<PB5)))){
             if(!wasPressedAlready){
                USART_Trans(131);//transmit byte
                wasPressedAlready=1;
             }
          }else if(wasPressedAlready){
             wasPressedAlready=0;
             _delay_ms(10);//debounce delay
          }
       }
       return 0;
    }

The computer code:

/* functions for communicating with the pololu sadapter over a serial port */

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/select.h>

/* write a message to the SSC */
/*void sendCommand(Sadapter, char id, char cmd, char servo, char data) {
  char buf[5];
  snprintf(buf,5,"%c%c%c%c%c",0x80,id,cmd,servo,data);
  write(fd,buf,5);
}

void sendCommand6(Sadapter, char controller, char cmd, char servo, char data1, char data2) {
  char buf[6];
  servo += controller*16;
  snprintf(buf,6,"%c%c%c%c%c%c",0x80,0x01,cmd,servo,data1,data2);
  write(fd,buf,6);
}

int enable(Sadapter, int controller, int servo, int enabled) {
  if(!connected) { return 0; }

  if(enabled) {
    sendCommand((char)controller,0,(char)servo,(char)0x40);
    printf("enabled %i\n",servo); fflush(stdout);
  } else {
    sendCommand((char)controller,0,(char)servo,0x00);
    printf("disabled %i\n",servo); fflush(stdout);
  }

}

int stepTo(Sadapter, int controller, int servo, int pos) {
  if(!connected) { return 0; }

  sendCommand6((char)controller,4,(char)servo,(char)(pos/128),(char)(pos%128));

  return 1;
}
*/
int connected, fd, done=0;
char idstring[26];
void endSession() {
  if(!connected) return;
  close(fd);
}

int connectSadapter() {
  struct termios options;
  int count,ret;

  connected=0; /* reset in case we fail to connect */

  fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY);
  if (fd == -1) return 0;
  else fcntl(fd, F_SETFL, 0);

  tcgetattr(fd, &options);

  /* go to 9600 baud */
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);

  options.c_cflag |= (CLOCAL | CREAD); /* enable */

  options.c_cflag &= ~PARENB; /* 8N1 */
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;

  /* set all of the options */
  tcsetattr(fd, TCSANOW, &options);

  connected=1;
  return 1;
}

int main()
{
	char input[32];
	
	if(done){
          printf("Program Terminated!\n");
          system("PAUSE");
          return -1;
       }
	
	printf("\n\nPololu Serial Adapter program\n\n");
	printf("Commands:\n");
	printf("Forward - w\n");
	printf("Reverse - s\n");
	printf("Stop - x\n");
	printf("Exit - q\n");
	//connect to serial adapter
	connectSadapter();
	
	while (!done)
	{
		*input=getchar();
		switch(*input)
		{
			case 'q'://exit the program
				done = 1;
				printf("Ending ssesion and exitting program\n");
				endSession();
				break;
			case 'w'://forward
				printf("Forward\n");
				write(fd,"fwd",3);
				break;
			case 's'://reverse
				printf("Reverse\n");
				write(fd,"back",4);
				break;
			case 'x'://stop
				printf("Stop\n");
				write(fd,"stop",4);
				break;
			default:
				break;
		}
	}
}
const char *getId() {
  return idstring;
}

I wanted that when I write ‘w’ on the computer, the program will send ‘fwd’ to the baby O and the led will light up. And when I write ‘x’ on the computer, the program will send ‘stop’ to the baby O and the led will stop working.
I tried to send ‘fwd’ using “cutecom” and still no good…