% open a tcp-ip socket and connect to the local port 2018
tcpClient = System.Net.Sockets.TcpClient();
address = System.Net.IPAddress.Loopback;
ep = System.Net.IPEndPoint(address, 2018);
tcpClient.Connect(ep);

% send (0...255) to the first cell
for v = 0:1:255
    Send (tcpClient, v,0,0,0,0);
    pause(0.01);
end

% close the connection
if tcpClient.Connected
    tcpClient.Close();
end





function Send(tcpClient, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)

    ns = tcpClient.GetStream();
    ns.WriteByte(3);    % command

    ns.WriteByte(10);   % len of values (low byte)
    ns.WriteByte(0);    % len of values (high byte)

    ns.WriteByte(v0);   % byte 0: Cell 1 
    ns.WriteByte(v1);   % byte 1: Cell 2
    ns.WriteByte(v2);   % byte 2: Cell 3
    ns.WriteByte(v3);   % byte 3: Cell 4
    ns.WriteByte(v4);   % byte 4: Cell 5
    
    ns.WriteByte(v5);   % byte 5: Cell 6 
    ns.WriteByte(v6);   % byte 6: Cell 7
    ns.WriteByte(v7);   % byte 7: Cell 8
    ns.WriteByte(v8);   % byte 8: Cell 9
    ns.WriteByte(v9);   % byte 9: Cell 10

    ns.Flush();   
end



% values of dots (every dot in a cell is a bit in the byte)
% ----------------------------------------------------------------------------
% byte 0          byte 1          byte 2          byte 3          byte 4
% connector 1     connector 2     connector 3     connector 4     connector 5
% ----------------------------------------------------------------------------
%  1 oo 8         1 oo 8          1 oo 8          1 oo 8          1 oo 8
%  2 oo 16        2 oo 16         2 oo 16         2 oo 16         2 oo 16
%  4 oo 32        4 oo 32         4 oo 32         4 oo 32         4 oo 32
% 64 oo 128      64 oo 128       64 oo 128       64 oo 128       64 oo 128
% ----------------------------------------------------------------------------
% 0 = all pins down, 255 = all pins set
% 1+2+4+64    = set left pins
% 8+16+32+128 = set right pins