#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <CommMG.au3> ;------------- If Not FileExists("portsettings.ini") Then ;если файл не существует, то $iniFile = FileOpen ( @ScriptDir&"\portsettings.ini", 1 );создаём ;и пишем в него всю структуру FileWrite ( $iniFile, "[comport]"&@CRLF&"port=1"&@CRLF&"baud=115200"& _ @CRLF&"databits=8"&@CRLF&"stopbits=1"&@CRLF&"parity=0"&@CRLF&"flowcontrol=0") FileClose ($iniFile) MsgBox (0, "AT sender v.0.1", "Это первый запуск, настройте параметры COM порта в файле portsettings.ini"& _ @CRLF&"port - Номер порта"&@CRLF&"baud - Скopocть (бит/c)"&@CRLF&"databits - Биты дaнныx"&@CRLF& _ "stopbits - Стoпoвыe биты"&@CRLF&"parity - Чeтнocть"&@CRLF&"flowcontrol - Упpaвлeниe пoтoкoм") Exit EndIf ;------------- $port = IniRead (@ScriptDir&"\portsettings.ini", "comport", "port", "NotFound");Номер порта $baud = IniRead (@ScriptDir&"\portsettings.ini", "comport", "baud", "NotFound");Скopocть (бит/c) $databits = IniRead (@ScriptDir&"\portsettings.ini", "comport", "databits", "NotFound");Биты дaнныx $stopbits = IniRead (@ScriptDir&"\portsettings.ini", "comport", "stopbits", "NotFound");Стoпoвыe биты $parity = IniRead (@ScriptDir&"\portsettings.ini", "comport", "parity", "NotFound");Чeтнocть $flowcontrol = IniRead (@ScriptDir&"\portsettings.ini", "comport", "flowcontrol", "NotFound");Упpaвлeниe пoтoкoм $result_err = "" $status_string = "Нет подключения" ;------------- ;подключаемся к порту $portstatus = _CommSetPort($port,$result_err,$baud,$databits,$parity,$stopbits,$flowcontrol) If $portstatus = 1 Then ; если ответ функции 1 то всё ОК и пишем это на лейбле $status_string = "Подключено к порту: COM"&$port Else ; если ответ не 1 то всё плохо... $status_string = "Ошибка подключения к порту: COM"&$port EndIf ; ~~~~~~~~ $Form1 = GUICreate("AT sender v.0.1", 395, 192) $Label1 = GUICtrlCreateLabel ($status_string,8, 2, 390, 17) $Input1 = GUICtrlCreateInput("", 8, 152, 297, 21) $Button1 = GUICtrlCreateButton("Send", 312, 150, 75, 25, 0) $Edit1 = GUICtrlCreateEdit("", 8, 20, 377, 121, $WS_VSCROLL) GUISetState(@SW_SHOW) ; ~~~~~~~~ основной цикл программы ~~~~~~~~ While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE If $portstatus = 1 Then $status_string = "Закрытие порта: COM"&$port&" ..." GUICtrlSetData ($Label1, $status_string) sleep(800);пауза, чтоб успели прочитать лейбл EndIf Exit Case $Button1 $senddata = GUICtrlRead ($Input1); считываем что ввели в Input If Not $senddata = "" Then; если не путо, то отправляем порту _CommSendString($senddata&@CR, 1); в конце нужно добавлять @CR GUICtrlSetData ($Edit1, "Отправлено:"&@CRLF&$senddata&@CRLF,1);пишем в Edit Else GUICtrlSetData ($Edit1, "Ошибка: нечего отправлять!"&@CRLF,1) EndIf EndSwitch $Ret_string = _CommGetstring(); постоянно опрашиваем порт в цикле If Not $Ret_string = "" Then ; если возвращённый результат не пустой GUICtrlSetData ($Edit1, "Принято:"&@CRLF&$Ret_string&@CRLF,1); то пишем в Edit $Ret_string = "";обнуляем переменную EndIf WEnd ; ~~~~~~~~ основной цикл программы ~~~~~~~~ Func OnAutoItExit(); функция срабатывает при выходе. _CommClosePort() ;MsgBox (0, "AT sender v.0.1", "порт закрыт") EndFunc |