ComportStati - Statusleitungen der seriellen Schnittstelle steuern

  • Hallo AutoIt Gemeinde!

    Ich habe ein kleines Skript zum Ansteuern/Auslesen der Statusleitungen der seriellen Schnittstelle geschrieben. Vielleicht kann der ein oder andere "Elektronikbewanderte" was damit anfangen. Ich benutze es, um die Pegel in Interface-Schaltungen gezielt beeinflussen und messen zu können.

    [Blockierte Grafik: http://franksteinberg.de/IMG/ComportStati.png

    • Verwendet nur WinAPI-Funktionen, läuft auf AutoIt ohne Extra-Dateien.
    • Funktioniert auch mit USB-seriell Adaptern.
    • Liest die vorhanden Com-Schnittstellen aus der Registry aus.
    • Macht "Bitbanging", keine serielle Datenübertragung (UART), dafür gibt es ja diesen Thread (von dem einiges gelernt habe).
    Spoiler anzeigen
    [autoit]


    ;- ComportStati.au3 --------------------------------------------- >>fst'12<< -
    ; - set/unset output statuslines (plus TxD) of serial port
    ; - read input statuslines of serial port
    ; - uses WinAPI only, no special DLLs, no extra UDFs
    ; - should work with native comport and serial-USB-Adapters
    ; - for AutoIt3 - http://www.autoitscript.com - http://www.autoit.de
    ;- V 20120402 --------------------------------- http://www.FrankSteinberg.de -

    [/autoit] [autoit][/autoit] [autoit]

    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Build GUI:
    Opt("GUIOnEventMode", 1)
    #Region ### START Koda GUI section ### Form=C:\WinSpr\AutoIt\_Eigenes\COMStati.kxf
    $Form1 = GUICreate(" ComportStati >>fst'12<<", 225, 211, -1, -1, $WS_SYSMENU)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
    $Combo_Port = GUICtrlCreateCombo("No Port", 8, 8, 73, -1)
    GUICtrlSetOnEvent(-1, "Combo_PortChange")
    $Group_IN = GUICtrlCreateGroup(" IN ", 112, 40, 97, 113)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Check_TxD = GUICtrlCreateCheckbox(" TxD Pin 3", 16, 80, 80, 24)
    GUICtrlSetOnEvent(-1, "Check_TxDClick")
    $Check_DTR = GUICtrlCreateCheckbox(" DTR Pin 4", 16, 104, 80, 24)
    GUICtrlSetOnEvent(-1, "Check_DTRClick")
    $Check_RTS = GUICtrlCreateCheckbox(" RTS Pin 7", 16, 128, 80, 24)
    GUICtrlSetOnEvent(-1, "Check_RTSClick")
    $Group_OUT = GUICtrlCreateGroup(" OUT ", 8, 64, 97, 89)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Check_DCD = GUICtrlCreateCheckbox(" DCD Pin 1", 120, 56, 80, 24)
    $Check_DSR = GUICtrlCreateCheckbox(" DSR Pin 6", 120, 80, 80, 24)
    $Check_CTS = GUICtrlCreateCheckbox(" CTS Pin 8", 120, 104, 80, 24)
    $Check_RI = GUICtrlCreateCheckbox(" RI Pin 9", 120, 128, 80, 24)
    $Label_Info = GUICtrlCreateLabel("choose a COMport", 96, 12, 98, 17, 0)
    $Label_URL = GUICtrlCreateLabel("www.FrankSteinberg.de", 47, 160, 118, 17, 0)
    GUICtrlSetOnEvent(-1, "Label_URLClick")
    GUICtrlSetColor(-1, 0x3399FF)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Declare global variables:
    Global $hSerialPort[1] ;handle for seruial port
    Global $lpModemStat ;pointer to status of serial input-lines
    Global $sComboVal ;comport selected by user (combobox)
    Global $sPortList ;list of all valid ports

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Create struct with one element to store input-line values - see Func Pin_Read():
    $lpModemStat = DllStructCreate("DWORD")

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Main loop:
    While 1
    Port_Search() ;read valid ports from registry and add to combobox
    Pin_Read() ;read status of comport input lines and show as checkboxes
    Sleep(100) ;give some time to windows
    WEnd
    ;*** Main loop end

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Read valid ports from registry and add to combobox:
    Func Port_Search() ;
    $sPortListOld = $sPortList ;remember last values
    $sPortList = "" ;delete last values
    For $i = 1 To 256 ;max. possible comports = COM1 - COM256
    Local $sRegVal = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM\", $i) ;... all valid ports listed here
    If @error <> 0 Then ExitLoop ;abort after last value
    $sPortList = $sPortList & "|" & RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $sRegVal) ;add value to list
    Next
    If $sPortList = $sPortListOld Then Return ;exit func when no difference from last call
    GUICtrlSetData($Combo_Port, $sPortList & "|close port") ;... otherwise replace list in combobox
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Open serial port using WinAPI:
    Func Port_Open()
    ;** Open Port with 'CreateFile'; prefix '\\.\' adds support for Ports greater than COM9:
    $hSerialPort = DllCall("kernel32.dll","hwnd","CreateFile","str","\\.\"&$sComboVal,"int",0xC0000000,"int",0,"ptr",0,"int",3,"int",0,"int",0)
    GUICtrlSetData($Label_Info, $sComboVal & " open") ;write success-message to gui
    If Number($hSerialPort[0]) < 1 Or @error Then ;if no success ...
    GUICtrlSetData($Label_Info, "Com ERROR !") ;... write to gui
    Return ;... and exit func
    EndIf
    Check_DTRClick() ;switch DTR to current checkbox state
    Check_RTSClick() ;switch RTS to current checkbox state
    Check_TxDClick() ;switch TxD to current checkbox state
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Close serial Port:
    Func Port_Close()
    $hClose=DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hSerialPort[0]) ;Win-API
    If $hClose >= 0 Then GUICtrlSetData($Label_Info, "COM closed") ;write message to gui
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Read input-lines values and show as checkboxes:
    Func Pin_Read()
    ;** Read stati of input-lines using WinAPI 'GetCommModemStatus':
    DllCall("kernel32.dll", "long", "GetCommModemStatus", "HWND", $hSerialPort[0], "Ptr", DllStructGetPtr($lpModemStat))
    $iPinState = DllStructGetData($lpModemStat, 1) ;all values are in $iPinState
    ;MsgBox(4096, String($lpModemStat), String($iPinState))
    ;Isolate value for CTS pin:
    If BitAND($iPinState, 0x10) Then ;0x10 = MS_CTS_ON
    GUICtrlSetState($Check_CTS, $GUI_CHECKED) ;set checbox, if bit is set
    Else
    GUICtrlSetState($Check_CTS, $GUI_UNCHECKED) ;uncheck, if bit is unset
    EndIf
    ;Isolate value from DSR pin:
    If BitAND($iPinState, 0x20) Then ;0x20 = MS_DSR_ON
    GUICtrlSetState($Check_DSR, $GUI_CHECKED)
    Else
    GUICtrlSetState($Check_DSR, $GUI_UNCHECKED)
    EndIf
    ;Isolate value from RI pin:
    If BitAND($iPinState, 0x40) Then ;0x40 = MS_RING_ON
    GUICtrlSetState($Check_RI, $GUI_CHECKED)
    Else
    GUICtrlSetState($Check_RI, $GUI_UNCHECKED)
    EndIf
    ;Isolate value from DCD pin:
    If BitAND($iPinState, 0x80) Then ;0x80 = MS_RLSD_ON
    GUICtrlSetState($Check_DCD, $GUI_CHECKED)
    Else
    GUICtrlSetState($Check_DCD, $GUI_UNCHECKED)
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Set/unset DTR pin using WinAPI 'EscapeCommFunction', when user clicks checkbox:
    Func Check_DTRClick()
    If GUICtrlRead($Check_DTR) = $GUI_CHECKED Then
    DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 5) ;5=SETDTR; set DTR high
    Else
    DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 6) ;6=CLRDTR; set DTR low
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Set/unset RTS pin using WinAPI 'EscapeCommFunction', when user clicks checkbox:
    Func Check_RTSClick()
    If GUICtrlRead($Check_RTS) = $GUI_CHECKED Then
    DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 3) ;3=SETRTS; set RTS high
    Else
    DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 4) ;4=CLRRTS; set RTS low
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Set/unset DTR pin using WinAPI 'EscapeCommFunction', when user clicks checkbox:
    Func Check_TxDClick()
    If GUICtrlRead($Check_TxD) = $GUI_CHECKED Then
    DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 8) ;8=SETBREAK; set TxD high (break)
    Else
    DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 9) ;9=CLRBREAK; set TxD low
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Open/close serial Port, depending on users clicks in combobox:
    Func Combo_PortChange()
    $sComboVal = GUICtrlRead($Combo_Port) ;read user value
    Port_Close() ;close previous opened port
    GUICtrlSetState($Check_TxD, $GUI_FOCUS) ;go to first checkbox
    If GUICtrlRead($Combo_Port) = "close port" Then Return ;exit func, close-only is selected
    Port_Open() ;open selected port
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Close port and exit app, when window is closed:
    Func Form1Close()
    Port_Close()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ;*** Show authors website on click on label:
    Func Label_URLClick()
    ShellExecute("http://www.franksteinberg.de")
    EndFunc

    [/autoit]
  • Hallo,


    habe eben ausprobiert und egal welchen Port ich wähle stürzt das Programm mit folgender fehlermeldung ab:

    Error parsing function call.:
    If Number($hSerialPort[0]) < 1 OrOr @error Then
    If Number($hSerialPort[0]) < 1 ^ ERROR


    Habe leider keine Zeit selber nachzuschauen....

  • Bei dir ist es:
    If Number($hSerialPort[0]) < 1 OrOr @error then

    Du musst es auf
    If Number($hSerialPort[0]) < 1 Or @error then

    ändern glaube ich.

  • Checkboxen bitte IMMER mit BitAND(GUICtrlRead($cCheck), $GUI_CHECKED) abfragen. Ansonsten schönes Tool.


  • Dann ändert sich die Spannung an Pin4 von ca. -12V auf ca. +12V.


    Darauf kann man sich nicht verlassen. Nach meiner Erfahrung sinds beim normalen PC wirklich ca. -12V und +12V,
    aber bei Notebooks sind auch -5V und +5V möglich.
    Ich zitiere mal aus dem Wiki:

    Zitat


    EIA-232 ist eine Spannungsschnittstelle (im Gegensatz z. B. zu einer Stromschnittstelle). Die Information (Bit) wird durch eine elektrische Spannung kodiert.
    Für die Datenleitungen (TxD und RxD) wird eine negative Logik verwendet, wobei eine Spannung zwischen −3 V und −15 V (ANSI/EIA/TIA-232-F-1997) eine logische Eins und eine Spannung zwischen +3 V und +15 V eine logische Null darstellt. Signalpegel zwischen −3 V und +3 V gelten als undefiniert.
    Bei den Steuerleitungen (DCD, DTR, DSR, RTS, CTS und RI) wird der aktive Zustand durch eine Spannung zwischen +3 V und +15 V dargestellt, der inaktive Zustand durch eine Spannung zwischen −3 V und −15 V.


    Quell: http://de.wikipedia.org/wiki/RS-232
    Also, verlass dich nicht auf die 12V... wenn deine Schaltung nur an einem bestimmten PC betrieben wird, nachmessen und gut isses.
    Wenn du ein zuverlässiges Gerät willst, das an jeder RS232 Schnittstelle läuft, musst du mit ungewöhnlichen Spannungen rechnen.
    Es gab schon so einige vermurkste Geräte, die nicht an jedem PC laufen, z.B. primitive PIC Programmiergeräte (braucht unbedingt 12V).
    Zum Glück gibts heutzutage USB, das läuft zwar nur noch mit Microcontroller, aber immerhin ist es ordentlich genormt.
    Empfehlung: http://www.sprut.de/electronic/pic…all/usb4all.htm

    Wer andern eine Bratwurst brät
    der hat ein Bratwurstbratgerät.

  • [quote='Steini63','index.php?page=Thread&postID=251074#post251074']Hallo AutoIt Gemeinde!

    Ich habe ein kleines Skript zum Ansteuern/Auslesen der Statusleitungen der seriellen Schnittstelle geschrieben. Vielleicht kann der ein oder andere "Elektronikbewanderte" was damit anfangen. Ich benutze es, um die Pegel in Interface-Schaltungen gezielt beeinflussen und messen zu können.

    [Blockierte Grafik: http://franksteinberg.de/IMG/ComportStati.png

    • Verwendet nur WinAPI-Funktionen, läuft auf AutoIt ohne Extra-Dateien.
    • Funktioniert auch mit USB-seriell Adaptern.
    • Liest die vorhanden Com-Schnittstellen aus der Registry aus.
    • Macht "Bitbanging", keine serielle Datenübertragung (UART), dafür gibt es ja Hallo AutoIt Gemeinde!

      Ich habe ein kleines Skript zum Ansteuern/Auslesen der Statusleitungen der seriellen Schnittstelle geschrieben. Vielleicht kann der ein oder andere "Elektronikbewanderte" was damit anfangen. Ich benutze es, um die Pegel in Interface-Schaltungen gezielt beeinflussen und messen zu können.

      [Blockierte Grafik: http://franksteinberg.de/IMG/ComportStati.png
      [list]

    • Verwendet nur WinAPI-Funktionen, läuft auf AutoIt ohne Extra-Dateien.
    • Funktioniert auch mit USB-seriell Adaptern.
    • Liest die vorhanden Com-Schnittstellen aus der Registry aus.
    • Macht "Bitbanging", keine serielle Datenübertragung (UART), dafür gibt es ja diesen Thread (von dem einiges gelernt habe).

      Spoiler anzeigen
      [autoit]


      ;- ComportStati.au3 --------------------------------------------- >>fst'12<< -
      ; - set/unset output statuslines (plus TxD) of serial port
      ; - read input statuslines of serial port
      ; - uses WinAPI only, no special DLLs, no extra UDFs
      ; - should work with native comport and serial-USB-Adapters
      ; - for AutoIt3 - http://www.autoitscript.com - http://www.autoit.de
      ;- V 20120402 --------------------------------- http://www.FrankSteinberg.de -

      [/autoit] [autoit][/autoit] [autoit]

      #include
      #include
      #include
      #include
      #include

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Build GUI:
      Opt("GUIOnEventMode", 1)
      #Region ### START Koda GUI section ### Form=C:\WinSpr\AutoIt\_Eigenes\COMStati.kxf
      $Form1 = GUICreate(" ComportStati >>fst'12<<", 225, 211, -1, -1, $WS_SYSMENU)
      GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
      $Combo_Port = GUICtrlCreateCombo("No Port", 8, 8, 73, -1)
      GUICtrlSetOnEvent(-1, "Combo_PortChange")
      $Group_IN = GUICtrlCreateGroup(" IN ", 112, 40, 97, 113)
      GUICtrlCreateGroup("", -99, -99, 1, 1)
      $Check_TxD = GUICtrlCreateCheckbox(" TxD Pin 3", 16, 80, 80, 24)
      GUICtrlSetOnEvent(-1, "Check_TxDClick")
      $Check_DTR = GUICtrlCreateCheckbox(" DTR Pin 4", 16, 104, 80, 24)
      GUICtrlSetOnEvent(-1, "Check_DTRClick")
      $Check_RTS = GUICtrlCreateCheckbox(" RTS Pin 7", 16, 128, 80, 24)
      GUICtrlSetOnEvent(-1, "Check_RTSClick")
      $Group_OUT = GUICtrlCreateGroup(" OUT ", 8, 64, 97, 89)
      GUICtrlCreateGroup("", -99, -99, 1, 1)
      $Check_DCD = GUICtrlCreateCheckbox(" DCD Pin 1", 120, 56, 80, 24)
      $Check_DSR = GUICtrlCreateCheckbox(" DSR Pin 6", 120, 80, 80, 24)
      $Check_CTS = GUICtrlCreateCheckbox(" CTS Pin 8", 120, 104, 80, 24)
      $Check_RI = GUICtrlCreateCheckbox(" RI Pin 9", 120, 128, 80, 24)
      $Label_Info = GUICtrlCreateLabel("choose a COMport", 96, 12, 98, 17, 0)
      $Label_URL = GUICtrlCreateLabel("www.FrankSteinberg.de", 47, 160, 118, 17, 0)
      GUICtrlSetOnEvent(-1, "Label_URLClick")
      GUICtrlSetColor(-1, 0x3399FF)
      GUISetState(@SW_SHOW)
      #EndRegion ### END Koda GUI section ###

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Declare global variables:
      Global $hSerialPort[1] ;handle for seruial port
      Global $lpModemStat ;pointer to status of serial input-lines
      Global $sComboVal ;comport selected by user (combobox)
      Global $sPortList ;list of all valid ports

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Create struct with one element to store input-line values - see Func Pin_Read():
      $lpModemStat = DllStructCreate("DWORD")

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Main loop:
      While 1
      Port_Search() ;read valid ports from registry and add to combobox
      Pin_Read() ;read status of comport input lines and show as checkboxes
      Sleep(100) ;give some time to windows
      WEnd
      ;*** Main loop end

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Read valid ports from registry and add to combobox:
      Func Port_Search() ;
      $sPortListOld = $sPortList ;remember last values
      $sPortList = "" ;delete last values
      For $i = 1 To 256 ;max. possible comports = COM1 - COM256
      Local $sRegVal = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM\", $i) ;... all valid ports listed here
      If @error <> 0 Then ExitLoop ;abort after last value
      $sPortList = $sPortList & "|" & RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $sRegVal) ;add value to list
      Next
      If $sPortList = $sPortListOld Then Return ;exit func when no difference from last call
      GUICtrlSetData($Combo_Port, $sPortList & "|close port") ;... otherwise replace list in combobox
      EndFunc

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Open serial port using WinAPI:
      Func Port_Open()
      ;** Open Port with 'CreateFile'; prefix '\\.\' adds support for Ports greater than COM9:
      $hSerialPort = DllCall("kernel32.dll","hwnd","CreateFile","str","\\.\"&$sComboVal,"int",0xC0000000,"int",0,"ptr",0,"int",3,"int",0,"int",0)
      GUICtrlSetData($Label_Info, $sComboVal & " open") ;write success-message to gui
      If Number($hSerialPort[0]) < 1 Or @error Then ;if no success ...
      GUICtrlSetData($Label_Info, "Com ERROR !") ;... write to gui
      Return ;... and exit func
      EndIf
      Check_DTRClick() ;switch DTR to current checkbox state
      Check_RTSClick() ;switch RTS to current checkbox state
      Check_TxDClick() ;switch TxD to current checkbox state
      EndFunc

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Close serial Port:
      Func Port_Close()
      $hClose=DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hSerialPort[0]) ;Win-API
      If $hClose >= 0 Then GUICtrlSetData($Label_Info, "COM closed") ;write message to gui
      EndFunc

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Read input-lines values and show as checkboxes:
      Func Pin_Read()
      ;** Read stati of input-lines using WinAPI 'GetCommModemStatus':
      DllCall("kernel32.dll", "long", "GetCommModemStatus", "HWND", $hSerialPort[0], "Ptr", DllStructGetPtr($lpModemStat))
      $iPinState = DllStructGetData($lpModemStat, 1) ;all values are in $iPinState
      ;MsgBox(4096, String($lpModemStat), String($iPinState))
      ;Isolate value for CTS pin:
      If BitAND($iPinState, 0x10) Then ;0x10 = MS_CTS_ON
      GUICtrlSetState($Check_CTS, $GUI_CHECKED) ;set checbox, if bit is set
      Else
      GUICtrlSetState($Check_CTS, $GUI_UNCHECKED) ;uncheck, if bit is unset
      EndIf
      ;Isolate value from DSR pin:
      If BitAND($iPinState, 0x20) Then ;0x20 = MS_DSR_ON
      GUICtrlSetState($Check_DSR, $GUI_CHECKED)
      Else
      GUICtrlSetState($Check_DSR, $GUI_UNCHECKED)
      EndIf
      ;Isolate value from RI pin:
      If BitAND($iPinState, 0x40) Then ;0x40 = MS_RING_ON
      GUICtrlSetState($Check_RI, $GUI_CHECKED)
      Else
      GUICtrlSetState($Check_RI, $GUI_UNCHECKED)
      EndIf
      ;Isolate value from DCD pin:
      If BitAND($iPinState, 0x80) Then ;0x80 = MS_RLSD_ON
      GUICtrlSetState($Check_DCD, $GUI_CHECKED)
      Else
      GUICtrlSetState($Check_DCD, $GUI_UNCHECKED)
      EndIf
      EndFunc

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Set/unset DTR pin using WinAPI 'EscapeCommFunction', when user clicks checkbox:
      Func Check_DTRClick()
      If GUICtrlRead($Check_DTR) = $GUI_CHECKED Then
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 5) ;5=SETDTR; set DTR high
      Else
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 6) ;6=CLRDTR; set DTR low
      EndIf
      EndFunc

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Set/unset RTS pin using WinAPI 'EscapeCommFunction', when user clicks checkbox:
      Func Check_RTSClick()
      If GUICtrlRead($Check_RTS) = $GUI_CHECKED Then
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 3) ;3=SETRTS; set RTS high
      Else
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 4) ;4=CLRRTS; set RTS low
      EndIf
      EndFunc

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Set/unset DTR pin using WinAPI 'EscapeCommFunction', when user clicks checkbox:
      Func Check_TxDClick()
      If GUICtrlRead($Check_TxD) = $GUI_CHECKED Then
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 8) ;8=SETBREAK; set TxD high (break)
      Else
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 9) ;9=CLRBREAK; set TxD low
      EndIf
      EndFunc

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Open/close serial Port, depending on users clicks in combobox:
      Func Combo_PortChange()
      $sComboVal = GUICtrlRead($Combo_Port) ;read user value
      Port_Close() ;close previous opened port
      GUICtrlSetState($Check_TxD, $GUI_FOCUS) ;go to first checkbox
      If GUICtrlRead($Combo_Port) = "close port" Then Return ;exit func, close-only is selected
      Port_Open() ;open selected port
      EndFunc

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Close port and exit app, when window is closed:
      Func Form1Close()
      Port_Close()
      Exit
      EndFunc

      [/autoit] [autoit][/autoit] [autoit]

      ;*** Show authors website on click on label:
      Func Label_URLClick()
      ShellExecute("http://www.franksteinberg.de")
      EndFunc

      [/autoit]


    hä?

  • Hallo, Steini,

    VIELEN VIELEN VIELEN ALLEN DANK DER WELT, DASS DU DIESES PROGRAMM GESCHRIEBEN HAST!
    Ich versuche jetzt schon seit 2 verdam_ten Jahren den RS232 Port mit AutoIt anzusteuern! Und da kommst du an, und hast so ein geiles Prog!
    Ich weiß gar nicht wie ich dir danken kann! Ich versteh den Script zwar nicht so ganz, aber ich versuche mal das zu tun!
    Ähm! Würde es dir was ausmachen, wenn du vielleicht eine kleine UDF zaubern könntest, mit der man DTR, RTS und TXD schalten kann?
    Und eventuell die Eingänge abfragen kann?
    Das wäre jetzt noch die Sahnehaube! Ich komme nähmlich mit deinem Script nicht so ganz klar, und verstehe nur Bahnhof!
    Weißt du, so viel hab ich mit AutoIt nun doch nicht gemacht!
    Das währe echt MEGA COOL von Dir, wenn du das machen könntest!
    Und ich verspreche dir: IN JEDEM PROGRAMM, IN DEM ICH DIESE UDF VERWENDE, WIRD DEIN NAME ALS AUTOR STEHEN!
    DARAUF KANNSTE GIFT NEHMEN! WOW! ICH BIN DIR SO DANKBAR! DANKE :)
    :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :)

  • nö, der lebt noch! der ist bloß viel im englischen forum! :D
    DANKE! für dein Kommentar!° WAS IST PN-SYSTEM?a4hkjfresgkjlrsghjsg ?(

    • 'nen Scheck brauche ich nicht, sondern mehr Zeit (falls du welche zu verschenken hast). :D
    • Tot bin ich nicht, ich stell mich nur manchmal tot. :sleeping:
    • Eine UDF gibt es im Prinzip schon, nur nicht für alle Leitungen/Pins -> Link .
    • Hier mal ein Prog, was auf das unbedingt Nötige beschränkt ist:
      [autoit]; *** Com1 öffnen:
      $hSerialPort = DllCall("kernel32.dll","hwnd","CreateFile","str","\\.\com1","int",0xC0000000,"int",0,"ptr",0,"int",3,"int",0,"int",0)

      ; *** Ausgänge steuern:

      ; 0,5 Sek für's menschliche Auge:
      Sleep(500)
      ; Alle Output-Pins mittels WinAPI 'EscapeCommFunction' auf ca.-12V setzen:
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 4) ;4=CLRRTS; set RTS low
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 6) ;6=CLRDTR; set DTR low
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 9) ;9=CLRBREAK; set TxD low
      ; 0,5 Sek für's menschliche Auge:
      Sleep(500)
      ; Alle Output-Pins mittels WinAPI 'EscapeCommFunction' auf ca. +12V setzen:
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 3) ;3=SETRTS; set RTS high
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 5) ;5=SETDTR; set DTR high
      DllCall("kernel32.dll","long","EscapeCommFunction","hwnd", $hSerialPort[0],"long", 8) ;8=SETBREAK; set TxD high (break)

      ; *** Eingänge lesen:

      ; Struktur mit einem Element für das Lesen der Eingänge erzeugen:
      $lpModemStat = DllStructCreate("DWORD")
      ; Input-Pins mittels WinAPI 'GetCommModemStatus' lesen:
      DllCall("kernel32.dll", "long", "GetCommModemStatus", "HWND", $hSerialPort[0], "Ptr", DllStructGetPtr($lpModemStat))
      $iPinState = DllStructGetData($lpModemStat, 1) ;Zustand der Pins nach $iPinState
      ; Werte für einzelne Pins isolieren:
      $sCTS = " CTS=off "
      If BitAND($iPinState, 0x10) Then $sCTS = " CTS=ON " ;0x10 = MS_CTS_ON
      $sDSR = " DSR=off "
      If BitAND($iPinState, 0x20) Then $sDSR = " DSR=ON " ;0x20 = MS_DSR_ON
      $sRing = " Ring=off "
      If BitAND($iPinState, 0x40) Then $sRing = " Ring=ON " ;0x40 = MS_RING_ON
      $sDCD = " DCD=off "
      If BitAND($iPinState, 0x80) Then $sDCD = " DCD=ON " ;0x80 = MS_RLSD_ON
      ; PinStatus anzeigen:
      MsgBox(0, " Com-Port", $sCTS & $sDSR & $sRing & $sDCD)

      ; *** ComPort schließen:
      DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hSerialPort[0]) ;Win-API

      [/autoit]

    Steini