当前位置: 首页>>代码示例>>C++>>正文


C++ serialOpen函数代码示例

本文整理汇总了C++中serialOpen函数的典型用法代码示例。如果您正苦于以下问题:C++ serialOpen函数的具体用法?C++ serialOpen怎么用?C++ serialOpen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了serialOpen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: serialOpen

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;
	  }
}
开发者ID:tyharbert,项目名称:SeniorDesign,代码行数:13,代码来源:xSerial.hpp

示例2: main

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 ;
}
开发者ID:insungHwang,项目名称:bob.io,代码行数:29,代码来源:SerialTest.cpp

示例3: main

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;
}
开发者ID:freecores,项目名称:eco32,代码行数:31,代码来源:receive.c

示例4: main

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;
        }
}
开发者ID:zorglub42,项目名称:tools,代码行数:35,代码来源:lcdprint.c

示例5: main

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;
}
开发者ID:RaghavAbboy,项目名称:smartKeyPi,代码行数:25,代码来源:serial.c

示例6: main

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 ;
}
开发者ID:SamKimbinyi,项目名称:Hotspot,代码行数:30,代码来源:ttnpub.c

示例7: futabaInit

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);
}
开发者ID:benzeng,项目名称:AutoQuad,代码行数:7,代码来源:futaba.c

示例8: main

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);
	}

}
开发者ID:hackathon-ro,项目名称:Eppe,代码行数:25,代码来源:play.c

示例9: main

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]);
	}
}
开发者ID:Peterthegreat,项目名称:Epee,代码行数:60,代码来源:main.c

示例10: initializeModule

// 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;

}
开发者ID:SlugCam,项目名称:SCnode,代码行数:27,代码来源:wificmd.c

示例11: main

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;
}
开发者ID:rajivvishwa,项目名称:RaspberryPi-Project,代码行数:28,代码来源:servo_Rpi.c

示例12: serialComms

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;
}
开发者ID:4levity,项目名称:antbike,代码行数:34,代码来源:antlights.cpp

示例13: serialOpen

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";
}
开发者ID:tmazur,项目名称:RaspberryPi-Wind-Powered-Robot-Navigation,代码行数:33,代码来源:controller.cpp

示例14: la_init_controls

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;
}
开发者ID:elelay,项目名称:LecteurAudio,代码行数:29,代码来源:serial_bridge.c

示例15: main

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;
}
开发者ID:Logout22,项目名称:Escape,代码行数:25,代码来源:send.c


注:本文中的serialOpen函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。