AdvancedHMI Software
General Category => Support Questions => Topic started by: joko markono on November 01, 2019, 04:39:11 AM
-
Hi All,
This is not really a AHMI issue but kind of related.
I'm sending out some data from the AHMI out to serial port to third party device:
https://www.manualslib.com/manual/961674/Netmc-Marine-Videotxt.html#manual (https://www.manualslib.com/manual/961674/Netmc-Marine-Videotxt.html#manual)
this is my code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If SerialPort1.IsOpen Then
SerialPort1.Write(BasicLabel1.Text & Space(8) & BasicLabel2.Text & Space(8) & DateAndTime.Now.ToString & vbCrLf & vbNewLine & DateAndTime.Now.ToString & vbCrLf)
End If
End Sub
I just need two line on the output screen that will continuously update but now I got following output:
Data1 Data2 11/1/2019 1:08:25 am
11/1/2019 1:08:25 am
Data1 Data2 11/1/2019 1:08:26 am
11/1/2019 1:08:26 am
Data1 Data2 11/1/2019 1:08:27 am
11/1/2019 1:08:27 am
Data1 Data2 11/1/2019 1:08:28 am
11/1/2019 1:08:28 am
Data1 Data2 11/1/2019 1:08:29 am
11/1/2019 1:08:29 am
So on....
I notice this happen when I added the vbnewline.
I'm not sure what is the trick if there someone could please help.
-
What is the output like if you remove what you added?
-
If i delete vbnewline, output will be on first line only if the character is less than 59 (thats how the setting on the device). If my character more than 59, it will continue on 2nd line and start repeating as my previous post.
i think it has to do with the hex code function as in attachment. Maybe i have to change the vbcrlf with the code?
may i know how can i use that hex code in my code?
-
See if this might help:
https://www.codeproject.com/Questions/236017/Correct-Way-to-write-Hex-Values-to-Serial-port-thi
-
In your code you have DateAndTime.Now.ToString appearing 2 times.
Is that necessary or could it be 1 only:
If SerialPort1.IsOpen Then
SerialPort1.Write(BasicLabel1.Text & Space(8) & BasicLabel2.Text & Space(8) & DateAndTime.Now.ToString & vbCrLf)
End If
-
I manage to stop the data from repeating by using the Hex Code provided in the manual. here is the modified code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
RichTextBox1.Text = Chr(&H13) & "Date :" & DateAndTime.DateString &
Chr(&H13) & Chr(&H14) & "Time :" & DateAndTime.TimeString
If SerialPort1.IsOpen Then
SerialPort1.Write(Chr(&H15) & RichTextBox1.Text)
End If
End Sub
As you can see from the code (I'm not sure what is the correct way), I added the cursor left Chr(&H14) but I get following output:
Date :11-03-2019
xxxxxxxxxxxxxxxxxTime :18:07:53
(xxxx is space)
How should I make the next line start from left?
-
The attached picture shows what I get when I use your code.
Can you use a Notepad and type several lines exactly how you want to them to look before you write each one of them using Serial Port.
-
Well I've done that. Ofcourse on my sending richtextbox, I get the same as you got.
if I don't use the hex code, I got this output on the richtextbox:
Date :11-03-2019
Time :19:40:20
Because I need to use the hex code to display the output on the device, my output on the device screen is as I showed in previous post.
-
If I use this code:
RichTextBox1.Text = Chr(&H13) & "Date :" & DateAndTime.DateString & Environment.NewLine & Chr(&H13) & "Time :" & DateAndTime.TimeString
then I get the output as in the attached picture.
-
Yes I get the same too.
but that is not the case when we see on the device screen.
I've sort out the issue. here is the code:
If SerialPort1.IsOpen Then
SerialPort1.Write(Chr(&H15) & Chr(&H13) & "Date :" & DateString & vbNewLine &
"Time :" & TimeString & vbNewLine &
"Head :" & Space(9 - Strings.Len("Head :")) & BasicLabel1.Text & " deg" & Space(10 - Strings.Len(BasicLabel1.Text + " deg")) &
"Pitch :" & Space(9 - Strings.Len("Pitch :")) & BasicLabel2.Text & " deg" & Space(10 - Strings.Len(BasicLabel2.Text + " deg")) &
"Roll :" & Space(9 - Strings.Len("Roll :")) & BasicLabel3.Text & " deg" & Space(10 - Strings.Len(BasicLabel3.Text + " deg")) &
vbNewLine &
"Pt Bury :" & Space(9 - Strings.Len("Pt Bury :")) & BasicLabel10.Text & " cm" & Space(10 - Strings.Len(BasicLabel10.Text + " cm")) &
"Stb Bury:" & Space(9 - Strings.Len("Stb Bury:")) & BasicLabel9.Text & " cm" & Space(10 - Strings.Len(BasicLabel9.Text + " cm")) &
"Jet Pres:" & Space(9 - Strings.Len("Jet Pres:")) & BasicLabel8.Text & " psi" & Space(10 - Strings.Len(BasicLabel8.Text + " psi")) &
vbNewLine &
"Alt :" & Space(9 - Strings.Len("Alt :")) & BasicLabel4.Text & " mtr" & Space(10 - Strings.Len(BasicLabel4.Text + " mtr")) &
"Depth :" & Space(9 - Strings.Len("Depth :")) & BasicLabel5.Text & " mtr" & Space(10 - Strings.Len(BasicLabel5.Text + " mtr")) &
vbNewLine &
RichTextBox3.Text)
End If
I have to include all the desired output in the If statement. Otherwise it is not well arranged.