Sign in to follow this  
Followers 0
Ghost21

TCP 2 Serial

2 posts in this topic

#1 ·  Posted (edited)

All I'm doing is setting up a TCP server and passing the Data to the Com Port. The problem is after I pass that data to the com port once it won't accept another connection...

I'm sure its something stupid.. Someone help me out Please...

#include <Constants.au3>

#include <CommMG.au3>

#include <SendMessage.au3>

Const $CMD_TIMEOUT = 500 ; 500 milliseconds

Local $COM = 1, $SuccessFlag, $response, $sErr

Dim $Server_IP = @IPAddress1

Dim $Server_Port = "9100"

Dim $COM = "1"

Dim $BPS = "9600"

Dim $DB = "8"

Dim $Par = "0"

Dim $Stop = "1"

Dim $Flow = "0"

_CommSetPort($COM, $sErr, $BPS, $DB, $Par, $Stop, $Flow) ; This sets up the COM Parameters set above.

TCPStartup() ; Starts the TCP Socket

$SERVER = TCPListen($Server_IP, $Server_Port) ; Begins to listen to the Server IP and Port

While 1

$SOCKET = TCPAccept($SERVER)

Sleep(10)

If $SOCKET >= 0 Then

Call("TCPReceived", $SOCKET)

$SOCKET = ""

EndIf

WEnd

Func TCPReceived($SOCKET)

While 1

$RECV = TCPRecv($SOCKET, 2048)

_CommSendString($RECV, 0)

Sleep(20)

WEnd

$RECV = ""

_CommClearOutputBuffer()

EndFunc ;==>TCPReceived

Edited by Ghost21

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

All I'm doing is setting up a TCP server and passing the Data to the Com Port. The problem is after I pass that data to the com port once it won't accept another connection...

I'm sure its something stupid.. Someone help me out Please...

#include <Constants.au3>

#include <CommMG.au3>

#include <SendMessage.au3>

Const $CMD_TIMEOUT = 500 ; 500 milliseconds

Local $COM = 1, $SuccessFlag, $response, $sErr

Dim $Server_IP = @IPAddress1

Dim $Server_Port = "9100"

Dim $COM = "1"

Dim $BPS = "9600"

Dim $DB = "8"

Dim $Par = "0"

Dim $Stop = "1"

Dim $Flow = "0"

_CommSetPort($COM, $sErr, $BPS, $DB, $Par, $Stop, $Flow) ; This sets up the COM Parameters set above.

TCPStartup() ; Starts the TCP Socket

$SERVER = TCPListen($Server_IP, $Server_Port) ; Begins to listen to the Server IP and Port

While 1

$SOCKET = TCPAccept($SERVER)

Sleep(10)

If $SOCKET >= 0 Then

Call("TCPReceived", $SOCKET)

$SOCKET = ""

EndIf

WEnd

Func TCPReceived($SOCKET)

While 1

$RECV = TCPRecv($SOCKET, 2048)

_CommSendString($RECV, 0)

Sleep(20)

WEnd

$RECV = ""

_CommClearOutputBuffer()

EndFunc ;==>TCPReceived

You have no way to exit the TCPReceived function. Inside the While loop you need to have something like

If $RECV = '' then Return;exitloop

_CommClearOutputBuffer shouldn't be needed.

Be careful that there are no nulls in the data receievd or you will not transmit everything over the serial port since a null indicates the end of a string.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0