Exemplo n.º 1
0
// настроить порт
int port_init ( askue_port_t *Port, const char *file, const char *speed, const char *dbits, const char *sbits, const char *parity )
{
    int RS232 = rs232_open ( file );
    if ( rs232_init ( RS232, &( Port->Termios ) ) )
    {
        rs232_close ( RS232 );
        return -1;
    }
    
    rs232_set_databits ( &( Port->Termios ), dbits );
    rs232_set_stopbits ( &( Port->Termios ), sbits );
    rs232_set_parity ( &( Port->Termios ), parity );
    rs232_set_speed ( &( Port->Termios ), speed );
    
    if ( rs232_apply ( RS232, &( Port->Termios ) ) )
    {
        rs232_close ( RS232 );
        return -1;
    }
    
    Port->RS232 = RS232;
    if ( __port_open ( Port ) )
    {
        close ( Port->RS232 );
        return -1;
    }
    else
    {
        return 0;
    }
}
Exemplo n.º 2
0
// порт
cli_result_t parse4port ( void *Port, int argc, char **argv )
{
    const char *PortCfg[ 5 ];
    #define File ( PortCfg[ 0 ] )
    #define Parity ( PortCfg[ 1 ] )
    #define Speed ( PortCfg[ 2 ] )
    #define DBits ( PortCfg[ 3 ] )
    #define SBits ( PortCfg[ 4 ] )
    
    // настроить порт
    cli_arg_t JournalArgs[] = 
    {
        { "port_file", 0, CLI_OPTIONAL_ARG, CLI_REQUIRED_VAL, __parse4port_strp, &File },
        { "port_parity", 0, CLI_OPTIONAL_ARG, CLI_REQUIRED_VAL, __parse4port_strp, &Parity },
        { "port_speed", 0, CLI_OPTIONAL_ARG, CLI_REQUIRED_VAL, __parse4port_strp, &Speed },
        { "port_sbits", 0, CLI_OPTIONAL_ARG, CLI_REQUIRED_VAL, __parse4port_strp, &DBits },
        { "port_dbits", 0, CLI_OPTIONAL_ARG, CLI_REQUIRED_VAL, __parse4port_strp, &SBits },
        CLI_LAST_ARG
    };
    
    cli_result_t Result = cli_parse ( JournalArgs, argc, argv );
    if ( Result != CLI_SUCCESS )
    {
        return Result;
    }
    
    if ( rs232_init ( ( *( askue_port_t** ) Port )->RS232, &( ( *( askue_port_t** ) Port )->Termios ) ) )
    {
        return CLI_ERROR_HANDLER;
    }
    
    rs232_set_speed ( &( ( *( askue_port_t** ) Port )->Termios ), Speed );
    rs232_set_databits ( &( ( *( askue_port_t** ) Port )->Termios ), DBits );
    rs232_set_stopbits ( &( ( *( askue_port_t** ) Port )->Termios ), SBits );
    rs232_set_parity ( &( ( *( askue_port_t** ) Port )->Termios ), Parity );
    
    if ( rs232_apply ( ( *( askue_port_t** ) Port )->RS232, &( ( *( askue_port_t** ) Port )->Termios ) ) )
    {
        return CLI_ERROR_HANDLER;
    }
    
    if ( port_init ( *( askue_port_t** ) Port, File, Speed, DBits, SBits, Parity ) == -1 )
    {
        return CLI_ERROR_HANDLER;
    }

    return Result;
    
    #undef File
    #undef Parity
    #undef Speed
    #undef DBits
    #undef SBits
}
Exemplo n.º 3
0
/**
 * Initalize the RS232 port.
 *
 */
void
rs232_init(void)
{
  rs232_set_speed(RS232_115200);
}