Shop OBEX P1 Docs P2 Docs Learn Events
From a PC application to Spinneret — Parallax Forums

From a PC application to Spinneret

BEEPBEEP Posts: 58
edited 2012-11-07 14:20 in Accessories
I finally had time to unpack my Spinneret and succeeded
with "Spinneret_Web_Server_DEMO v1.0.spin" to turn
on and off some leds.

What I want to do now is to read and write to Propeller
memory from an application on the PC so I need some
guidance on which network protocols(or whatever it is
called) and Spinneret objects as needed.

/Paul

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-11-05 14:24
    On the PC it's called socket programming. Create a socket request (IP : PORT), send data, and wait for a response. On the Spinneret side, listen for a a socket request, read the data into memory, do something with the data, send a response to the caller. The UPD or TCP protocol is used to send/receive the data.

    This tutorial might help a bit
    http://spinneret.servebeer.com:5000/
  • BEEPBEEP Posts: 58
    edited 2012-11-05 15:42
    I'm going to research about the keywords you gave me and read the tutorial properly, step by step and hopefully I will be a little wiser.
  • Mike GMike G Posts: 2,702
    edited 2012-11-05 18:05
    Let me know if you get stuck.
  • BEEPBEEP Posts: 58
    edited 2012-11-07 14:20
    It was easier than I first thought to send and receive messages from Spinneret.

    attachment.php?attachmentid=96757&d=1352325159


    Delphi 6
    Drag and drop a ClientSocket component on Form.
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      ClientSocket1.Port := 5555;
      ClientSocket1.Host := '192.168.1.120';
    end;
    
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      ClientSocket1.Active := false;
    end;
    
    procedure TForm1.ClientSocket1Read(Sender: TObject;
      Socket: TCustomWinSocket);
    begin
      Memo1.Lines.Add('Rec  '+TimeToStr(Time)+':   '+Socket.ReceiveText);
      Memo1.Lines.Add('Elapsed time:      '+IntToStr(GetTickCount-startTime)+' ms');
      Memo1.Lines.Add('');
    end;
    
    procedure TForm1.BtnSendClick(Sender: TObject);
    begin
      ClientSocket1.Active := true;
    
      //- Temporary fix -
      Sleep(50);
      Application.ProcessMessages;
      Sleep(50);
      Application.ProcessMessages;
    
      if ClientSocket1.Active then
      begin
        startTime := GetTickCount;
        ClientSocket1.Socket.SendText(EditMsg.Text);
        Memo1.Lines.Add('Send '+TimeToStr(Time)+':   '+EditMsg.Text);
      end
      else
      begin
        Memo1.Lines.Add('ClientSocket1.Active = false');
        Memo1.Lines.Add('');
      end;
    end;
    


    Propeller Tool
    Spinneret_Web_Server_DEMO v1.0.spin
    PUB Main | packetSize
      '- Infinite loop of the server ; listen on the TCP socket - 
      repeat                                                          
        repeat while !W5100.SocketTCPestablished(0)            
    
        '- Initialize the buffers and bring the data over -
        bytefill(@data, 0, bytebuffersize)    
        repeat
          packetSize := W5100.rxTCP(0, @data)
        while packetSize == 0 
    
        '- Terminal -
        pst.Str(string("Packet from browser:", PST#NL))
        pst.Str(@data[0])
        pst.Char(13)  
    
        '--- Parse Data Packet for ... ---
        
    
        '--- Generate HTML data to send ---
        StringSend(0, string("Ok"))  
                      
        '- We don't support persistent connections, so disconnect here -     
        W5100.SocketTCPdisconnect(0)
        PauseMSec(25)
        
        '- Connection terminated -
        W5100.SocketClose(0)
    
        '- Once the connection is closed, need to open socket again -
        OpenSocketAgain(0)
    
Sign In or Register to comment.