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