Skip to content

Instantly share code, notes, and snippets.

@saleph
Created February 2, 2017 21:05
Show Gist options
  • Save saleph/1c79fce4f8358b1bbf014c83796a6a50 to your computer and use it in GitHub Desktop.
Save saleph/1c79fce4f8358b1bbf014c83796a6a50 to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#define BAUDRATE B9600
#define MODEMDEVICE "/dev/ttyAMA0"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define FALSE 0
#define TRUE 1
volatile int STOP = FALSE;
main()
{
int fd, c, res;
struct termios oldtio, newtio;
char buf[255];
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY);
if (fd < 0) {
perror(MODEMDEVICE);
exit(-1);
}
tcgetattr(fd, &oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
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] = 244; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &newtio);
while (STOP == FALSE) { /* loop for input */
res = read(fd, buf, 255); /* returns after 5 chars have been input */
uint16_t lol = *(uint16_t*)buf;
printf("%d, ID: %u\n", res, lol);
//usleep(500);
}
tcsetattr(fd, TCSANOW, &oldtio);
}
@JessicaLawson
Copy link

Hello
Happy to meet you, my name is Miss Jessica Lawson, it is my pressure to meet you here  today through this site, i will like you to write to me so that i can be able to tell you more about me and the reason of my contact with you. here is my private email address, please write to me here so that i can tell you more anout me and also to send my picture  to you ( jesicalawson91@gmail.com )  thanks

Yours Miss Jessica Lawson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment