Thank you everyone for your help and posts. I have finally got it working!! PaulS, thank you for your initial post. I took a better look at my code and compared it closer to a working version of the HTML working code and found that, as you said, I was never reading the client. As for other ways of doing the same thing I am wanting a momentary button so that on my PC I would click a button and while I am holding the mouse button down the light would be on and once I let go the light goes off until I click and hold the button again. I have implemented this using the keyboard but thought it would also be nice to do it in VB code as well using the mouse but haven't figured it out just yet. Also thank you to rbright for the link. I can definitely see some uses for that interface and program in the very near future. My working code is below. It has some extra items in it that I got from another example but I think I can modify it to make what I want.
Arduino Code:
//*************************************************************************************************************************************
// Declarations
//*************************************************************************************************************************************
#include <SPI.h>
#include <Ethernet.h>
//*************************************************************************************************************************************
// Wired configuration parameters
//*************************************************************************************************************************************
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xD1, 0x4B };
unsigned char local_ip[] = {192,168,1,100}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
EthernetServer server(80);
//char buffer[20];
String buffer = "";
void setup()
{
pinMode(8,OUTPUT);
Ethernet.begin(mac, local_ip);
Serial.begin(9600);
}
void loop()
{
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.print(c);
buffer+=c;
int val;
if (c == 'O')
{
digitalWrite(8,HIGH);
}
else if (c == 'F')
{
digitalWrite(8,LOW);
}
}
}
}
}
VB Code:
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Dim tcpClient As New System.Net.Sockets.TcpClient()
Dim networkStream As NetworkStream
Dim KeyPressed As Integer
Private Function Arduino_Connect(ByVal IP As String, ByVal Port As Integer) As Boolean
tcpClient.Connect(IP, Port)
networkStream = tcpClient.GetStream()
If Not networkStream.CanWrite Or Not networkStream.CanRead Then
tcpClient.Close()
networkStream = Nothing
Return False
End If
Return True
End Function
Private Sub Arduino_Write(ByVal Output As String)
If Not IsNothing(networkStream) Then
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(Output)
Dim endByte As [Byte]() = {&HFE}
networkStream.Write(sendBytes, 0, sendBytes.Length)
networkStream.Write(endByte, 0, 1)
Else
MsgBox("ERROR")
End If
End Sub
Private Sub Form1_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Arduino_Connect("192.168.1.100", 80)
picOff.Visible = True
picOn.Visible = False
End Sub
Private Sub Arduino_Disconnect()
If Not IsNothing(networkStream) Then
tcpClient.Close()
networkStream = Nothing
End If
End Sub
Private Sub btnOn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOn.Click
picOff.Visible = False
picOn.Visible = True
Arduino_Write("O")
End Sub
Private Sub btnOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOff.CLick
picOff.Visible = True
picOn.Visible = False
Arduino_Write("F")
End Sub
Private Sub Control_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Control.KeyDown
Select Case KeyPressed
Case 38 ' Up
'Car_Stop()
Case 40 ' Down
' Car_Stop()
Case 39 ' Right
'MsgBox("You pressed Ctrl and Arrowkey Right")
picOff.Visible = False
picOn.Visible = True
Arduino_Write("O")
Case 37 ' Left
' Car_TurnNone()
End Select
KeyPressed = 0
End Sub
Private Sub Control_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Control.KeyUp
KeyPressed = e.KeyCode
Select Case KeyPressed
Case 38 ' Up
'Car_ForwardDrive(Speed.Text)
Case 40 ' Down
'Car_BackwardDrive(Speed.Text)
Case 39 ' Right
picOff.Visible = True
picOn.Visible = False
Arduino_Write("F")
Case 37 ' Left
' Car_TurnLeft()
End Select
End Sub
End Class