Serielle Schnitstelle größer als COM8 öffnen



  • Hallo,

    ich möchte über die Windows-API auch serielle Schnittstellen größer als COM8 öffnen. Bis COM8 ist das kein Problem. Ich bekomme zwar auch ein HANDLE zurück,
    kann die Daten jedoch nicht empfangen und versenden. Wenn ich über meine Applikation die Schnittstelle z.B COM10 öffne, kann das Windows-Terminal immer noch
    ohne Fehlermeldung die COM10 öffnen und empfängt auch die Daten. Wie muß ich vorgehen um auch meine Applikation zu bewegen, die COM10 exclusiv zu öffen und Daten zu empfangen?

    Bisher habe ich folgendes zum öffnen der Schnittstelle benutzt:

    hCom = CreateFile(portname,
                      GENERIC_READ|GENERIC_WRITE,
                      0,
                      NULL,
                      OPEN_EXISTING,
                      0,
                      NULL);
    

    Mit frdl. Gruß
    ruppi98



  • Dieser Thread wurde von Moderator/in akari aus dem Forum VCL (C++ Builder) in das Forum WinAPI verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.



  • Bin gerade auch dabei eine serielle Kommunikation herzustellen.
    In deinem Code ist mir halt nur aufgefallen dass ein Flag auf 0 gesetzt ist, welches eigentlich einen Wert braucht. Keine Ahnung vielleicht ist das das Problem:

    hCom = CreateFile(portname,
                      GENERIC_READ|GENERIC_WRITE,
                      0,
                      NULL,
                      OPEN_EXISTING,
                      0,      <------------------
                      NULL);
    

    hier die möglichen Flags die man da einstellen kann:
    exklusiv wäre glaube ich non-overlapped, von daher vielleicht FILE_ATTRIBUTE_NORMAL.

    dwFlagsAndAttributes - defines the file attributes and flags. Any combination of the following attributes except the FILE_ATTRIBUTE_NORMAL attribute is possible:

    * FILE_ATTRIBUTE_ARCHIVE - the file must be archived. The applications use this attribute to mark the file for reserve copying or deletion.
    * FILE_ATTRIBUTE_COMPRESSED - file or catalogue is compressed . If it's a file, it means that all data in the file are compressed. If it's a catalogue it means that compression is the default value for recently created files and subdirectories.
    * FILE_ATTRIBUTE_HIDDEN - the file is hidden. It shouldn't be included into the usual directory list.
    * FILE_ATTRIBUTE_NORMAL - the file has no attributes.
    * FILE_ATTRIBUTE_OFFLINE - the data of the file are not available at the moment. It shows that the data of the file have been moved to an off-line archive.
    * FILE_ATTRIBUTE_READONLY - the file is read-only. The applications can read the file but cannot write or delete the data.
    * FILE_ATTRIBUTE_SYSTEM - a part of the file is used by the operation system only.
    * FILE_ATTRIBUTE_TEMPORARY - the file is used for temporary data storing. File systems try to keep all data in memory for quicker access rather than flushing the data back to mass archive. A temporary file should be deleted by the application as soon as it is no longer needed.

    Also possible is any combination of the following flags:

    * FILE_FLAG_WRITE_THROUGH
    * FILE_FLAG_OVERLAPPED
    * FILE_FLAG_NO_BUFFERING
    * FILE_FLAG_RANDOM_ACCESS
    * FILE_FLAG_SEQUENTIAL_SCAN
    * FILE_FLAG_DELETE_ON_CLOSE
    * FILE_FLAG_BACKUP_SEMANTICS
    * FILE_FLAG_POSIX_SEMANTICS



  • Du musst als Portnamen folgende Notation verwenden:

    TCHAR portname[] = _T("\\\\.\\COM10");
    

    Grüsse
    Simon



  • Hallo,

    erst mal vielen Dank für die schnellen Antworten.

    Zur Antwort von JDHawk.
    Die "0" am Parameter dwFlagsAndAttributes ist nach meiner Meinung ok, da ich kein OVERLAPPED benutzen will.

    Ich denke also nicht, das das mein Problem ist. Trotzdem Danke.

    Nun zur Antwort von simon.gysi:

    Wenn ich im C++Builder Deine Anweisung compiliere bekomme ich folgende Fehlermeldung:

    [C++ Fehler] Unit1.cpp(15): E2268 Aufruf der undefinierten Funktion '_T'
    [C++ Fehler] Unit1.cpp(15): E2034 Konvertierung von 'int' nach 'char[]' nicht möglich

    Wo liegt hier das Problem?

    Mit frdl. Gruß

    ruppi98



  • Hallo,

    habe Fehler erkannt 😉
    Hatt vergessen "#include "TCHAR.H"" einzubinden. 😞
    Funktioniert nun alles prima 🙂 .

    Vielen Dank an alle!!

    ruppi98


Anmelden zum Antworten