MIchaelfjsmith2 Posted May 22, 2015 Posted May 22, 2015 I am working on a script that will receive a TCP command then send that command to the serial port receive the response and send back out to the TCP client. All works at startup. I am having an issue with reconnecting to the TCP server for a second time. any help would be greatly appreciated. Thanks,expandcollapse popup#include 'CommMG.au3' Global $MainSocket = -1 Global $ConnectedSocket = -1 Global $mode Local $MaxLength = 512; Maximum Length Of String Local $Port = 5200; Port Number Local $Server = "10.144.160.142"; Server IpAddress Global $Comport = 27 ; CommPort Connected TCPStartup() $MainSocket = TCPListen($Server, $Port) If $MainSocket = -1 Then Exit MsgBox(16, "Error", "Unable to intialize socket.") While 2 $Data = TCPRecv($ConnectedSocket, $MaxLength) ; Receive Data from AMX If $Data <> "" Then ; Unconditional Receive ConsoleWrite($Data & @CRLF) SetPort($mode = 1) _CommSendstring($Data & @CR) ; Send Received Data to CommPort Sleep(1000) $instr = _commGetline(@CR,20,200) ; Read Responce from CommPort If $instr <> '' Then;if we got something $instr2 = StringTrimRight($instr,3) ; Removed Garbage at end of String ConsoleWrite($instr2 & @CRLF) TCPSend($ConnectedSocket,$instr2 & @CR) ; Send Responce Back to AMX sleep(10) EndIf EndIf $ConnectedSocket = TCPAccept($MainSocket) If $ConnectedSocket = -1 Then ContinueLoop If $ConnectedSocket <> -1 Then ; Someone Connected TCPSend($ConnectedSocket, "Connected!" & @CR) EndIf WEnd Func SetPort($mode = 1) Local $sportSetError $retval = 0 $resOpen = _CommSetPort($Comport, $sportSetError, 115200, 8, "none", 1, "NONE") Return $retval EndFunc ;==>SetPort Func OnAutoItExit() If $ConnectedSocket <> - 1 Then TCPCloseSocket($ConnectedSocket) EndIf If $MainSocket <> -1 Then TCPCloseSocket($MainSocket) TCPShutdown() _Commcloseport(true) EndFunc;==>OnAutoItExit
JohnOne Posted May 22, 2015 Posted May 22, 2015 I am having an issueYou should outline that issue. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
MIchaelfjsmith2 Posted May 22, 2015 Author Posted May 22, 2015 When i try to reconnect to the server it will not receive anymore commands. i am not sure exactly in the script where i am getting caught on.
JohnOne Posted May 22, 2015 Posted May 22, 2015 You should start by Console write the return, @error, and @extended return values to the console. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
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