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


C++ SerialPort::Open方法代码示例

本文整理汇总了C++中SerialPort::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ SerialPort::Open方法的具体用法?C++ SerialPort::Open怎么用?C++ SerialPort::Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SerialPort的用法示例。


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

示例1: InitSerialPort

 void InitSerialPort(const wxString& portname, int baudrate)
 {
     static char errmsg[100];
     if (portname == "NotConnected") return;
     serptr=new SerialPort();
     int errcode=serptr->Open(portname, baudrate, SerialConfig);
     if (errcode < 0)
     {
         sprintf(errmsg,"unable to open serial port, error code=%d",errcode);
         throw errmsg;
     }
 };
开发者ID:darylc,项目名称:xLights,代码行数:12,代码来源:xlights_out.cpp

示例2: main

int main(int argc, char *argv[])
{
	const char default_path[] = "/dev/ttyUSB2";
	const char *path;
	if(argc < 2)
		path = default_path;
	else
		path = argv[1];
	char buf[1024];
	SerialPort sp;
	sp.Init();
	sp.Open(path, 9600, 8, 1, 'n');
	while(1)
	{
		cout<<"Please key in data"<<endl;
		cin>>buf;
		sp.Write(buf, strlen(buf)+1);
	}
	return 0;
}
开发者ID:iElaine,项目名称:mcc_old,代码行数:20,代码来源:writesp.cpp

示例3: main


//.........这里部分代码省略.........
            case '?':
            case 'h':
            {
                Usage();
                return 1;
            }
        }
    }

    if ( optind < argc )
    {
        if (( optind + 1 ) != argc )
        {
            fprintf( stderr, "Only one download file supported\n" );
            return 1;
        }

        gDownloadFileName = argv[ optind ];
    }

    // Open the file to download

    if ( gDownloadFileName != NULL )
    {
        // If we are asked to download a file, then read the entire file
        // into memory.

        if (( gDownloadInfo = ReadFile( gDownloadFileName )) == NULL )
        {
            return 1;
        }
    }

    if ( !gSerialPort.Open( portStr, baudStr ))
    {
        return 1;
    }
    if ( gUseRtsToReset )
    {
        gSerialPort.StrobeRTS( 10 );
    }

    // Put stdin in raw mode

    setbuf( stdin, NULL );
    setbuf( stdout, NULL );

#if defined( unix )
    sigemptyset( &termSig );
    sigaddset( &termSig, SIGINT );
    sigaddset( &termSig, SIGTERM );

    pthread_sigmask( SIG_BLOCK, &termSig, NULL );

    struct termios tio_new;

    if ( tcgetattr( fileno( stdin ), &gTio_org ) < 0 )
    {
        LogError( "Unable to retrieve terminal settings\n" );
        return 1;
    }
    
    tio_new = gTio_org;
    tio_new.c_lflag &= ~( ICANON | ECHO );
    tio_new.c_cc[VMIN] = 1;
    tio_new.c_cc[VTIME] = 0;
开发者ID:JonHylands,项目名称:projects,代码行数:67,代码来源:BootHost.cpp

示例4: main

int main(int argc, char* argv[])
{

sleep(1);
    ros::init(argc, argv, "sonar");
    ros::NodeHandle n;
    ros::NodeHandle nh("~");
    // get the number of sonar sensors
    nh.getParam("sensors", no_of_sensors);

  
    if (no_of_sensors <= 0) {
        ROS_ERROR("The number of sensors must be specified");
    }
    else {

        // get the device to read from
        std::string device_name = "";
        nh.getParam("device", device_name);
        if (device_name == "") device_name = "/dev/ttyUSB0";

        // do we need to set the address?
        std::string sensor_address_str = "";        
        nh.getParam("address", sensor_address_str);
        nh.setParam("address", ""); // clear the address parameter after it has been read
        if (sensor_address_str != "") {
            char* endstr;
            sensor_address = strtol(sensor_address_str.c_str(), &endstr, 16);
            if ((sensor_address > 0xfe) || (sensor_address < 0xe0)) {
                ROS_ERROR("The sensor address must be between 0xe0 and 0xfe");
                sensor_address_str = "";
            }
            else {
                if (no_of_sensors != 1) {
                    ROS_ERROR("When setting the address %s only one sensor should be attached to the module", sensor_address_str.c_str());
                    sensor_address_str = "";
                }
                else {
                    ROS_INFO("Setting sensor address to %s", sensor_address_str.c_str());
                }
            }
        }

        // sonar ranges are stored in this array
        int range_mm[no_of_sensors];

        // create the publisher
        sonar_pub = n.advertise<usbi2c::sonar_params>("sonar", 10);
	sonar_filtered_pub = n.advertise<sensor_msgs::Range> ("/sonar_height", 2, true);

	// create filters
	cAFilter = new ContingencyAnalysisWindowMeanFilter(3, 1.0);
  	outlierFilter = new OutlierRejectionFilter(-0.25, 0.5);

        SerialPort serial;
        if (serial.Open(device_name) == 0) {
            // 19200 baud, 8 data bits, no parity, 2 stop bits
            serial.Initialise(19200, 8, 2, PARITY_NONE);

            ROS_INFO("Connected to %s", device_name.c_str());

            if (sensor_address_str != "") {
                // set the address of the sonar sensor
                SetSensorAddress(serial, (unsigned char)sensor_address, 2000);
            }

            //ros::Rate loop_rate(20);
            while ((n.ok()) && (!transmission_complete)) {
                Update(serial,10,range_mm);
                ros::spinOnce();
                //loop_rate.sleep();
            }

            ROS_INFO("Closing %s", device_name.c_str());
        }
        else {
            ROS_WARN("Can't open %s", device_name.c_str());
        }
    }

    return 0;
}
开发者ID:NIFTi-Fraunhofer,项目名称:nifti_uav,代码行数:82,代码来源:sonar.cpp


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