#include #include #include #include #include #include #define BAUDRATE B19200 #define MODEMDEVICE "/dev/cua0" #define _POSIX_SOURCE 1 /* POSIX compliant source */ #define FALSE 0 #define TRUE 1 volatile int STOP=FALSE; void SetPWM(unsigned char value); int fd; main(int argc, char **argv) { int c, res; unsigned char pwmvalue; struct termios oldtio,newtio; unsigned char buf[255]; int i,count; long position; argc--;*argv++; if(argc-- > 0) pwmvalue = atoi(*argv++); printf("Setting PWM value = %d\n",pwmvalue); fd = open(MODEMDEVICE, O_RDWR); if (fd <0) {perror(MODEMDEVICE); exit(-1); } tcgetattr(fd,&oldtio); /* save current port settings */ /* bzero(newtio, sizeof(newtio)); */ newtio.c_cflag = BAUDRATE | CS8 | CREAD; newtio.c_iflag = 0; newtio.c_oflag = 0; /* set input mode (non-canonical, no echo,...) */ newtio.c_lflag = 0; newtio.c_cc[VTIME] = 0; /* inter-character timer unused */ newtio.c_cc[VMIN] = 0; /* blocking read until 1 chars received */ tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); SetPWM(pwmvalue); tcsetattr(fd,TCSANOW,&oldtio); } void SetPWM (unsigned char value) { unsigned char a[40]; int i = 0; int j; unsigned char sum = 0; int ret; a[i++] = 0xAA; a[i++] = 0x01; a[i++] = 0x24; a[i++] = 0xc8; a[i++] = value; printf("In SetPWM: value = %d\n",value); sum = 0; for(j=1;j