Exemplo n.º 1
2
int main(int argc, char *argv[]) {
  char *serialPort;
  unsigned char prev, curr;
  int count, errors;

  if (argc != 2) {
    printf("Usage: %s <serial port>\n", argv[0]);
    exit(1);
  }
  serialPort = argv[1];
  serialOpen(serialPort);
  count = 0;
  errors = 0;
  while (!serialRcv(&prev)) ;
  count++;
  while (count < 100000) {
    while (!serialRcv(&curr)) ;
    count++;
    if (((prev + 1) & 0xFF) != curr) {
      errors++;
    }
    prev = curr;
  }
  if (sfd != 0) {
    serialClose();
    sfd = 0;
  }
  printf("count = %d (ok = %d, errors = %d)\n",
         count, count - errors, errors);
  return 0;
}
Exemplo n.º 2
1
int   Serial::Open (){
        if ((this->fd = serialOpen (this->device, this->baud)) < 0)
          {
//		std::cout << "Unable to open serial device\n";
          	return 0 ;
          }
	else
	  {
		//std::cout << "Serial port opened\n";
		this->fd = serialOpen(this->device, this->baud);
		return this->fd;
	  }
}
Exemplo n.º 3
1
int main ()
{
  int fd;
  unsigned char data=3;


  if ((fd = serialOpen ("/dev/ttyAMA0", 9600))<0)
  {
	fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno));
	return 1;
  }


  printf ("\nRaspberry Pi UART Test \n");
  
  while(1)
  {

	  serialPutchar(fd,data);
//	  printf ("\nPC > RPi = %c", (char)data);
  
//	  serialPutchar(fd, data);
//	  serialPuts(fd, "\n");
	  fflush(stdout);
  }
  

  return 0 ;
}
Exemplo n.º 4
0
int main(int argc, char *argv[]){
        if (argc < 3 ){
                printf("Usage:\nlcdprint line col [text]\n");
                return 1;
        }else{
                int col=atoi(argv[2]);
                if (col<0 || col> 15){
                        printf("col must be between 0 and 15\n");
                        return 2;
                }
                int line=atoi(argv[1]);
                if (line<0 || line> 1){
                        printf("col must be between 0 and 1\n");
                        return 3;
                }
                lcd=serialOpen(SERIAL, BAUD_RATE);
                setLCDCursor(line*16+col);
				if (argc>3){
					int i;
					for (i=3;i<argc;i++){
							serialPuts(lcd, argv[i]);
							if (i<argc-1){
									serialPuts(lcd, " ");
							}
					}
				}else{
					char c;
					while ((c=getchar()) !=255){
						serialPutchar(lcd, c); 
					}
				}
                serialClose(lcd);
                return 0;
        }
}
Exemplo n.º 5
0
int main ()
{
	int fd,i=0;
	fd= serialOpen("/dev/ttyAMA0",115200);
	if(fd < 0)  { printf("Opening serial failed.\n"); return 0; }

	while(i<10)
	{
		delay(500);
		serialPutchar(fd,i);
		i++;

		//printf("serialDataAvail: %d\n", serialDataAvail(fd));

		if(serialDataAvail(fd) >= 1)
		{
       			printf ("->%d\n", serialGetchar(fd));
       			fflush (stdout);
		}
	}

	printf("Serial port closing.\n");
	serialClose(fd);
	return 0;
}
Exemplo n.º 6
0
int main (int argc, char **argv)
{
	char *ttnMsg;
	int usbPort=0;    //File descriptor for the USB port when we open it

	// Set up wifiCount if the parameter was passed
	if (argc==2) {
		ttnMsg=argv[1];
	} else {
		printf("Usage hotspotuno ttnMsg\n");
		return 1;
	}
	
	usbPort=serialOpen("/dev/ttyACM0",9600);
	delay(1000);
	printf("Port opened, number %d \n",usbPort);
	if(usbPort) {
		delay(1000);
		printf("Pause...\n");
		serialPuts(usbPort, ttnMsg);
		printf("Message posted \n");
		delay(1000);
		serialClose(usbPort);
		printf("Port closed \n");
	}

	system(ttnMsg);
	
	return 0 ;
}
Exemplo n.º 7
0
void futabaInit(void) {
    memset((void *)&futabaData, 0, sizeof(futabaData));

    radioData.serialPort = serialOpen(FUTABA_UART, FUTABA_BAUD, USART_HardwareFlowControl_None, FUTABA_RXBUF_SIZE, 0);
    serialChangeParity(radioData.serialPort, USART_Parity_Even);
    serialChangeStopBits(radioData.serialPort, USART_StopBits_2);
}
Exemplo n.º 8
0
int main(int argc, char **argv) {

	int com;
	char buff[1024];
	FILE *f;

	com=serialOpen("/dev/ttyUSB0");
	f=fdopen(com, "r");
	fgets(buff, 1024, f); //First line usually only comes in half; kill it.
        printf("Serialul pare ok..\n");



	if(argc<2) {
		printf("Usage: play inputfile");
		return 1;
	}


	while(1){
		float class = classifyInput(f, argv[2]);
		printf("Am detectat %i ", class);
	}

}
Exemplo n.º 9
0
int main(int argc, char **argv) {
	int com;
	FILE *f;
	char buff[1024];
	int samps;
	int n;
	com=serialOpen("/dev/ttyUSB0");
	f=fdopen(com, "r");
	fgets(buff, 1024, f); //First line usually only comes in half; kill it.
	printf("Serialul pare ok..\n");

	if (argc<3) {
		printf("Usage: %s [-printavg samps|-gentrain label [no_samples]|-autotrain classes filename [no_samples]|-classify svm-model-prefix]\n", argv[0]);
		return 1;
	}
	if (strcmp(argv[1], "-printavg")==0) {
		printAvgValsOver(f, atoi(argv[2]));
	} else if (strcmp(argv[1], "-gentrain")==0) {
		if(argc==4) {
			printf("Am 3 parametrii\n");
			genLibSvmTrainSet(f, atoi(argv[2]), argv[3],DEFAULT_SAMPLES);
		}else if(argc==5){
			printf("Am 4 parametrii\n");
			genLibSvmTrainSet(f, atoi(argv[2]), argv[3],atoi(argv[4]));
		}else{
			printf("Error");
		}
	} else if (strcmp(argv[1], "-autotrain")==0) {
		int i = 0;
		for(i = 0; i< atoi(argv[2]); i++) {

			printf("Ne antrenam pt comanda %i.\n",i);

			if(argc==3){ //assume default no_sample
				genLibSvmTrainSet(f, i, argv[3],DEFAULT_SAMPLES);
			} else {
				genLibSvmTrainSet(f, i, argv[3],atoi(argv[4]));
			}

			if(i< atoi(argv[2]) - 1) {
				printf("Urmatoarea clasa in 2secunde..");
				sleep(3);
			}
		}

		printf("Dau svm-easy\n");
		printf(argv[3]);
		printf("\n");
		char cmd[90];
		sprintf(cmd, "svm-easy %s", argv[3]);
		printf("Comanda e %s",cmd);
		system(cmd);

		//run the new classification
		classifyInput(f, argv[3]);

	} else if (strcmp(argv[1], "-classify")==0) {
			classifyInput(f, argv[2]);
	}
}
Exemplo n.º 10
0
// Initialize the WiFi Module serial port and return the file descriptor for the
// serial port.
int initializeModule() {
    int fd;

    //open serial port
    if ((fd = serialOpen ("/dev/ttyAMA0", 115200)) < 0)
    {
        //fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
        syslog (LOG_ERR, "Unable to open serial device: %s\n", strerror (errno)) ;
        return 1 ;
    }

    //The wiringPi's kernel setup procedures
    if (wiringPiSetup () == -1)
    {
        //fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
        syslog (LOG_ERR, "Unable to start wiringPi: %s\n", strerror (errno)) ;
        return 1 ;
    }

    fflush (stdout) ;
    //serialFlush(fd);

    return fd;

}
Exemplo n.º 11
0
int main(void)
{
	int fd;
	unsigned char pos = 0;
	unsigned char buf[4] = {0};
	unsigned char *buf1 = "hello\n";

	fd = serialOpen("/dev/ttyAMA0", 9600);	

	unsigned char tmp;

	while(1){
	//	scanf("%d", &pos);
	//	snprintf(buf, 4, "%d", pos);
		//printf("*** %s\n",buf);
		serialPrintf(fd, "120\r\n");
		sleep(1);
		serialPrintf(fd, "20\r\n");
		sleep(1);
		serialPrintf(fd, "150\r\n");
		sleep(1);
		delay(2500);
	}

	serialClose(fd);

	return 0;
}
Exemplo n.º 12
0
void* serialComms(void* arg) {
  fdSerial = serialOpen("/dev/ttyAMA0",115200);
  if(fdSerial == -1) {
    std::cout <<"error opening serial port"<<std::endl;
  } else {
    int lastCh,bufLen;
    unsigned char buf[SERIALBUFLEN];
    //struct termios options;
    //    tcgetattr(fdSerial, &options);
    //options.c_cc[VTIME]=100;// 5 x 0.1 sec = 0.5 sec timeout
    //tcsetattr(fdSerial, TCSANOW, &options);

    while(!shutdown) {
      bufLen=0;
      do {
	lastCh=serialGetchar(fdSerial);
	if(lastCh>0) {
	  buf[bufLen]=((unsigned char)lastCh) % 256;
	  bufLen++;
	}
      } while(lastCh>0 && bufLen<SERIALBUFLEN && !shutdown);
      for(int i=0;i<bufLen;i++) {
	// process buffer
	std::cout << buf[i]<<std::flush;
      }
      if(lastCh<=0) {
	// timeout could indicate problem with mcu
	//std::cout<<"|timeout|"<<std::flush;
      }
    }
    serialClose(fdSerial);
  }
  return NULL;
}
void Controller::runUart() {
	int fd = serialOpen(UART_DEVICE, 9600);
	int bSize = 0; // ilość znaków w buforze
	while(!endThreads) {
		bSize = serialDataAvail(fd);
		if(bSize==8) { // dwa inty czekają na odczyt
			union IntOrByte {
				char b[4];
				int i;
			} u;
			
			// odczyt kierunku wiatru
			for (int i =0; i < 4; i++) { //odczytaj 4 bajty
				u.b[i] = serialGetchar(fd);
			}
			this->windDirection = u.i;

			// odczyt prędkości wiatru
			u.i = 0; // resetujemy union
			for (int i =0; i < 4; i++) { //odczytaj 4 bajty
				u.b[i] = serialGetchar(fd);
			}
			this->windSpeed = u.i;
		} else if(bSize>8) { // zbyt dużo informacji w buforze
			serialFlush(fd);
		}

		chrono::milliseconds sleepDuration(500);
		this_thread::sleep_for(sleepDuration);
	}
	serialClose(fd);
	dlog << "koniec threadWorker";
}
Exemplo n.º 14
0
int la_init_controls(int** fdControls, int* fdControlCount)
{
	int ret;

	ret = wiringPiSetup();
	if(ret) return ret;

	if ((fdsArduino[0] = serialOpen ("/dev/ttyAMA0", 9600)) < 0)
    {
    	fprintf (stderr, "E: Unable to open serial device: %s\n", strerror (errno)) ;
    	return -1;
    }

    serialFlush(fdsArduino[0]);

    fArduino = fdopen(fdsArduino[0], "r");

    buf_len = 128;
    buf = malloc(buf_len);
    if(!buf)
    {
    	fprintf (stderr, "E: Unable to allocate buffer: %s\n", strerror (errno)) ;
    	return -1;
    }

	*fdControls = fdsArduino;
	*fdControlCount = 1;
	return 0;
}
Exemplo n.º 15
0
int main(int argc, char *argv[]) {
  unsigned char curr;
  int count;

  if (argc != 1) {
    printf("Usage: %s\n", argv[0]);
    exit(1);
  }
  serialOpen();
  curr = 0;
  count = 0;
  while (count < 100000) {
    while (!serialSnd(curr)) ;
    curr = (curr + 1) & 0xFF;
    count++;
  }
  printf("count = %d\n", count);
  while (!serialRcv(&curr)) ;
  printf("answer = %c\n", curr);
  if (sfd != 0) {
    serialClose();
    sfd = 0;
  }
  return 0;
}
Exemplo n.º 16
0
/********************************************************************
* init:																*
* initializes the program											*
********************************************************************/
void init()
{
	/* Initialize serial port for xbee comm */
	wiringPiSetup();
	if((serialFd = serialOpen("/dev/ttyAMA0", BAUD_RATE)) < 0)
		error("error opening serial port");

	//initialize the mutex
	pthread_mutex_init(&flagMutex, NULL);

	// Set up sig handler for USR1 signal (restart recv thread)
	if (signal(SIGUSR1, sig_handler) == SIG_ERR)
        error("error setting up the sig_handler\n");

    update.desiredFlowRate = MAX_FLOW;
    update.frequency = MAX_FREQ;
    update.VFDState = ON_VFD;
    // set all flags for first run
    LOCK(&flagMutex);
    update.updateFlag = UPDATE_FREQ_STATE | UPDATE_FLOW;
    UNLOCK(&flagMutex);

	// Initialize memory and flush remaining serial data
	serialFlush(serialFd);
    memset((void*)&data, 0, sizeof(data));
	memset((void*)&messageFromServer, 0, sizeof(messageFromServer));
	memset((void*)&messageFromVfd, 0, sizeof(messageFromVfd));

	// Create thread to monitor the socket and receive messages
	if( pthread_create(&thread_id, NULL, receive_handler, (void*)&thread_id) < 0)
		error("could not create recv thread");
}
Exemplo n.º 17
0
void gpsTask(void *unused)
{
    gpsData.serial = serialOpen(USART1, 9600);
    gpsData.mode = MODE_NMEA;   // NMEA

    while (1) {
        CoTickDelay(25);

        while (uartAvailable(gpsData.serial)) {
            switch (gpsData.mode) {
            case MODE_NMEA:    // NMEA
                gpsData.validFrames += gpsNewFrameNMEA(uartRead(gpsData.serial));
                break;

            case MODE_UBX:     // UBX
                gpsData.validFrames += gpsNewFrameUBLOX(uartRead(gpsData.serial));
                break;

            case MODE_MTK:     // MTK
                break;

            case MODE_PASSTHROUGH:     // GPS -> UART bridge
                // TODO
                // usbSerialWrite(uartRead(gpsData.serial));
                break;
            }
        }
    }
}
Exemplo n.º 18
0
void futabaInit(radioInstance_t *r, USART_TypeDef *uart) {
   memset((void *)&futabaData, 0, sizeof(futabaData));

    r->serialPort = serialOpen(uart, FUTABA_BAUD, USART_HardwareFlowControl_None, FUTABA_RXBUF_SIZE, 0);
    serialChangeParity(r->serialPort, USART_Parity_Even);
    serialChangeStopBits(r->serialPort, USART_StopBits_2);
}
Exemplo n.º 19
0
int  main() {
	int c, res ,seq = 0 ,len;
	unsigned char result, serialRead;
	struct sockaddr_in receiver_addr;
	int sock_fd;

	/* Prepare Serial Port */
	if(serialOpen() != 0) return -1;
	signal(SIGINT, interrupt); //set ctrl-c handler

	/* Prepare Socket */
	sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	receiver_addr.sin_family = AF_INET;
	if( inet_aton( ADDR,  &receiver_addr.sin_addr )== 0) {
		printf("Crap!, Init failed\n");
		close(sock_fd);
		return;
	}
	receiver_addr.sin_port = htons( PORT );

	while (isrunning) {   /*endless loop until ctrl-c is typed */
		serialRead = serialReadChar();
		printf("value is %c\n", serialRead);
		makeATCommand(at_command,seq,serialRead);
		len = strlen(at_command);
		sendto(sock_fd, at_command, len, 0,(struct sockaddr*)&receiver_addr,sizeof(receiver_addr));
		seq ++;
		
	}
 	
 	close(sock_fd);
	serialClose();

	return 0;
}
int main ()
{
    printf("Program started.\n");

    int ser_handle; // the serial connection (file descriptor)

    if ((ser_handle = serialOpen("/dev/ttyAMA0", BAUD_RATE)) < 0)
    {
        fprintf(stderr, "Unable to open serial device: %s\n", strerror(errno));
        return 1 ;
    }
    else
        printf("Serial open\n");

    int counter = 0;

    int avail_bytes;
    for(;;) {
        if(avail_bytes = serialDataAvail(ser_handle))
        {
            serialPutchar(ser_handle,serialGetchar(ser_handle));
            counter = counter + 1;
            if(counter%100 == 0) {
                printf("Byte %i has been passed on\n", counter);
            }
        }
    }
}
Exemplo n.º 21
0
int u16RPISerialSetups(char* port, int baudrate)
{
	int fd; 

	fd = serialOpen (port, baudrate);

	return fd;
} 
Exemplo n.º 22
0
Transmitter::Transmitter()
{
	controller = new Controller();
	
	std::cout << "attempting to open /dev/xbee" << std::endl;
	handle = serialOpen("/dev/ttyUSB0", BAUD_RATE_XBEE);
	std::cout << "sucessfully opened /dev/xbee" << std::endl;
}
Exemplo n.º 23
0
/*
 * Class:     com_pi4j_wiringpi_Serial
 * Method:    serialOpen
 * Signature: (Ljava/lang/String;I)I
 */
JNIEXPORT jint JNICALL Java_com_pi4j_wiringpi_Serial_serialOpen
  (JNIEnv *env, jobject obj, jstring device, jint baud)
{
	char devchararr[256];
	int len = (*env)->GetStringLength(env, device);
	(*env)->GetStringUTFRegion(env, device, 0, len, devchararr);
	return serialOpen(devchararr, baud);
}
Exemplo n.º 24
0
bool serialLed::connect(char com, int baud)
{
    int isSerialOpen = serialOpen( com, baud );

    if ( isSerialOpen >= 0 )
        return true;
    else
        return false;
}
Exemplo n.º 25
0
Arquivo: CV7.cpp Projeto: pophaax/CV7
void CV7::loadConfig(std::string portName, int baudRate)
{	
	setPortName(portName);
	
	m_fd = serialOpen(portName.c_str(), baudRate);

	if(m_fd < 0) {
		throw "CV7::openPort: Unable to connect";
	}
}
Exemplo n.º 26
0
void WpiEngine::initSerial()
{
    if (wiringPiSetup () == -1)                         printf ("Unable to start wiringPi.\n") ;
    pinMode (1, OUTPUT) ;

    if ((fd = serialOpen ("/dev/ttyAMA0", 9600)) < 0)   printf ("Unable to open serial device.\n") ;

    time2016.tm_hour = 0;   time2016.tm_min = 0; time2016.tm_sec = 0;
    time2016.tm_year = 116; time2016.tm_mon = 0; time2016.tm_mday = 1;
}
Exemplo n.º 27
0
int serial_openadapter(char *serial_bus)
{
	int id = getSerialId();
	struct serial_bus *sb = serial_buses[id];
	sb->bus = serial_bus;
	sb->speed = SERIAL_DEFAULT_SPEED;
	int fd = serialOpen(sb->bus, sb->speed);
	sb->fd = fd;
	return id;

}
Exemplo n.º 28
0
uint8_t serial_readbyte(int serial_id)
{
	struct serial_bus *sb = serial_buses[serial_id];
	if(!sb)
		return -1;
	if(sb->fd < 0)
	{
		sb->fd = serialOpen(sb->bus, sb->speed);
	}
	return serialGetchar (sb->fd);
}
Exemplo n.º 29
0
void int_serial(void)
{
  if ((fd=serialOpen("/dev/ttyAMA0",115200))<0)
   {
        printf("unable to open serial device\n");
   }
  if (wiringPiSetup()==-1)
  {
  	printf("unable to start wiringPi\n");
  }
}
Exemplo n.º 30
0
int main (void)
{
int handle = serialOpen ("/dev/ttyAMA0", 19200); //115200) ;
serialParity(handle,1);
  while(1) {
    serialPutchar(handle,0b10100000);
	usleep (800);
  }

  return 0 ;
}