Data Sheet

dScript
dScript User Manual v2.15
TCP/IP ports
Both client and server tcp/ip ports are available. A client port initiates communication while a
server port listens for an incoming connection. Both are capable of transmitting and receiving.
TCP/IP server
To operate a tcp/ip server the module will require an IP address and a port number to listen
on. The default IP address is 192.168.0.123 and the default mask is 255.255.255.0. If you
have a DHCP server on your network (most probably your router) then the module will use the
IP address issued by that server. In that case the default IP is not used. However it is more
likely you will want to use a fixed IP of your own choosing. Defining your own IP address
overrides both the default and DHCP addresses. The following code will assign the IP address
and mask:
tcpip.ip "192.168.0.136"
tcpip.mask "255.255.255.0"
The port number is assigned the same way:
tcpip.port 17494
Note that as this is a server, you do not need gateway or DNS addresses. The server never
needs to go out on the network, it just responds to incoming connection requests.
To receive and process incoming messages you will need to set up a thread, define the thread
like this:
thread myThreadName tcpip
for example:
thread TcpipCmds tcpip
The tcpip type informs the compiler that this thread will be triggered when a tcp/ip message
comes in. To receive the incoming message you need to define one integer and one string
variable.
var tcpLength
string tcpBuf[1024]
The thread will be:
TcpipCmds: tcpip.Read(tcpBuf, tcpLength)
. . . . .
<Process Message>
. . . . .
threadsuspend
The read command will read the incoming message into the supplied buffer and report the
length in the supplied var, this is to notify you how many bytes have arrived. You do not need
to check for an incoming message, the thread will start automatically as soon as it arrives.
After you have finished processing the message just suspend the thread, it will start again
from the beginning when a new message arrives.
Copyright © 2016, Devantech Ltd.
All rights reserved.
www.robot-electronics.co.uk
34