嵌入式Linux的串口通讯C++程序设计(3)

class CSerial m_Serial;
        int main( int argc,char* argv[] )
        {
                int i1;
                int portno, baudRate;
                char cmdline[256];

printf( 'Step2_SerialTest V1.0\n' );
                // 解析命令行参数:串口号 波特率
                if( argc > 1 ) strcpy( cmdline, argv[1] );
                else portno = 1;
                if( argc > 2 )
                {
                        strcat( cmdline, ' ' );
                        strcat( cmdline, argv[2] );
                        scanf( cmdline, '%d %d', &portno, &baudRate );
                }
                else
                {
                        baudRate = 115200;
                }
                printf( 'port:%d baudrate:%d\n', portno, baudRate);
                //打开串口相应地启动了串口数据接收线程
                i1 = m_Serial.OpenPort( portno, baudRate, '8', '1', 'N');
                if( i1<0 )
                {
                        printf( 'serial open fail\n');
                        return -1;
                }
                //进入主循环,这里每隔1s输出一个提示信息
                for( i1=0; i1<10000;i1++)
                {
                        sleep(1);
                        printf( '%d \n', i1+1);
                }
                m_Serial.ClosePort( );
                return 0;
        }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwssxd.html