I have taken an alerting system and built it to use at my station. That being said my programming knowledge is all self taught. Im hoping someone will be able to help me finish my last error or at least point me in the right direction.
The code below is the control program for a LED signboard. The lines towards the bottom that read "n = write(fd,"\x61\x1C\x32",2);" control the colors for the board. Now to the problem, the board displays any color it wants it is not following what it is supposed to. Any one have any help to give.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "betabrite.h"
#define DEFAULT_SERIAL_PORT "/dev/com1" /* Cygwin */
int OpenPort(char *serial_port) {
int fd ;
fd = open(serial_port, O_RDWR|O_NOCTTY|O_NDELAY) ;
if (fd == -1) {
perror("OpenPort: Unable to open port - ") ;
} else {
fcntl(fd,F_SETFL,0) ;
} /* if */
return(fd) ;
} /* OpenPort() */
/* SetupSerial() - open the serial port and setup comm parameters */
int SetupSerial(char *serial_port) {
struct termios options ;
int fd = OpenPort(serial_port) ;
tcgetattr(fd,&options) ;
/* 9600 baud */
cfsetispeed(&options,B9600) ;
cfsetospeed(&options,B9600) ;
options.c_cflag |= (CLOCAL|CREAD) ;
tcsetattr(fd,TCSANOW,&options) ;
/* 7 bits */
options.c_cflag &= ~CSIZE ;
options.c_cflag |= CS7 ;
/* even parity */
options.c_cflag |= PARENB ;
options.c_cflag &= ~PARODD ;
options.c_cflag &= ~CSTOPB ;
options.c_cflag &= ~CSIZE ;
options.c_cflag |= CS7 ;
/* software flow */
options.c_iflag |= (IXON | IXOFF | IXANY) ;
options.c_oflag &= ~OPOST;
options.c_oflag &= ~ONLCR;
options.c_oflag &= ~OCRNL;
tcsetattr(fd,TCSANOW,&options);
return(fd) ;
} /* SetupSerial() */
int main(int argc, char **argv) {
int fd;
int n;
char *serial_port = DEFAULT_SERIAL_PORT;
fd = SetupSerial(serial_port) ;
n = write(fd,"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",20) ;
n = write(fd,"\001Z00\002",5);
if(argv[1] == 'a' && argv[2] == 'a')
n = write(fd,"A0",2);
else {
n = write(fd,"A0\x1B ",3);
if(argv[2] == 'f')
n = write(fd,'c',1);
else
n = write(fd,'a',1);
if(argv[1] == 'g')
n = write(fd,"\x61\x1C\x32",2);
else if(argv[1] == 'r')
n = write(fd,"\x61\x1C\x31",2);
else
n = write(fd,"\x61\x1C\x38",2);
n = write(fd,argv[3],strlen(argv[3]));
}
//n = write(fd,"AA\x1B b",5);
//n = write(fd,"\x1C\x32\x08\x07A",3);
n = write(fd,"\004",1);
close(fd);
return(0);
}