I'm writing some code that should communicate with an Arduino through the serial line. But I'm having some troube getting my preliminary stuff working. This is what I have so far, if someone could tell me if there's something wrong with this id really appreciate it.
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h> /* close */
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
int main()
{
printf("LED read write test...v1.2\n");
int flashNum;
int serial;
char sendLine[1], recvLine[256] = {0};
serial = open("/dev/tts/1", O_RDWR | O_NOCTTY);
if (serial == -1)
printf("ERROR opening serial file\n");
else
printf("seral opened\n");
printf("how many times would you like the led to blink (single digit)?\n");
scanf("%c", &flashNum);
sendLine[0] = (char)flashNum;
//just to have it keep trying to write until it works
while(write(serial, sendLine, 1) <= 0)
{
printf("writing failed....\n");
}
printf("writing sucess\n");
//same as write but with read
while(read(serial, recvLine, 1) < 0)
{
printf("trying to read...\n");
}
if (recvLine[0] == '1')
printf("finished flashing\nclosing....\n");
else
printf("got unexpected data: %d", recvLine[0]);
close(serial);
return 0;
}