This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-03-25 12:36:42

shadowmouse
New Scratcher
Registered: 2013-02-03
Posts: 100+

Remote sensor connections

Is it possible to connect scratch and either visual basic or logicator (a version of VB) with scratch so that they can communicate, and if so how?

Offline

 

#2 2013-03-25 14:47:07

shadowmouse
New Scratcher
Registered: 2013-02-03
Posts: 100+

Re: Remote sensor connections

I just founs something on an old thread:
_________________________________________________________________________________________
Yes got VB.net to listen to scratch. It can also communicate if I bother to get the format right.

Code:

Imports System.Net.Sockets
Imports System.Text
Module Module1
    Sub Main()
        For value As Integer = 0 To 50
            Dim tcpClient As New System.Net.Sockets.TcpClient()
            tcpClient.Connect("127.0.0.1", 42001)
            Dim networkStream As NetworkStream = tcpClient.GetStream()
            If networkStream.CanWrite And networkStream.CanRead Then
                ' Do a simple write.
                Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there")
                'networkStream.Write(sendBytes, 0, sendBytes.Length)
                ' Read the NetworkStream into a byte buffer.
                Dim bytes(tcpClient.ReceiveBufferSize) As Byte
                networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
                ' Output the data received from the host to the console.

                Dim returndata As String = Encoding.ASCII.GetString(bytes)
                Console.WriteLine(("Host returned: " + returndata))
            Else
                If Not networkStream.CanRead Then
                    Console.WriteLine("cannot not write data to this stream")
                    tcpClient.Close()
                Else
                    If Not networkStream.CanWrite Then
                        Console.WriteLine("cannot read data from this stream")
                        tcpClient.Close()
                    End If
                End If
            End If
           
            Threading.Thread.Sleep(4000)
        Next
    End Sub
End Module

And on scratch. Activate mesh
__________________________________________________________________________________________

But I've never used VB before. Say I'm using a pic micros with four LDRs and I've got a scrtach program where one of four lights randomly lights up and you have to put your hand over the corresponding LDR. How would I get it to work?

Offline

 

Board footer