无法从Event中访问Chart

时间:2013-12-19 22:16:07

标签: wpf vb.net events

我正在尝试从事件中运行子例程DrawPoint,它什么都不做。我甚至可以从代码中的其他地方调用它,它可以正常工作。

Public Sub DrawPoint(X As Double, Y As Double, Optional SeriesRef As Integer = 0)
    'Draws a point on the graph given X + Y coordinates
    MainForm.Chart.Series.Item(SeriesRef).Points.AddXY(X, Y)
End Sub

从com_DataRecieved事件中运行时,该命令不执行任何操作。我甚至尝试将MainForm.Chart.Series.Item(0).Points.AddXY(X, Y)添加到com_DataRecieved事件本身,它仍然不起作用或错误,或者除了未在图表上显示之外,其他任何错误!这对我来说非常奇怪。 这是com_DataRecieved子例程:

Public Sub com_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles com.DataReceived
    'Handles recieving COM data
    Dim line As String = com.ReadLine 'For storing the read line
    'If the first character is a number then...
    If Asc(line(0)) < 58 And Asc(line(0)) > 47 Then
        'Console.Out.WriteLine("DEBUG: COMDATA: " + line)
        Dim lineSplit As String() = line.Split(",")
        Dim X As Double = Convert.ToInt32(lineSplit(0))
        Dim Y As Double = Convert.ToInt32(lineSplit(1))
        Console.Out.WriteLine("DEBUG: COMPARSEDDATA: " + X.ToString + ";" + Y.ToString)
        DrawPoint(X, Y)
        'MainForm.Chart.Series.Item(0).Points.AddXY(X, Y)
        DrawPoint(13, 5)
    Else
        'Write other lines to console as debug datas
        Console.Out.WriteLine("DEBUG: COMDEBUG: " + line)
    End If
End Sub

如果您想查看项目的任何其他源代码,可以单击(到Github)here

编辑:我添加了一段代码,其中列出了图表上的图表点数到Console,它提供了一些没有意义的奇怪信息。这真的很难解释但是当我真的很快地添加点数(通过COM)时,点数似乎会增加,但它们似乎也从列表中删除了。我曾经有一次我慢慢加点,当加法时间相差约2秒时我有1,1,10,1!正如我之前所说,这让我非常困惑!

0 个答案:

没有答案