hi everyone...
Can anyone help me to build the code to link my c language to the mysql server...this program wiill receive the data from the RFID tag using the serial connection then the data will send into mysql server.. now i dont now how to write the program to connection to mysql server .... Can you all help me....
this my code to get the data from serial ..
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>
#define BAUDRATE B2400
#define MODEMDEVICE "/dev/ttyr01"
#define _POSIX_SOURCE 1
#define FALSE 0
#define TRUE 1
volatile int STOP=FALSE;
main()
{
int fd,c,res,i;
struct termios oldtio , newtio;
char buf[20];
FILE *fid;
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
if (fd<0) {perror(MODEMDEVICE);
exit(-1);
}
tcgetattr (fd,&oldtio);
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR | ICRNL;
newtio.c_oflag = 0;
newtio.c_lflag = ICANON;
tcflush(fd, TCIFLUSH);
tcsetattr (fd,TCSANOW, &newtio);
char id [16];
printf("Opening COm Port : %s\n\n",MODEMDEVICE);
fid = fopen ("data1.dat","w+");
if (fid<0)
printf ("Error \n");
while (STOP==FALSE)
{
res = read(fd,buf,16);
buf[res]=0;
strcpy(id,buf);
fprintf(fid,"ID: %\n", id);
printf("ID: %s\n", buf);
}
fclose(fid);
tcsetattr(fd,TCSANOW,&oldtio);
}

Reply With Quote
