Ndg Posted July 6, 2008 Posted July 6, 2008 heya folks it's my first day programming with autoit. what i want to do, i have a neuros media center box with linux on it. by telnet i can send commands, no problem. what i want to do, do a programm on my computer (windows), that does this commands in the background. for example to play music, i write down "xmms2 play" and so on... this is what i've done til now... is that the "best" way, or a good way, or is it just crap... i mean it works, but i think i looks a bit ugly, if everytime i press a button, quickly a black window starts up... some suggestions? thank you all. expandcollapse popup#include <GuiConstantsEx.au3> #include <AVIConstants.au3> #include <TreeViewConstants.au3> $window = GUICreate("Neuros Music Controller v1.0", 800, 800) GUISetState(@SW_SHOW) ; MENU GuiCtrlCreateMenu("Datei") GuiCtrlCreateMenu("Bearbeiten") GuiCtrlCreateMenu("Ansicht") GuiCtrlCreateMenu("Beenden") GUICtrlSetOnEvent(-1,"quit") ;PIC GuiCtrlCreatePic("neuros.jpg",277,0, 245,246) GuiCtrlSetColor(-1,0xffffff) Opt("GUIOnEventMode", 1) $prev = GUICtrlCreateButton("prev", 200, 330, 100, 30) GUICtrlSetOnEvent(-1,"prevPressed") $stop = GUICtrlCreateButton("stop", 300, 330, 100, 30) GUICtrlSetOnEvent(-1,"stopPressed") $play = GUICtrlCreateButton("PLAY", 400, 330, 100, 30) GUICtrlSetOnEvent(-1,"playPressed") $next = GUICtrlCreateButton("next", 500, 330, 100, 30) GUICtrlSetOnEvent(-1,"nextPressed") Func prevPressed() ;Run Telnet Run("telnet 192.168.xxx.xxx") ;Rename window $WinTitle="Telnet 192.168.xxx.xxx" WinWait("Telnet 192.168.xxx.xxx","") WinSetTitle("Telnet 192.168.xxx.xxx","",$WinTitle) WinSetState($WinTitle, "", @SW_HIDE) ;Login ControlSend($WinTitle,"","","user{ENTER}") ControlSend($WinTitle,"","","password{ENTER}") ControlSend($WinTitle,"","","xmms2 prev{Enter}") EndFunc ;==>playPressed Func stopPressed() ;Run Telnet Run("telnet 192.168.xxx.xxx") ;Rename window $WinTitle="Telnet 192.168.xxx.xxx" WinWait("Telnet 192.168.xxx.xxx","") WinSetTitle("Telnet 192.168.xxx.xxx","",$WinTitle) WinSetState($WinTitle, "", @SW_HIDE) ;Login ControlSend($WinTitle,"","","user{ENTER}") ControlSend($WinTitle,"","","password{ENTER}") ControlSend($WinTitle,"","","xmms2 stop{Enter}") EndFunc ;==>playPressed Func playPressed() ;Run Telnet Run("telnet 192.168.xxx.xxx") ;Rename window $WinTitle="Telnet 192.168.xxx.xxx" WinWait("Telnet 192.168.xxx.xxx","") WinSetTitle("Telnet 192.168.xxx.xxx","",$WinTitle) WinSetState($WinTitle, "", @SW_HIDE) ;Login ControlSend($WinTitle,"","","user{ENTER}") ControlSend($WinTitle,"","","password{ENTER}") ControlSend($WinTitle,"","","xmms2 play{Enter}") EndFunc ;==>playPressed Func nextPressed() ;Run Telnet Run("telnet 192.168.xxx.xxx") ;Rename window $WinTitle="Telnet 192.168.xxx.xxx" WinWait("Telnet 192.168.xxx.xxx","") WinSetTitle("Telnet 192.168.xxx.xxx","",$WinTitle) WinSetState($WinTitle, "", @SW_HIDE) ;Login ControlSend($WinTitle,"","","user{ENTER}") ControlSend($WinTitle,"","","password{ENTER}") ControlSend($WinTitle,"","","xmms2 next{Enter}") EndFunc ;==>playPressed Func quit() $GUI_EVENT_CLOSE EndFunc ;==>playPressed GuiSetState() While GuiGetMsg() <> $GUI_EVENT_CLOSE WEnd
TomZ Posted July 6, 2008 Posted July 6, 2008 Instead of using the telnet tool, you can use AutoIt's native TCP functions. Example: TCPStartUp() $socket = TCPConnect(127.0.0.1, 80) TCPSend($socket, "hello" & @CRLF) MsgBox(0, "TCP Example - server response", TCPReceive($socket, 1024)) TCPSend($socket, "bye" & @CRLF) TCPCloseSocket($socket) TCPShutDown()
Eric88 Posted July 27, 2008 Posted July 27, 2008 Instead of using the telnet tool, you can use AutoIt's native TCP functions.Example:TCPStartUp()$socket = TCPConnect(127.0.0.1, 80)TCPSend($socket, "hello" & @CRLF)MsgBox(0, "TCP Example - server response", TCPReceive($socket, 1024))TCPSend($socket, "bye" & @CRLF)TCPCloseSocket($socket)TCPShutDown()Hi TomZ!i don't think AutoIt native TCP function could solve the telnet problme IF you are telnet into server which running Linux likeRedhat or CentOS . It will prompt unusual char refer to http://www.autoitscript.com/forum/index.php?showtopic=44542Please advice!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now