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


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

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


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

示例1: main

int main()
{
	SerialPort sp;
	cout << sp.Connect("COM3") << endl;
	cout << sp.Setup() << endl;

	// Create a message
	RobotCommand msg;
	UnitStatus stat;
	SetStatus(stat, 0, 0, 0, 1, 1);

	// Write it to device

	while (1)
	{
		char c = getch();
		switch (c)
		{
		case 'w':
			SetMessage(msg, CMD_FORWARD, 50);	// Forward with 50/255 speed
			break;
		case 'a':
			SetMessage(msg, CMD_LEFT, 10);		// Left with 10/255 of max
			break;
		case 's':
			SetMessage(msg, CMD_BACKWARD, 20);	// Backward with 20/255
			break;
		case 'd':
			SetMessage(msg, CMD_RIGHT, 5);
			break;
		case 'q':
			SetMessage(msg, CMD_STOP, 0);		// Stop with no braking
		case 'e':
			SetMessage(msg, CMD_STOP, 255);	// Stop with full braking
			break;
		default:
			cout << "## Command not recognized ##" << endl << endl;
			continue;
		}
		cout << "Sending message: " << endl << "------------------------" << endl << msg << endl << endl;
		sp.WriteMessage(msg);

		cout << "Fetching robot status:" << endl << "------------------------" << endl;
		SetMessage(msg, CMD_GET_CURRENT_STATE);
		sp.WriteMessage(msg);

		int res = sp.ReadMessage(stat);
		if (res)
			cout << "Failed to read message: " << res << endl;
		else
			cout << stat << endl;
	}	

	sp.Close();
	cout << endl << "End" << endl;
	return 0;
}
开发者ID:hallonterror,项目名称:Blue-Loris,代码行数:57,代码来源:Main.cpp

示例2: ControlC

void ControlC( int sigNum )
{
    fprintf( stderr, "Shutting down...\n" );

    // Closing the serial port will cause the ReadSerialThread to unblock and exit

    gSerialPort.Close();

    if ( tcsetattr( fileno( stdin ), TCSANOW, &gTio_org ) == -1 )
    {
        LogError( "Unable to restore terminal settings\n" );
    }

    if ( gLogFs2 != NULL )
    {
        fclose( gLogFs2 );
    }

    // Now do whatever the default handling for the signal would be

    signal( sigNum, SIG_DFL );
    raise( sigNum );

} // ControlC
开发者ID:JonHylands,项目名称:projects,代码行数:24,代码来源:BootHost.cpp

示例3: main


//.........这里部分代码省略.........
        return 1;
    }
#endif

    const char *bootLoaderType = "*** Unknown ***";

    if ( gDongle )
    {
        bootLoaderType = "Serial Dongle";
    }
    else
    if ( gMegaLoad )
    {
        bootLoaderType = "MegaLoad v2.3";
    }
    else
    if ( gStk500 )
    {
        bootLoaderType = "STK500";
    }

    gLogFs2 = fopen( "BootHost.log", "wb" );

    Log( "BootHost - BootLoader: %s\n", bootLoaderType );

    // Kick off the serial port reader thread.

    rc = pthread_create( &readSerialThreadId, NULL, ReadSerialThread, &gSerialPort );
    if ( rc != 0 )
    {
        fprintf( stderr, "Error creating ReadSerialThread: %d\n", rc );
        return 1;
    }

    // Kick off the stdin reader thread.

    rc = pthread_create( &readStdinThreadId, NULL, ReadStdinThread, NULL );
    if ( rc != 0 )
    {
        fprintf( stderr, "Error creating ReadSerialThread: %d\n", rc );
        return 1;
    }

#if defined( unix )

    // Wait for a termmination signal

    if (( rc = sigwait( &termSig, &sig )) != 0 )
    {
        fprintf( stderr, "sigwait failed\n" );
    }
    else
    {
        fprintf( stderr, "Exiting...\n" );
    }

    pthread_cancel( readSerialThreadId );
    pthread_cancel( readStdinThreadId );

    // Restore stdin back to the way it was when we started

    if ( tcsetattr( fileno( stdin ), TCSANOW, &gTio_org ) == -1 )
    {
        LogError( "Unable to restore terminal settings\n" );
    }
#endif

#if defined( __CYGWIN__ )

    // Under Windows closing the serial port and stdin will cause the reads
    // to unblock. Under linux, this isn't required, but it doesn't hurt 
    // either.

    gSerialPort.Close();
    fclose( stdin );
#endif

    // Unblock the termination signals so the user can kill us if we hang up
    // waiting for the reader threads to exit.

#if defined( unix )
    pthread_sigmask( SIG_UNBLOCK, &termSig, NULL );
#endif

    pthread_join( readSerialThreadId, NULL );
    pthread_join( readStdinThreadId, NULL );

#if !defined( __CYGWIN__ )
    gSerialPort.Close();
    fclose( stdin );
#endif

    if ( gVerbose )
    {
        printf( "Done\n" );
    }

    return 0;

} // main
开发者ID:JonHylands,项目名称:projects,代码行数:101,代码来源:BootHost.cpp


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