Hi,i,m new with arduino and here i want to read analog input of my arduino to visual basic 2010 with ethernet,but igot an error mesage when i want to see it in label
Here is my arduino code
[#include <SPI.h>
#include <Ethernet.h>
//*************************************************************************************************************************************
// Wired configuration parameters
//*************************************************************************************************************************************
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xD1, 0x4B };
unsigned char local_ip[] = {192,168,1,8}; // IP address of WiShield
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
EthernetServer server(12);
//char buffer[20];
String buffer = "";
void setup()
{
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 sensepin;
if (c == 'O')
{
sensepin=analogRead(A0);
String s=String(sensepin);
Serial.println(s);
}
delay(100);
}
}
}
}
]
and here is my visual studio code
[code][Imports System.Net.Sockets
Imports System.Text
Public Class Form2
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 Arduino_Disconnect()
If Not IsNothing(networkStream) Then
tcpClient.Close()
networkStream = Nothing
End If
End Sub
Private Sub Form2_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Arduino_Connect("192.168.1.8", 12)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Arduino_Write("E")
Dim data As String
Try
data = SerialPort1.ReadLine
Label1.Text = data
Catch ex As Exception
End Try
End Sub
End Class]
in visual studio i got an error in data=serialport1.readline,i know i must must change this code because i use ethernet not serial,but i don't know what code should i change,can anyone help me?
I really appreaciate any help,thanks
[/code]