Hi,
I wrote a Programm that gets data from a scale via SerialPort.
That works fine - but I don´t know wher to format the Data.
I get fore example the Data
If I would like to format in the Delegate-Part I olways get Errors because the lengh of the String is wrong. And I think I must say, if it starts with S S.
My try you can see is as comment.
Can anyone tell me how to format the incoming Data? - On witch event?
I think when I make a TextBox changed Event I will get a loop.
How can I chek if receive of Data is compleate?
Your´s
Stefan
[/COLOR][/FONT][/SIZE][/COLOR][/FONT][/COLOR][/FONT]
I wrote a Programm that gets data from a scale via SerialPort.
That works fine - but I don´t know wher to format the Data.
I get fore example the Data
I would like that the Text-Box only displays 135,4 gS S 135.4 g <Return>.
If I would like to format in the Delegate-Part I olways get Errors because the lengh of the String is wrong. And I think I must say, if it starts with S S.
My try you can see is as comment.
Can anyone tell me how to format the incoming Data? - On witch event?
I think when I make a TextBox changed Event I will get a loop.
How can I chek if receive of Data is compleate?
Your´s
Stefan
VB.NET:
[FONT=Arial][SIZE=2][COLOR=black]Private Sub cmd_wiegen_uebernehmen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_wiegen_uebernehmen.Click[/COLOR][/SIZE][/FONT]
[FONT=Arial][COLOR=black][SIZE=2][FONT=Arial][COLOR=black][FONT=Arial][COLOR=black]' Anzeigefeld leeren[/COLOR][/FONT][/COLOR][/FONT][/SIZE]
[FONT=Arial][COLOR=black][SIZE=2][FONT=Arial][COLOR=black]TextBox_Waagendisplay.Text = Nothing[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]ToolStripStatusLabel_Gewicht.Text = Nothing[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]' Befehl an Schnittstelle / Gerät senden[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]If ComboBox_Waagen_Modell.SelectedItem = "MODEM" Then[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]Serielle_Schnittstelle.WriteLine("ATI3" & (Chr(13)))[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]End If[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]If ComboBox_Waagen_Modell.SelectedItem = "Mettler-Toledo" Then[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]Serielle_Schnittstelle.WriteLine("S" & (Chr(13)))[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]End If[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]End Sub[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]===========================================================================================[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]Private Sub Serielle_Schnittstelle_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Serielle_Schnittstelle.DataReceived[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]Try[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]TextBox_Waagendisplay.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]Catch ex As Exception[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Fehler aufgetreten... ...Gerät / Port richtig eingestellt?")[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]Exit Sub[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]End Try[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]End Sub[/COLOR][/FONT][/SIZE][/COLOR][/FONT][/COLOR][/FONT]
[FONT=Arial][SIZE=2][COLOR=black]============================================================================================[/COLOR][/SIZE][/FONT]
[FONT=Arial][COLOR=black][SIZE=2][FONT=Arial][COLOR=black][FONT=Arial][COLOR=black]Public Delegate Sub myDelegate()[/COLOR][/FONT][/COLOR][/FONT][/SIZE]
[FONT=Arial][COLOR=black][SIZE=2][FONT=Arial][COLOR=black]Public Sub updateTextBox()[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]With TextBox_Waagendisplay[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black].Font = New Font("Microsoft Sans Serif", 16.0!, FontStyle.Bold)[/COLOR][/FONT][/SIZE]
[SIZE=2][B][FONT=Arial][COLOR=black][B]'If ComboBox_Waagen_Modell.SelectedItem = "Mettler-Toledo" Then[/B][/COLOR][/FONT][/B][/SIZE]
[B][B][SIZE=2][FONT=Arial][COLOR=black]'.AppendText(Serielle_Schnittstelle.ReadExisting.Substring(3, 11)) ' hier splitten[/COLOR][/FONT][/SIZE][/B]
[B][SIZE=2][FONT=Arial][COLOR=black]'Else[/COLOR][/FONT][/SIZE][/B]
[B][SIZE=2][FONT=Arial][COLOR=black].AppendText(Serielle_Schnittstelle.ReadExisting)[/COLOR][/FONT][/SIZE][/B]
[B][SIZE=2][FONT=Arial][COLOR=black]'End If[/COLOR][/FONT][/SIZE][/B]
[/B]
[SIZE=2][FONT=Arial][COLOR=black].ScrollToCaret()[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]End With[/COLOR][/FONT][/SIZE]
[SIZE=2][FONT=Arial][COLOR=black]' Daten / Anzeige im Waagendisplay in die Zwischenablage kopieren[/COLOR][/FONT][/SIZE]
[SIZE=2][B][FONT=Arial][COLOR=black][B]Dim Uebergabewert_PA As String = TextBox_Waagendisplay.Text.Substring(0, (TextBox_Waagendisplay.Text.Length) - (2))[/B][/COLOR][/FONT][/B][/SIZE]
[B][B][SIZE=2][FONT=Arial][COLOR=black]Clipboard.SetDataObject(Uebergabewert_PA, True)[/COLOR][/FONT][/SIZE][/B]
[B][SIZE=2][FONT=Arial][COLOR=black]'Gewicht nochmal in Statusleiste anzeigen[/COLOR][/FONT][/SIZE][/B]
[B][SIZE=2][FONT=Arial][COLOR=black]ToolStripStatusLabel_Gewicht.Text = TextBox_Waagendisplay.Text[/COLOR][/FONT][/SIZE][/B]
[/B]
[SIZE=2][FONT=Arial][COLOR=black]End Sub
Last edited by a moderator: