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


C++ Serial::waitInput方法代码示例

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


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

示例1: main

int main(int argc, char* argv[])
{
	printf("[i] Start... \n");

	Serial serial;
#if defined(WIN32)
	serial.open(SERIAL_PORT_NAME, SERIAL_PORT_RATE, true);
#elif defined(LINUX)
	serial.open(SERIAL_PORT_NAME, SERIAL_PORT_RATE);
#endif

	if(!serial.connected())
	{
		printf("[!] Cant open port!\n");
		return -1;
	}

	char c = 'y';
	int res = 12;

	char buf[BUF_SIZE1];
	memset(buf, 0, BUF_SIZE1);

	while(true)
	{

		serial.write( &c, 1 );
#if 0
		if(res = serial.available()){
			if( res = serial.Read(buf, res) ){
				printf("%d %s\n", res, buf);
			}
		}
#else
		if(serial.waitInput(1000)==0)
			printf("[i] timeout!\n");
		else
		{
			if(res = serial.available())
			{
				res = serial.read(buf, res);
				printf("%d %s\n", res, buf);
			}
		}
#endif
	}
	serial.close();

	printf("[i] End.\n");
	return 0;
}
开发者ID:Aadi2110,项目名称:openrobovision,代码行数:51,代码来源:test_serial.cpp

示例2: sizeof

TEST(Serial, WriteCOM) {

	Serial serial;

	serial.open("COM7", 9600);

	if(!serial.connected()){
		FAIL()<<"cant open serial port!";
	}

	char buf[1024];
	int res = 0;
	while(1){

		char wbuf[] = {0xff, 0xff, 0x00, 0x00, 0x00, 0x00 ,0xff};

		serial.write(wbuf, sizeof(wbuf));

		if( serial.waitInput(1000) > 0){
			if( (res = serial.available()) > 0 ){
				if( res = serial.read(buf, res) ){
					printf("[i] read data(%d): \n", res);
					for(int i=0; i<res; i++){
						printf("%02X ", (unsigned char)buf[i]);
						if(i>0 && (i+1)%16 == 0) {
							printf("\t");
							for(int j=i-15; j<=i; j++){
								printf("%c", buf[j]);
							}
							printf("\n");
						}
					}
					printf("\n");
					res = 0;
				}
			}
		}
		Sleep(1000);
	}
}
开发者ID:Aadi2110,项目名称:openrobovision,代码行数:40,代码来源:serial_unittest.cpp

示例3: process_serial

void process_serial(Serial &serial, TBuff<uint8_t> &buff, orcp2::packet &pkt)
{
    int res = 0;

    if(!buff.data || !pkt.message.data) {
        ROS_ERROR("[!] Error: no memory!\n");
        return ;
    }

    ros::Time current_time;

    ros_4wd_driver::drive_telemetry_4wd drive;
    ros_4wd_driver::sensors_telemetry_4wd sensors;
    ros_4wd_driver::imu_raw_data imu;

    if( res = serial.waitInput(500) ) {
        //printf("[i] waitInput: %d\n", res);
        if( (res = serial.available()) > 0 ) {
            //printf("[i] available: %d\n", res);
            //res = res > (buff.real_size-buff.size) ? (buff.real_size-buff.size) : res ;
            if( (res = serial.read(buff.data+buff.size, buff.real_size-buff.size)) > 0 ) {
                buff.size += res;

                // get packet from data
                while ( (res = orcp2::get_packet(buff.data, buff.size, &pkt)) > 0) {
                    //     ROS_INFO("[i] res: %02d message: %04X size: %04d CRC: %02X buff.size: %02d\n",
                    //              res, pkt.message_type, pkt.message_size, pkt.checksum, buff.size);

                    uint8_t crc = pkt.calc_checksum();
                    if(crc == pkt.checksum) {
                        //         ROS_INFO("[i] Good message CRC: %02X\n", pkt.checksum);

                        current_time = ros::Time::now();

                        switch(pkt.message_type) {
                        case ORCP2_SEND_STRING:
                            pkt.message.data[pkt.message.size]=0;
                            ROS_INFO("[i] String: %s\n", pkt.message.data);
                            //printf("[i] counter: %d\n", counter);
#if 0
                            if(++counter > 50) {
                                //printf("[i] digitalWrite: %d\n", val);
                                val = !val;
                                orcp.digitalWrite(13, val);
                                counter = 0;
                            }
#endif
                            break;
                        case ORCP2_MESSAGE_IMU_RAW_DATA:
                            deserialize_imu3_data(pkt.message.data, pkt.message.size, &raw_imu_data);
                            ROS_INFO( "[i] IMU: acc: [%d %d %d] mag: [%d %d %d] gyro: [%d %d %d]\n",
                                      raw_imu_data.Accelerometer[0], raw_imu_data.Accelerometer[1], raw_imu_data.Accelerometer[2],
                                      raw_imu_data.Magnetometer[0], raw_imu_data.Magnetometer[1], raw_imu_data.Magnetometer[2],
                                      raw_imu_data.Gyro[0], raw_imu_data.Gyro[1], raw_imu_data.Gyro[2] );

                            imu.header.stamp = current_time;
                            imu.accelerometer1 = raw_imu_data.Accelerometer[0];
                            imu.accelerometer2 = raw_imu_data.Accelerometer[1];
                            imu.accelerometer3 = raw_imu_data.Accelerometer[2];
                            imu.magnetometer1 = raw_imu_data.Magnetometer[0];
                            imu.magnetometer2 = raw_imu_data.Magnetometer[1];
                            imu.magnetometer3 = raw_imu_data.Magnetometer[2];
                            imu.gyro1 = raw_imu_data.Gyro[0];
                            imu.gyro2 = raw_imu_data.Gyro[1];
                            imu.gyro3 = raw_imu_data.Gyro[2];

                            imu_raw_data_pub.publish(imu);
                            break;
                        case ORCP2_MESSAGE_ROBOT_4WD_DRIVE_TELEMETRY:
                            deserialize_robot_4wd_drive_part(pkt.message.data, pkt.message.size, &robot_data);
                            ROS_INFO( "[i] Drive telemetry: bmp: %d enc: [%d %d %d %d] PWM: [%d %d %d %d]\n",
                                      robot_data.Bamper,
                                      robot_data.Encoder[0], robot_data.Encoder[1], robot_data.Encoder[2], robot_data.Encoder[3],
                                      robot_data.PWM[0], robot_data.PWM[1], robot_data.PWM[2], robot_data.PWM[3] );

                            drive.header.stamp = current_time;
                            drive.bamper = robot_data.Bamper;
                            drive.encoder1 = robot_data.Encoder[0];
                            drive.encoder2 = robot_data.Encoder[1];
                            drive.encoder3 = robot_data.Encoder[2];
                            drive.encoder4 = robot_data.Encoder[3];
                            drive.pwm1 = robot_data.PWM[0];
                            drive.pwm2 = robot_data.PWM[1];
                            drive.pwm3 = robot_data.PWM[2];
                            drive.pwm4 = robot_data.PWM[3];

                            drive_telemetry_pub.publish(drive);
                            calc_odometry(drive);
                            break;
                        case ORCP2_MESSAGE_ROBOT_4WD_SENSORS_TELEMETRY:
                            deserialize_robot_4wd_sensors_part(pkt.message.data, pkt.message.size, &robot_data);
                            ROS_INFO( "[i] Sensors telemetry: US: %d IR: [%d %d %d %d] V: %d\n",
                                      robot_data.US[0],
                                      robot_data.IR[0], robot_data.IR[1], robot_data.IR[2], robot_data.IR[3],
                                      robot_data.Voltage );

                            sensors.header.stamp = current_time;
                            sensors.us = robot_data.US[0];
                            sensors.ir1 = robot_data.IR[0];
                            sensors.ir2 = robot_data.IR[1];
//.........这里部分代码省略.........
开发者ID:IlyaPetrovM,项目名称:robot_4wd,代码行数:101,代码来源:robot_4wd_node.cpp


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