#include #include #include ;Global $sIPAddress = "192.168.0.102" ; Set the Variable $sIPAddress. ;Global $iPort = "9100" ;9100 ; Port used for the connection. ; Inifil FilePath = Arbejds Mappen + ZEBRA-Utillity.ini Global Const $IniFilePath = (@ScriptDir&'\STG_XML.ini') ; File Navn på INI Filen "ZEBRA-Utillity.ini" ; Create application object Local $oExcel = _Excel_Open() Local $bReadOnly = False Local $bVisible = True Local Const $sFilePath = @WorkingDir & "/test1.txt" ; Vælg Filnavn og Path hvor Fil skal gemmes. ; Register OnAutoItExit to be called when the script is closed. OnAutoItExitRegister("OnAutoItExit") $iIPAddress = IniRead($IniFilePath, "HM_Application", "IP_Address", "127.0.0.1") ; Indlæs IP Address fra Ini Fil $iSUBNet = IniRead($IniFilePath, "HM_Application", "SubNet-Mask", "255.255.255.0") ; Indlæs IP Address fra Ini Fil $iPort = IniRead($IniFilePath, "HM_Application", "PORT", "9100") ; Indlæs Port No. fra Ini Fil $iColumn = IniRead($IniFilePath, "Exel_Ark", "Column_Read", "A") ; Indlæs Colonne Ident. fra Ini Fil ; **************************************************************************** ; Open an existing workbook and return its object identifier. ; ***************************************************************************** Local $sWorkbook = @ScriptDir&"\Temp.xlsx" ; Selekt hvor Exel Fil er gemt Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook, $bReadOnly, $bVisible) ;Local $aResult = _Excel_RangeRead($oWorkbook, Default, "A1:B5", 1) Local $aResult = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns($iColumn), 1) _Excel_Close($oExcel, False, True) ; Does not save any open workbooks and closes the Excel instance _ArrayDisplay($aResult) #comments-start ; Open the file for writing (append to the end of a file) and store the handle to a variable. Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") ; Return False EndIf ;_FileWriteFromArray($sFilePath, $aResult, 0) For $i = 0 To UBound($aResult) - 1 FileWrite($hFileOpen, '' & @CRLF) FileWrite($hFileOpen, '' & @CRLF) FileWrite($hFileOpen, ' ' & @CRLF) FileWrite($hFileOpen, '' & @CRLF) Next #comments-end Send_Data() _Exit() Func Send_Data() TCPStartup() ; Start the TCP service. ; Register OnAutoItExit to be called when the script is closed. OnAutoItExitRegister("OnAutoItExit") ; Assign Local variables the loopback IP Address and the Port. ; Local $sIPAddress = "192.168.0.102" ; 127.0.0.0 This IP Address only works for testing on your own computer. ; Local $iPort = 9100 ; Port used for the connection. Opt("TCPTimeout", 1000) Local $nMaxTimeout = 10 ; script will abort if no server available after 10 secondes Local $iSocket, $iError While 1 ; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified. $iSocket = TCPConnect($iIPAddress, $iPort) ; If an error occurred display the error code and return False. If @error = 10060 Then ; Timeout occurs try again $nMaxTimeout -= 1 If $nMaxTimeout < 0 Then MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not connect, after " & 10 - $nMaxTimeout & " Sec. TimeOut") Return False EndIf ContinueLoop ElseIf @error Then $iError = @error ; The server is probably offline/port is not opened on the server. MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not connect, Error code: " & $iError) Return False Else ; MsgBox($MB_SYSTEMMODAL, "", "Connection successful after " & 10 - $nMaxTimeout & " Sec.") ;_FileWriteFromArray($sFilePath, $aResult, 0) For $i = 0 To UBound($aResult) - 1 TCPSend ( $iSocket, '' & @CRLF) TCPSend ( $iSocket, '' & @CRLF) TCPSend ( $iSocket, ' ' & @CRLF) TCPSend ( $iSocket, '' & @CRLF) Next ; Sleep for 5 seconds. Sleep(1000) ExitLoop EndIf WEnd ; Close the socket. TCPCloseSocket($iSocket) EndFunc ;==>Send_Data ;Func Open_TCP() Func OnAutoItExit() TCPShutdown() ; Close the TCP service. EndFunc ;==>OnAutoItExit Func _Exit() Exit 0 EndFunc #comments-start #include TCPStartUp() Dim $szServerPC = @ComputerName Dim $szIPADDRESS = TCPNameToIP($szServerPC) Dim $nPORT = 85 Dim $ConnectedSocket = -1 $ConnectedSocket = TCPConnect($szIPADDRESS,$nPORT & "/processXML.slap") MsgBox(0,"Test", $szIPADDRESS & ":" & $nPORT) Dim $szData $FileName = FileOpen("C:\request_1.xml",0) $XMLData = FileRead ($FileName) If @error Then MsgBox(4112,"Error","TCPConnect failed with WSA error: " & @error) Else MsgBox(0, "XML Data", $XMLData) TCPSend($ConnectedSocket,$XMLData) Sleep(100) $Response = TCPRecv($ConnectedSocket,1024) MsgBox(0, "XML Response", $Response); EndIf TCPCloseSocket($ConnectedSocket) #comments-end