Logo Banner

Velleman K8000 - [K8000 Standalone Usage] - [K8000 Wireless Server]

K8000 Server Protocol

Designing the protocol

This page gives some information about the design of the K8000 server protocol. You don't need to know all these details if you are just going to work with my predefined software classes. In this case you can skip to the next page.

The K8000 protocol defines how the communication between server and client should look like. Designing a protocol can be fun because you can design it any way you like. The image below shows the resulting protocol in action:

the server protocol in action

Netwerk protocol: TCP/IP

I have chosen to build my K8000 server as a TCP/IP server. This is the most obvious protocol to use for a server. We could also use the UDP protocol but this is a connectionless protocol. You are never sure if the transmitted data is received at the other side.

Our server will constantly for incoming TCP/IP connection requests from external clients. Our server is listening to a certain TCP/IP port for this. In my sample solution I will use TCP/IP port 23. In the case all server connections are in use, the new incoming connection is ignored.

Transmission data format

Data is transmitted between the server and client. The transmitted data is send as plain text. I defined two major rules that should be followed:

  1. All commands must be transmitted as text strings with an UTF-8 encoding. (this is an encoding method for text characters).
  2. Each command is terminated by an Enter-character (carriage-return character + linefeed character).

Server Responses

The server is only allowed to send responses when the client requested this: it may not send responses on its own initiative. A response should also only have one line of text.

Each server response must be preceded by either +OK or +ERR. Optionally it can be followed by some additional information. There must be a space between the +OK/+ERR and this additional information.

Initial Server Response

The server should give an initial response when a new client connects to it. This response must be this:

      +OK Fez-to-K8000 TCP server
    

The client should analyze this client to verify if it is really connected to the K8000 server. The client should drop the connection immediately if the server response fails.

Server login

The client should login right after the initial server response. This is done with the PASS command. The default server's password is bart!. This password has to be entered within 5 seconds after the initial server response. Otherwise the server will disconnect the client.

      +OK Fez-to-K8000 TCP server
      pass bart!
      +OK Welcome to the K8000 TCP/IP server!
    

The server won't accept any commands before the password is transmitted. In this case it will just respond with the error message: +ERR Please login first!

Configuring K8000 Digital Channels

The K8000 needs to be initialized when it is first accessed. You have to tell it which channels inputs and which channels are outputs. This can be done by calling the IOCONFIG command, followed by 16 bits (1/0). They allow you to set of a channel is an input (0) or an output (1).

      IOCONFIG 0000000011111111
      +OK
		

Calling the IOCONFIG command will clear the state of all I/O channels. It should be only executed one time when the server is running. I introduced the INIT command to keep track of this: INIT allows you to specify if the IOCONFIG is already executed. Its usage:

      IOCONFIG 0000000011111111
      +OK
      INIT 1
      +OK 1
		

The INIT command can have two values: 0 (not initialized) or 1 (initialized). So the sample above specifies the initialisation is done. Each client can request the state of the initialisation by sending INIT 2:

      INIT 2
      +OK 1
    

K8000 Digital Channels

These commands are supported to control the I/O channels:

You need to replace [channel] by a channel number between 1 and 16. The server will immediately process the command after receiving it. It always answers with an +OK, followed by a series of 16 bits. They contain the current state of the I/O channels. In the example below the I/O channel 16 is active:

    	+OK 0000000000000001
    

K8000 Analog Channels

These commands are supported to control the analog channnels:

You need to replace [channel] by the channel number. You need to replace [value] by the desired output value: 0-63 for the DAC channels, 0-255 for the DAC channels.

GETAD and GETALLAD are used to read the value of the A/D channels. The following example is showing the outputs of the GETALLAD and the GETAD commands:

      GETALLAD
      +OK 179 0 0 0
			
      GETAD 1
      +OK 179		
    

Other commands

For now the K8000 server supports one extra command to disconnect the client from the server:


Copyright ©1998-2022 Vanderhaegen Bart - last modified: August 24, 2013