#include <sys/fcntl.h>
#include <sys/file.h>
#include <unistd.h>
#include <stdio.h>
#include <termio.h>
#include <termios.h>
#include <errno.h>

int main(){
  
  //fd is the file descriptor.  It is not a pointer, but rather a number
  //that unix assigns
  int fd, written, bytes, status, returned;
  char ispeed,ospeed;
  int phex=0x68;
  int shex=0x73;
  int thex=0x74;
  //char shex=0x73;
  int *pphex,*pshex,*pthex; 
  //char *amessage;
  char rmessage[60];
  struct termios options;
  pphex=&phex;
  pshex=&shex;
  pthex=&thex;
 
  //*amessage='s';
  //pshex=&shex;
 // pphex=&phex;

  //Open the Serial Port to be used
  fd=open("/dev/ttyUSB0",O_RDWR | O_NONBLOCK);
  //tcflush(fd,TCIOFLUSH);
  //ioctl(fd,TCFLSH);  
  fcntl(fd,F_SETFL,0);
  perror("");
  printf("%d\n",errno);
  //Do some setting business
  //Force a zero delay time in reading the serial port
  //fcntl(fd,F_SETFL,FNDELAY);
  //Get the current options for the port

  printf("Writing:\n");
  written=write(fd,pphex,1);
  //ioctl(fd,FIONREAD,&bytes);
  //sleep(.5);
  perror("");  
  returned=read(fd,rmessage,60);
  //ioctl(fd,TIOCMGET, &status);
  perror("");
  perror("read()");
 
  printf("%d\n",errno);




  printf("handle= %ld\n",fd);
  printf("number of bytes written=%ld\n",written);
  printf("value returned=%ld\n",returned);
  printf("value returned=%ld\n",rmessage[0]);
  printf("number of bytes returned=%ld\n",bytes);
  close(fd);
  return 0;
}

