Announcement

Collapse
No announcement yet.

Daten über Com empfangen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Daten über Com empfangen

    ich hab ein kleines programm welches mir daten von einem Avr per Com empfangen soll
    Das empfangen funktionierte auch, jedoch hab ich probleme, mit dem Splitten des strings
    , bekomme irgendwie immer den Index out of Range,.
    ich zerteile den String mit
    Code:
            
    Dim words As String()
    words = System.Text.RegularExpressions.Regex.Split(test, " ")
    Dim word As String
            tbserialinput.AppendText("Volt: " & words(0) & vbCrLf)
            tbserialinput.AppendText("Prozent: " & words(1) & vbCrLf)
            tbserialinput.AppendText("Ampere: " & words(2) & vbCrLf)
    mein empfangener String sieht so aus
    4.857600209 97 1.234

  • #2
    Das kommt davon dass Du words niemals Deinen gelesen Wert zuweist. Wenn Du dann splittest findet er natürlich keine Vorkommen und das Ergebnis Array hat nur einen Wert. Wenn Du dann auf words[1] zugreifst krachts natürlich

    -> words den gelesenen Wert zuweisen!

    Comment


    • #3
      sorry bin totaler anfänger, beschätige mich erst 2 Tage mit vb.net
      ich dachte
      dim words as string()
      -> definiert words als string-array

      words = test.Split(" ")
      -> splittet test auf, es entstehen teile wie (0)123, (1)0.1234, (2)123
      und diese teile wären dann als words
      ?

      glaube aber das es am enpfangenen Datenstring liegt,
      denn es wird meistens das erste mal richtig gemacht , dann beim 2 empfangenen string, splittet er nicht mehr richtig,.
      Zuletzt editiert von Bonze; 09.12.2010, 11:44.

      Comment


      • #4
        mh es funktionierte jetzt, bekomme aber plötzlich nen
        System.InvalidOperationException wurde nicht behandelt.
        Message=Fehler beim Erstellen des Formulars. Weitere Informationen finden Sie in Exception.InnerException. Fehler: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt..
        Source=Battery Manager
        StackTrace:
        bei WindowsApplication1.My.MyProject.MyForms.Create__I nstance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 190.
        bei WindowsApplication1.My.MyProject.MyForms.get_Form1 ()
        bei WindowsApplication1.My.MyApplication.OnCreateMainF orm() in C:\Dokumente und Einstellungen\Bonze\Eigene Dateien\Visual Studio 2010\Projects\Battery Manager\Battery Manager\My Project\Application.Designer.vb:Zeile 35.
        bei Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
        bei Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
        bei Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[] commandLine)
        bei WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:Zeile 81.
        bei System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
        bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
        bei Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
        bei System.Threading.ThreadHelper.ThreadStart_Context( Object state)
        bei System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
        bei System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
        bei System.Threading.ThreadHelper.ThreadStart()
        InnerException: System.NullReferenceException
        Message=Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
        Source=Battery Manager
        StackTrace:
        bei WindowsApplication1.Form1.Form1_Tray(Object sender, EventArgs e) in C:\Dokumente und Einstellungen\Bonze\Eigene Dateien\Visual Studio 2010\Projects\Battery Manager\Battery Manager\Form1.vb:Zeile 20.
        bei System.Windows.Forms.Control.OnSizeChanged(EventAr gs e)
        bei System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
        bei System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height)
        bei System.Windows.Forms.Control.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
        bei System.Windows.Forms.Form.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
        bei System.Windows.Forms.Control.SetBounds(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
        bei System.Windows.Forms.Control.set_Size(Size value)
        bei System.Windows.Forms.Control.SetClientSizeCore(Int 32 x, Int32 y)
        bei System.Windows.Forms.Form.SetClientSizeCore(Int32 x, Int32 y)
        bei System.Windows.Forms.Control.set_ClientSize(Size value)
        bei System.Windows.Forms.Form.set_ClientSize(Size value)
        bei WindowsApplication1.Form1.InitializeComponent() in C:\Dokumente und Einstellungen\Bonze\Eigene Dateien\Visual Studio 2010\Projects\Battery Manager\Battery Manager\Form1.Designer.vb:Zeile 132.
        bei WindowsApplication1.Form1..ctor() in C:\Dokumente und Einstellungen\Bonze\Eigene Dateien\Visual Studio 2010\Projects\Battery Manager\Battery Manager\Form1.vb:Zeile 8.
        InnerException:


        fehler, wie bekomme ich raus, wo der fehler liegt?
        oder was falsch ist?
        EDIT: meine eingefügten elemente wie serialport, timer, notifiicopn usw, werden garnicht mehr angezeigt, wenn ich jetzt nen serialport einfüge, wird er aber automatich serialport2 genannt,
        Zuletzt editiert von Bonze; 09.12.2010, 21:04.

        Comment


        • #5
          hab wohl von hand da im code was verpfuschd, hab aber alle änderungen rückgängig gemacht, funktioniert aber trotzdem nicht mehr
          Code:
          Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
          Partial Class Form1
              Inherits System.Windows.Forms.Form
          
              'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
              <System.Diagnostics.DebuggerNonUserCode()> _
              Protected Overrides Sub Dispose(ByVal disposing As Boolean)
                  Try
                      If disposing AndAlso components IsNot Nothing Then
                          components.Dispose()
                      End If
                  Finally
                      MyBase.Dispose(disposing)
                  End Try
              End Sub
          
              'Wird vom Windows Form-Designer benötigt.
              Private components As System.ComponentModel.IContainer
          
              'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
              'Das Bearbeiten ist mit dem Windows Form-Designer möglich.  
              'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
              <System.Diagnostics.DebuggerStepThrough()> _
              Private Sub InitializeComponent()
                  Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
                  Me.ctMenueStripÖffnen = New System.Windows.Forms.ToolStripMenuItem()
                  Me.ctMenueStripBeenden = New System.Windows.Forms.ToolStripMenuItem()
                  Me.tbLog = New System.Windows.Forms.TextBox()
                  Me.btSave = New System.Windows.Forms.Button()
                  Me.cbPort = New System.Windows.Forms.ComboBox()
                  Me.cbTime = New System.Windows.Forms.ComboBox()
                  Me.tbserialinput = New System.Windows.Forms.TextBox()
                  Me.btInfo = New System.Windows.Forms.Button()
                  Me.lbbattproz = New System.Windows.Forms.Label()
                  Me.pbBatt = New System.Windows.Forms.PictureBox()
                  CType(Me.pbBatt, System.ComponentModel.ISupportInitialize).BeginInit()
                  Me.SuspendLayout()
                  '
                  'ctMenueStripÖffnen
                  '
                  Me.ctMenueStripÖffnen.Name = "ctMenueStripÖffnen"
                  Me.ctMenueStripÖffnen.Size = New System.Drawing.Size(127, 22)
                  Me.ctMenueStripÖffnen.Text = "Öffnen"
                  '
                  'ctMenueStripBeenden
                  '
                  Me.ctMenueStripBeenden.Name = "ctMenueStripBeenden"
                  Me.ctMenueStripBeenden.Size = New System.Drawing.Size(127, 22)
                  Me.ctMenueStripBeenden.Text = "Beenden"
                  '
                  'tbLog
                  '
                  Me.tbLog.BackColor = System.Drawing.SystemColors.ActiveCaptionText
                  Me.tbLog.Enabled = False
                  Me.tbLog.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
                  Me.tbLog.Location = New System.Drawing.Point(12, 264)
                  Me.tbLog.Multiline = True
                  Me.tbLog.Name = "tbLog"
                  Me.tbLog.ReadOnly = True
                  Me.tbLog.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal
                  Me.tbLog.Size = New System.Drawing.Size(293, 39)
                  Me.tbLog.TabIndex = 1
                  '
                  'btSave
                  '
                  Me.btSave.Location = New System.Drawing.Point(230, 217)
                  Me.btSave.Name = "btSave"
                  Me.btSave.Size = New System.Drawing.Size(75, 23)
                  Me.btSave.TabIndex = 2
                  Me.btSave.Text = "Speichern"
                  Me.btSave.UseVisualStyleBackColor = True
                  '
                  'cbPort
                  '
                  Me.cbPort.FormattingEnabled = True
                  Me.cbPort.Location = New System.Drawing.Point(113, 219)
                  Me.cbPort.Name = "cbPort"
                  Me.cbPort.Size = New System.Drawing.Size(95, 21)
                  Me.cbPort.TabIndex = 3
                  Me.cbPort.Text = "Com Port"
                  '
                  'cbTime
                  '
                  Me.cbTime.FormattingEnabled = True
                  Me.cbTime.Items.AddRange(New Object() {"1000", "2000", "5000", "10000", "600000", "6000000"})
                  Me.cbTime.Location = New System.Drawing.Point(12, 219)
                  Me.cbTime.Name = "cbTime"
                  Me.cbTime.Size = New System.Drawing.Size(95, 21)
                  Me.cbTime.TabIndex = 4
                  Me.cbTime.Text = "Timertime"
                  '
                  'tbserialinput
                  '
                  Me.tbserialinput.Location = New System.Drawing.Point(12, 13)
                  Me.tbserialinput.Multiline = True
                  Me.tbserialinput.Name = "tbserialinput"
                  Me.tbserialinput.Size = New System.Drawing.Size(139, 169)
                  Me.tbserialinput.TabIndex = 6
                  '
                  'btInfo
                  '
                  Me.btInfo.Location = New System.Drawing.Point(230, 188)
                  Me.btInfo.Name = "btInfo"
                  Me.btInfo.Size = New System.Drawing.Size(75, 23)
                  Me.btInfo.TabIndex = 7
                  Me.btInfo.Text = "Info"
                  Me.btInfo.UseVisualStyleBackColor = True
                  '
                  'lbbattproz
                  '
                  Me.lbbattproz.AutoSize = True
                  Me.lbbattproz.Location = New System.Drawing.Point(215, 95)
                  Me.lbbattproz.Name = "lbbattproz"
                  Me.lbbattproz.Size = New System.Drawing.Size(40, 13)
                  Me.lbbattproz.TabIndex = 8
                  Me.lbbattproz.Text = "Load..."
                  '
                  'pbBatt
                  '
                  Me.pbBatt.Image = CType(resources.GetObject("pbBatt.Image"), System.Drawing.Image)
                  Me.pbBatt.Location = New System.Drawing.Point(173, 12)
                  Me.pbBatt.Name = "pbBatt"
                  Me.pbBatt.Size = New System.Drawing.Size(132, 169)
                  Me.pbBatt.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
                  Me.pbBatt.TabIndex = 9
                  Me.pbBatt.TabStop = False
                  '
                  'Form1
                  '
                  Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
                  Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
                  Me.ClientSize = New System.Drawing.Size(317, 315)
                  Me.Controls.Add(Me.lbbattproz)
                  Me.Controls.Add(Me.btInfo)
                  Me.Controls.Add(Me.tbserialinput)
                  Me.Controls.Add(Me.btSave)
                  Me.Controls.Add(Me.cbTime)
                  Me.Controls.Add(Me.tbLog)
                  Me.Controls.Add(Me.cbPort)
                  Me.Controls.Add(Me.pbBatt)
                  Me.Name = "Form1"
                  Me.Text = "Battery Manager"
                  CType(Me.pbBatt, System.ComponentModel.ISupportInitialize).EndInit()
                  Me.ResumeLayout(False)
                  Me.PerformLayout()
          
              End Sub
              Friend WithEvents NotifyIcon1 As System.Windows.Forms.NotifyIcon
              Friend WithEvents SerialPort1 As System.IO.Ports.SerialPort
              Friend WithEvents ContextMenuStrip1 As System.Windows.Forms.ContextMenuStrip
              Friend WithEvents ctMenueStripÖffnen As System.Windows.Forms.ToolStripMenuItem
              Friend WithEvents ctMenueStripBeenden As System.Windows.Forms.ToolStripMenuItem
              Friend WithEvents tbLog As System.Windows.Forms.TextBox
              Friend WithEvents btSave As System.Windows.Forms.Button
              Friend WithEvents cbPort As System.Windows.Forms.ComboBox
              Friend WithEvents cbTime As System.Windows.Forms.ComboBox
              Friend WithEvents Timer1 As System.Windows.Forms.Timer
              Friend WithEvents tbserialinput As System.Windows.Forms.TextBox
              Friend WithEvents btInfo As System.Windows.Forms.Button
              Friend WithEvents lbbattproz As System.Windows.Forms.Label
              Friend WithEvents pbBatt As System.Windows.Forms.PictureBox
          
          End Class

          Comment


          • #6
            sry wenn ich hier zuspamme, konnte es aber auf diese Sub reduzieren aber was soll daran falsch sein ß
            Public Sub Form1_Tray(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
            Select Case Me.WindowState 'derzeitigen Fensterstatus abfragen
            Case FormWindowState.Minimized 'Wenn minimiert
            Me.NotifyIcon1.Visible = True 'Icon sichtbar machen
            Me.ShowInTaskbar = False 'Programm aus Task-Leiste entfernen
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow 'Formrahmen abändern um es in ALT+TAB unsichtbar zu machen
            Case FormWindowState.Normal 'Wenn normal
            Me.NotifyIcon1.Visible = False 'Icon ausblenden
            Me.ShowInTaskbar = True 'In der Task-leiste wieder anzeigen
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle 'Formrahmen abändern um es wieder mit ALT+TAB sichtbar zu machen
            End Select
            End Sub

            Comment


            • #7
              bei WindowsApplication1.Form1.Form1_Tray(Object sender, EventArgs e) in C:\Dokumente und Einstellungen\Bonze\Eigene Dateien\Visual Studio 2010\Projects\Battery Manager\Battery Manager\Form1.vb:Zeile 20.
              bei System.Windows.Forms.Control.OnSizeChanged(EventAr gs e)

              Was passiert den in Form1_Tray? Und warum heißt der EventHandler der scheinbar von OnSizeChanged aufgerufen wird überhaupt Form1_Tray? Das passt zumindest vom Namen her nicht zusammen.


              Edit: Ahh. Problemstelle schon selbst gefunden

              Comment


              • #8
                ja gefunden, aber ich weiss nicht was ich machen muss das es weggeht?,
                bekomme auch nen fehler das ich serialport als neue objektinstanz starten muss
                mit dim serialport as io.ports.serialport() geht der fehler weg,
                jedoch kommt dann an einer anderen stelle ein fehler das serialport schon als widthevent element definiert ist,.
                sehr komisch es ging ja wie ich wollte,.
                dann hab ich irgendwas gemacht und dann ging nichts mehr,.

                Comment


                • #9
                  Jupp, die Zeile zum erzeugen des SerialPort scheinst du aus deinem Designer Code gelöscht zu haben.

                  Ergänze mal

                  Code:
                  Me.SerialPort1 = New System.IO.Ports.SerialPort()
                  wieder in der InitializeComponent() Methode(am Anfang da wo auch die anderen Controls erzeugt werden). Du scheinst noch ein paar Controls mehr gelöscht zu haben. In der Designer.vb sind unten 14 Controls erwähnt. In der InitializeComponent Methode werden aber nur 10 Controls auch erzeugt. Eigentlich solltest du diese 4 nicht erzeugten Controls auch nicht mehr im Winforms Designer auf der Form sehen können. In der InitializeComponent Methode wird aber immer noch auf diese zugegriffen was zu NullReferenceExceptions führen sollte.

                  Comment

                  Working...
                  X