Arduino and Visual Basic Interface

Hi everyone, I'm trying to make an interface between Arduino and VB for a project in my actual work.
I want to receive information from a cutting machine that cuts wire.

-Required Information-
*The time the machine is working.
*The time the machine is stop (not working).
*The amount of hits the die makes during the process.
Etc..

I want to display all that information on VB.

I could already do the connections to count both times (Work Time and Time Out) and display them on VB; it works fine.

I also made the connections to count the amount of hits the die makes during the process.
To receive that information, we receive 24V each time die goes down and 0V when the die goes up.
We put a counter on VB, that every time we receive 24V, the program count +1. The program works perfectly, and shows the counting of hits.

But at a certain time, VB gets freeze.. and we need to reconnect Arduino again to the computer so the program works again.. Some times it freezes at 10 minutes, 30 minutes, even an hour, but it always gets freeze at some time. We don't know why.
The Image shows the diagram that we use to receive the 24V to the Arduino:

The negative side of the "Arduino voltage" needs to be connected to the Arduino board's ground.

If you still have problems, it's probably your code.

Pete

Oh yes I forgot to put that in Proteus, but in real life, Yes I just saw my circuit and I have the grounds connected (Arduino Ground and 24V Ground).

ricardo_1994:
Oh yes I forgot to put that in Proteus, but in real life, Yes I just saw my circuit and I have the grounds connected (Arduino Ground and 24V Ground).

But you STILL forgot the code on both sides...

VB Code:
'Abrir puerto serial
Public Sub serial_port()
Try
With SerialPort1
If .IsOpen Then
.Close()
End If
.PortName = "COM10/"
.BaudRate = 9600 '9600
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
'.Parity = IO.Ports.Parity.None
'.DtrEnable = False
'.Handshake = IO.Ports.Handshake.None
'.ReadBufferSize = 2048
'.WriteBufferSize = 1024
'.ReceivedBytesThreshold = 1
'.WriteTimeout = 500
'.Encoding = System.Text.Encoding.Default
.Open() 'ABRIR EL PUERTO SERIAL
Label8.Text = "conectado.."
End With
Catch ex As Exception
MsgBox("Error al abrir el puerto serial" & ex.Message)
End Try
End Sub

Dim golpedadoR As String
Dim golpedadoL As String
Dim old_golpedadoR As String
Dim old_golpedadoL As String = "on"
Dim countgolpesR As Integer
Dim countgolpesL As Integer

'Timer para verificar golpe de dado
Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick
Label33.Text = time_out
If golpedadoR <> old_golpedadoR Then
If golpedadoR = "on" Then
countgolpesR = countgolpesR + 1
End If
End If
old_golpedadoR = golpedadoR
txt_golpes_dado_R.Text = countgolpesR

If golpedadoL <> old_golpedadoL Then
If golpedadoL = "on" Then
countgolpesL = countgolpesL + 1
End If
End If
old_golpedadoL = golpedadoL
txt_golpes_dado_L.Text = countgolpesL
Label32.Text = golpedadoL
End Sub

////////////////////////////////////////////////////////////////////////////////////

Arduino Code:
const int Golpe_Dado_R = 5; //Pin recibe Golpes Dado R
const int Golpe_Dado_L = 3; //Golpes Dado L

int estado_golpe_dado_R; //Recibe el estado del dado R
int estado_golpe_dado_L; //Recibe el estado del dado L

int count_golpes_L=0;

void setup() {
pinMode(Golpe_Dado_R, INPUT); //Recibe 0V o 5V para el conteo de los dados
pinMode(Golpe_Dado_L, INPUT); //Recibe 0V o 5V para el conteo de los dados
Serial.begin(9600);
}

void loop() {
estado_golpe_dado_R = digitalRead(Golpe_Dado_R);
estado_golpe_dado_L = digitalRead(Golpe_Dado_L);

//Condicion Golpe Dado R
if (estado_golpe_dado_R == LOW) {
Serial.println(11, DEC);
digitalWrite(LED_YELLOW, HIGH);
} else {
Serial.println(10, DEC);
digitalWrite(LED_YELLOW, LOW);
}

//Condicion Golpe Dado L
if (estado_golpe_dado_L == LOW) {
Serial.println(13, DEC);
} else {
Serial.println(12, DEC);
}

}//fin de Loop

I don't see anything in the VB code that actually reads from the serial port.

Maybe you can use my visual studio VBA application. I have made some sort of standard scada application for working with an arduino mega. See also my website for more info (and than espec. the HMI part). www.jbsiemonsma.nl.