Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2001
    Messaggi
    97
    Ciao
    qualcuna saprebbe darmi una dritta su come poter leggere e scrivere dalle porte seriali tramite C ?
    L' ambiente dove dovrei effettuare tali letture e'Win'98, Win2000 o WinNT4
    Se riusciste a darmi qualche dritta su funzioni che gestiscono le porte seriale o quanto meno se conoscete dei libri che trattato tale argomento, ve ne sarei infinitamente grato....

    La mia domanda e' troppo complessa ?
    Per me si, ma sono sicuro che tra voi si nasconde qualche genio....

  2. #2
    Fare qualcosa di semplice non è difficile. Se invece devi andare sul professionale, allora è diverso.

    Una porta seriale si apre e si legge, in C, come un file qualunque. Il nome è Com1, Com2, ecc. ecc.

    In molti libri trovi esempi.

    Tieni presente, però, che per un programma serio, ti tocca quasi sempre avere dei buffer e dei semplici protocolli di comunicazione.
    Se il programma lavora assieme ad altri, potresti essere costretto a scrivere delle parti che reagiscono ad eventi Windows che arrivano dalla porta.
    Inoltre se la cosa ti serve per interfacciare un FEP, allora devi avere anche la sua documentazione.

    Cosa vuoi fare, esattamente?

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2001
    Messaggi
    97

    Grazie Fradefra

    Ciao,
    innanzitutto grazie per l' interessamento.
    Lo scopo del programma era di configurare e leggere delle interfacce per barcode readers tramite COM1 e COM2 e contemporaneamente acquisire dati provenienti da un modulo ASCII-PLC connesso alla porta COM3.

    Parlo al passato in quanto il programa l'ho quasi ultimato. Ho semplicemente utilizzato le funzioni WriteFile, ReadFile ecc..

    Se pero' volessi gestire la seriale a basso livello (quindi ricostruire completamente il protocollo RS232, timing ecc.) Sapresti dove e' possibile prelevare tale informazioni, o titoli di libri che mi potrebbero aiutare in futuro a preparare un driver per seriali ?
    Grazie Ancora
    Ciao.


  4. #4

    Re: Grazie Fradefra

    Vedo che senza saperlo hai usato proprio le funzioni a cui pensavo!
    Per la gestione a basso livello, non so. Non sono mai arrivato a tale livello (non mi serviva).
    Non so dove abiti. Ti consiglio la visita ad una buona libreria informatica. Troverai sicuramente. Se trovi una libreria della catena Hoepli, di solito sono ben forniti sull'informatica.
    Buono studio.

  5. #5
    se posso volevo fare una domanda: Quando vado a leggere sulla seriale (anche la mia collegata ad un PLC) il buffer, non so perkè ma ci sono anke dei karatteri ke nn centra 1 kaxxo kon kuelli ke mi aspetto dal plc, kome faccio a fare un bel clear del buffer?
    users quote:
    - "Ovviamente ho lavorato gratis, non farei mai un lavoro così fatto male a pagamento.."
    "..Non per polemizzare ma diciamoci la verita viva i wizzard di Linux.."
    "..Se comprassi la suse potrei anche comperarmi win. Non credete???.."

  6. #6
    Utente di HTML.it
    Registrato dal
    Jul 2001
    Messaggi
    97
    La funzione che potrebbe aiutarti e' la seguente:

    int fflush( FILE *stream );

    inclusa in <stdio.h>
    Ti allego una veloce spiegazione delhelp on-line di Visual Studio.
    Ciao
    Sergio

    ************************************************** ********************
    Return Value

    fflush returns 0 if the buffer was successfully flushed. The value 0 is also returned in cases in which the specified stream has no buffer or is open for reading only. A return value of EOF indicates an error.

    Note If fflush returns EOF, data may have been lost due to a write failure. When setting up a critical error handler, it is safest to turn buffering off with the setvbuf function or to use low-level I/O routines such as _open, _close, and _write instead of the stream I/O functions.

    Parameter

    stream Pointer to FILE structure

    Remarks

    The fflush function flushes a stream. If the file associated with stream is open for output, fflush writes to that file the contents of the buffer associated with the stream. If the stream is open for input, fflush clears the contents of the buffer. fflush negates the effect of any prior call to ungetc against stream. Also, fflush(NULL) flushes all streams opened for output. The stream remains open after the call. fflush has no effect on an unbuffered stream.

    Buffers are normally maintained by the operating system, which determines the optimal time to write the data automatically to disk: when a buffer is full, when a stream is closed, or when a program terminates normally without closing the stream. The commit-to-disk feature of the run-time library lets you ensure that critical data is written directly to disk rather than to the operating-system buffers. Without rewriting an existing program, you can enable this feature by linking the program's object files with COMMODE.OBJ. In the resulting executable file, calls to _flushall write the contents of all buffers to disk. Only _flushall and fflush are affected by COMMODE.OBJ.

    For information about controlling the commit-to-disk feature, see Stream I/O, fopen, and _fdopen.

    Example




    /* FFLUSH.C */

    #include <stdio.h>
    #include <conio.h>

    void main( void )
    {
    int integer;
    char string[81];

    /* Read each word as a string. */
    printf( "Enter a sentence of four words with scanf: " );
    for( integer = 0; integer < 4; integer++ )
    {
    scanf( "%s", string );
    printf( "%s\n", string );
    }

    /* You must flush the input buffer before using gets. */
    fflush( stdin );
    printf( "Enter the same sentence with gets: " );
    gets( string );
    printf( "%s\n", string );
    }

    Output




    Enter a sentence of four words with scanf: This is a test
    This
    is
    a
    test
    Enter the same sentence with gets: This is a test
    This is a test

    Stream I/O Routines

    (See Also fclose, _flushall, setvbuf)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.