arduino due e Visual basic express2010 programazione

Ciao mi chiamo Vittorio , ho bisogno di un programma in visualbasic express 2010 che possa comunicare con arduino per un presepe tecnologico, le condizioni del protocollo di comunicazione sono:

1- arduino in via "1" seriale come richiamo di lettura a visual basic
2- visual basic risponde seriale con "1"
3- arduino in via serial il dato da 6 byte
4-arduino risponde serial "1"

da varie prove non riesco a dialogare con arduino nonostante usi la lettura byte per byte in visual basic , non trovo niente nel buffer di lettura.
Dalla parte di arduino non ho problema a ricevere, il problema e con visual basic.

Questo programma mi serve per un presepe tecnologico e deve gestire un quadro elettronico con arduino due : ha 64 uscite a transistor con funzione a massa, arduino dialoga con un microprocessore POLOLU (gestisce la sequenza delle luci), 3 uscite a relè per carichi 220V, 12 uscite a relè per carichi bassa potenza, controlla una scheda audio con 16 canali selezionabili e grazie a una scheda SOMO14D posso selezionare le traccie audio.
Chiedo un aiuto per risolvere questo problema di comunicazione, sono mesi che provo senza venire a capo.

Qualcuno potrebbe indicarmi il modo corretto per dialogare con il protocollo indicato sopra.

Grazie mille per chi mi aiuterà.

tradotto da google:

Hello my name is Victor, I need a program in VisualBasic 2010 Express to communicate with the Arduino for a crib technological conditions of the communication protocol are:

1- arduino being "1" as serial recall reading in visual basic
2- visual basic serial responds with "1"
3- Arduino via serial data from 6 bytes
4-arduino serial responds "1"

various trials I can not talk to Arduino uses despite reading byte by byte in visual basic, I find nothing in the read buffer.
On the arduino I have no problem in receiving, and the problem with visual basic.

This program do I need for a crib and technology must handle an electronic panel with arduino two: has 64 transistor outputs with function grounded, Arduino communicates with a microprocessor Pololu (manages the sequence of lights), 3 relay outputs for 220V loads, 12 relay outputs for low power loads, controls a sound card with 16 selectable channels and thanks to a card SOMO14D can select audio tracks.
I ask for help to solve this problem of communication, are months that I try not to get on top.

Someone could tell me the proper way to communicate with the protocol described above.

Thank you so much for those who will help me.

Perhaps you could use google postMyCode, to POST YOUR CODE!

Questo è il codice in visual basic express 2010 utilizzato:

Imports System
Imports System.Threading
Imports System.IO.Ports

Public Class Form1

Public iSerialReceived As Integer

Function SerialReceive() As Integer
On Error GoTo ErrHandler

Do While SerialPort1.BytesToRead > 0

iSerialReceived = SerialPort1.ReadByte()

Loop

ErrHandler:
RichTextBox1.Text = "Errore comunicazione"
End Function
Dim dati(6) As Integer

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

SerialReceive()

If iSerialReceived = 49 Then
SerialPort1.Write("1")
For index As Integer = 0 To 6
SerialReceive()
dati(index) = iSerialReceived
RichTextBox1.Text = Chr(dati(index))
Next
SerialPort1.Write("1")
End If
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
SerialPort1.Open()
Timer1.Enabled = SerialPort1.IsOpen
RichTextBox1.Text = "porta aperta"

End Sub
End Class

condizioni:
Arduino comunica a visual che è pronto per la comunicazione codice 49 (char "1")
Visual risponde OK con il codice 49(char "1")
Arduino invia 6 byte
Dopo aver ricevuto i 6 byte visual invia codice 49 (char "1") come risposta ricevuti ad Arduino

conditions :
Arduino communicates a visual that is ready for communication code 49 (char " 1 " )
Visual responds OK with code 49 (char " 1 " )
Arduino sends 6 bytes
After receiving the 6 byte send visual code 49 (char " 1 " ) as a response received to Arduino

To know the crib that realizable in google " presepe di Terrarossa Colombo "

Serial data arrival triggers an event handler. Implementing that event handler, instead of using a timer to look for data, makes far more sense to me.

Ciao Victor,

See this: http://msdn.microsoft.com/it-it/library/system.io.ports.serialport_events(v=vs.110).aspx

This is the English part of the site, please post in English only.

Thanks , Pauls and guix , try this method , good year in 2015 !

Hello , did some tests with the following code of VisualBasic , but using a Form for reading serial data presents compilation errors :

Error 1 Can not refer to an instance member of a class within a shared method or shared member initializer without an explicit instance of the class. C : \ Documents and Settings \ vittorio \ Documents \ Visual Studio 2010 \ Projects \ arduino two test \ test two arduino \ Form2.vb 27 9 test two arduino

Are a staple , I know little Visualbasic is a crib to do , if I inpostate a form of reading the serial would be very grateful , thank you.

Public Class Form2
Public Event DataReceived As SerialDataReceivedEventHandler
Public Shared Sub Main()
Dim mySerialPort As New SerialPort(“COM10”)

mySerialPort.BaudRate = 115200
mySerialPort.Parity = Parity.None
mySerialPort.StopBits = StopBits.One
mySerialPort.DataBits = 8
mySerialPort.Handshake = Handshake.None

AddHandler mySerialPort.DataReceived, AddressOf DataReceivedHandler

mySerialPort.Open()

End Sub

Private Shared Sub DataReceivedHandler(sender As Object, e As SerialDataReceivedEventArgs)
Dim sp As SerialPort = CType(sender, SerialPort)
Dim indata As String = sp.ReadExisting()
Label1.Text = “Data Received:”
Label1.Text = indata
End Sub

End Class

Label1 this error

Sorry but this is arduino forum, not a VB forum :slight_smile:

The first result of googling this error message is: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class - Visual Basic | Microsoft Docs

And I recommend using C# instead of this weird VB language...

hello , nothing resolved, I tried and tried for several months without ottnere a result , there is no way to use arduino with vb2010 decently.
The last code used is :
Public Shared InputSeriale(7) As Integer

Private Sub SerialPort1_LetturaSeriale()
Do
If SerialPort1.BytesToRead > 0 Then
InputSeriale(0) = SerialPort1.ReadChar

If InputSeriale(0) = 120 Then ' 120 = "x" 1° byte
For indexin As Integer = 1 To 6 Step 1
MyDelayMacro(9999)
SerialPort1.Write("y")
MyDelayMacro(9999)
Do
If SerialPort1.BytesToRead > 0 Then
InputSeriale(indexin) = SerialPort1.ReadChar ' 2 to 7 byte
Else
Exit Do
End If
Loop
Next indexin
End If

Else
Exit Do

End If
Loop
End Sub

VB question arises " X0000 " in the serial , arduino responds with " x " 1 byte , VB answers " y " , Arduino responds with the 2nd byte , VB answers " y " , Arduino responds with the 3rd byte , VB responds " y " , Arduino meets 4th byte , VB answers" y " , Arduino responds 5th byte , VB answers" y " , Arduino responds 6th byte , VB risbonde " y " , Arduino responds 7th byte , read- closed cycle .

If I proceed step by step works, but I get by run data received random numbers . The program completes the read cycle .
What's up? I do not understand where is the problem , in a way it works but normally no !. Compel in cycles .... Do Loop for reading that does not fail .
In fact, no other law but fails ! >:(
Help me with Arduino I have no problems , on various forums VB use functions that have not been able to make them work , and among other things does not always guarantee the sucess of reading MS.NET indicates .
Possible that none of the forum has used VB for control panel and visualization ?
I need to update variables in real time without updating all the time to rewrite the code .
With a crib you have to set thresholds of time depending on the realization is a matter of practicality .
Thank You