hi All,
I’ve written a custom VB.net app to log temperature and status data from heating system via my Arduino Duemilanove however the majority of the time when I open the serial port in the app the Arduino freezes up. If I hit the reset button on the Arduino it comes back up fine and the program starts logging data as it should but this isn’t feasible as a long term solution.
Here is the relevant code from my VB.net program:
Imports System
Imports System.IO.Ports
Imports System.Timers
Imports System.Data.OleDb
Imports System.Data.Common
Imports System.Data
Module Module1
Dim message As String
Dim readthread As Threading.Thread = New Threading.Thread(AddressOf read)
Sub Main()
'AddHandler mytimer.Elapsed, AddressOf dataInsertTest
readthread.Start()
Console.WriteLine("Press the Enter key to exit the program.")
Console.ReadLine()
End Sub
Sub read()
Dim mySerial As SerialPort
Dim I As Integer = 0
mySerial = New SerialPort
mySerial.PortName = "COM3"
mySerial.BaudRate = "9600"
mySerial.Parity = Parity.None
mySerial.DataBits = 8
mySerial.StopBits = StopBits.One
mySerial.Encoding = System.Text.Encoding.ASCII
mySerial.NewLine = Chr(13) + Chr(10)
mySerial.ReadTimeout = 30000
'MsgBox(mySerial.PortName)
mySerial.Open()
Try
Console.Write(mySerial.ReadLine())
Catch ex As Exception
Console.Write(ex.Message)
End Try
System.Threading.Thread.Sleep(60000)
While (1 < 2)
Try
message = mySerial.ReadLine()
If message <> "" Then
Console.WriteLine(CStr(Now) + Chr(9) + CStr(message))
dataInsertSamples(message)
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
System.Threading.Thread.Sleep(60000)
End While
mySerial.Close()
mySerial.Dispose()
End Sub
Does anyone have any idea why this might be causing the Arduino to freeze? I can use the Arduino serial monitor or a terminal program and it doesn’t cause any problem with the device.
thanks for any help.