Gopher2011
Well-known member
Threads - "Conversion from string "" to type 'Double' is not valid."
I have a application that writes and reads from a serial port.
The com-port is opened elsewhere in the early stages of starting / running frm_Main and is not shown.
I have a button1 on my form and when I click it, the module 'RTUValues_Get_IOData' executes perfectly ok, with no errors. No Problems.
The module code that is called is shown below.
However when I call it via a thread [button2], I get the following exception error and it hangs, at the part shown above in RED
"Conversion from string "" to type 'Double' is not valid."
Does anyone have any advice? Thanks in advance.
I have a application that writes and reads from a serial port.
The com-port is opened elsewhere in the early stages of starting / running frm_Main and is not shown.
I have a button1 on my form and when I click it, the module 'RTUValues_Get_IOData' executes perfectly ok, with no errors. No Problems.
VB.NET:
Imports System
Imports System.IO.Ports
Imports System.Threading
Imports System.Threading.Thread
[COLOR="blue"]Public Class frm_Main[/COLOR]
[...inits and vars not shown...]
[COLOR="blue"]Private Sub Button1_Click[/COLOR](ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Debug.WriteLine(" ...Get the Eprom Data - Works fine called from here")
RTUValues_Get_IOData()
[COLOR="blue"]End Sub[/COLOR]
[COLOR="blue"]Private Sub Button2_Click[/COLOR](ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Debug.WriteLine(" ...Get the Eprom Data - Causes an Error")
bgwComms.RunWorkerAsync()
[COLOR="blue"]End Sub[/COLOR]
[COLOR="blue"]Private Sub bgwComms_DoWork[/COLOR](ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwComms.DoWork
RTUValues_Get_IOData()
[COLOR="blue"]End Sub[/COLOR]
[COLOR="blue"]End Class[/COLOR]
The module code that is called is shown below.
VB.NET:
[COLOR="blue"]Module Get_Data[/COLOR]
[...inits and vars not shown...]
[COLOR="blue"]Public Sub RTUValues_Get_IOData[/COLOR]()
If RTU_Write(150, "val") <> 1 Then Debug.WriteLine(" Failed to send")
If RTU_Read(150, vbCr) <> "a" Then Debug.WriteLine(" Failed to relpy")
[COLOR="red"]Temp_Val = RTU_Read(150, ", ")[/COLOR] : frm_Main.txtDataReceived.AppendText(" : ")
[COLOR="blue"]End Sub[/COLOR]
[COLOR="blue"]End Module[/COLOR]
However when I call it via a thread [button2], I get the following exception error and it hangs, at the part shown above in RED
"Conversion from string "" to type 'Double' is not valid."
Does anyone have any advice? Thanks in advance.