本文整理汇总了C++中serialOpen函数的典型用法代码示例。如果您正苦于以下问题:C++ serialOpen函数的具体用法?C++ serialOpen怎么用?C++ serialOpen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serialOpen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: init
/********************************************************************
* 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");
}
开发者ID:kristinjm,项目名称:VICEproject,代码行数:36,代码来源:vfdController.c
示例17: gpsTask
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;
}
}
}
}
开发者ID:CamBl98,项目名称:afrodevices,代码行数:29,代码来源:gps.c
示例18: futabaInit
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);
}
开发者ID:jiezhi320,项目名称:aq_flight_control,代码行数:7,代码来源:futaba.c
示例19: main
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;
}
开发者ID:kenkenrep1ew,项目名称:auto_drone,代码行数:35,代码来源:auto_drone1.c
示例20: main
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);
}
}
}
}
开发者ID:TobiasLundby,项目名称:Autonomous-precision-landing_BScF16_MHE-TL,代码行数:28,代码来源:simple_echo.c
注:本文中的serialOpen函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论