Open TCP & UDP - BASIC

The Ewon gateway can publish its tag values through Modbus TCP or SNMP protocols natively.

The Ewon gateway acts as a ModbusTCP / SNMP / OPCUA server in this case.

However, when you must publish the tag values through another protocol, you can use the BASIC script to develop your own client protocol based on TCP or UDP protocols.
Server protocols cannot be developed with BASIC. To do so, refer to Open TCP&UDP JAVA.

This is done through the BASIC function OPEN.

Here is an example:

OPEN "192.168.1.1:23" FOR BINARY OUTPUT AS 1
WaitConnect:
	B$ = GET 1
	IF (B$="#CLOSED#") THEN
		GOTO WaitConnect  
	ENDIF
	
	REM: SEND DATA
	PUT 1,"ECHO"
	t% = GETSYS PRG,"MSEC"
	GOTO WaitForResponse
END

WaitForResponse:
	REM : Wait 100 ms before reading
	s% = GETSYS PRG,"MSEC"
	IF s% > t% + 100 THEN
		A$ = GET 1,100
		PRINT A$
	ELSE
		GOTO WaitForResponse
	ENDIF

	REM: Close Socket
	CLOSE 1
END