Ok.
With this reading in of information am I doing it right.
I am doing the following.
1. Sending 's' to the prop to get it to call the sendDataSerial function.
2. Reading in the Number of schedules as a byte.
3. doing a For Loop to read in the long one byte at a time.
e.g
For i = 0 To NumSchedules(0).ToString - 1
SerialPort1.Read(Data, 0, 4) 'Read in 4 Bytes of information and save to buffer Data which is a Byte array
'Display the data in a textbox
RichTextBox1.Text += Data(0).ToString
RichTextBox1.Text += Data(1).ToString
RichTextBox1.Text += Data(2).ToString
RichTextBox1.Text += Data(3).ToString
RichTextBox1.Text += vbCrLf
Next
4. Display the data as a string.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
VB can only read in bytes.
With the original method is all the data sent as bytes representing the numbers.
How do you change a byte of 1's and 0's into an actual number again.
All I am doing is getting all four bytes and joining them together and displaying them as text.
Will ask on the VB forums anyway and see if I get any useful information.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
For i = 0 To NumSchedules(0).ToString - 1
SerialPort1.Read(Data, 0, 1) 'Read in 1 Bytes of information
'Display the data in a textbox
RichTextBox1.Text += Data1.ToString
SerialPort1.Read(Data, 0, 1)
RichTextBox1.Text += Data.ToString
SerialPort1.Read(Data, 0, 1)
RichTextBox1.Text += Data.ToString
SerialPort1.Read(Data, 0, 1)
RichTextBox1.Text += Data.ToString
RichTextBox1.Text += vbCrLf
Next
Never used a serial port in any of the programming that I've done on a pc and I've never used vb so I really don't know. Maybe see if someone else here can help I think that there are several people here that know vb.
what version of VB.net? I have a dll I wrote in vb.net 2005 that controls the serial port. you setup the port number, speed, etc. and an event fires off anytime data is detected. I'll post it if it would help.
Time 22:22, Day Monday, Code 01
Time 22:22, Day Monday, Code 01
Time 22:22, Day Monday, Code 01
Time 22:22, Day Monday, Code 01
Time 22:22, Day Monday, Code 01
Time 22:22, Day Monday, Code 01
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Thank you, however I am currently using the serial component that comes with Visual Basic 2008 and it works fine with sending.
The only problem is that when receiving the data is getting fragmented and the wrong values are returned.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Hi computer guy, for VB display purposes you can use the DataReceived event of the serial port and capture the characters as they come. First set up a delegate that will actually write to the text box
Public Delegate Sub capture(ByVal sData As String)
·Private Sub Text_Out(ByVal sData As String) ······· RichTextBox1.Text = RichTextBox1.Text & Chr(sData) 'this will write the ASCII code as a character End Sub
then invoke the delegate from within the datareceived event
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
······· Do ············ Dim in_data As String ············ Dim capture_delegate As New capture(AddressOf Text_Out) ············ in_data = SerialPort1.ReadByte ············ RichTextBox1.Invoke(capture_delegate, in_data) ········ Loop Until SerialPort1.BytesToRead < 1·····
End Sub
you will probably have to drop a LF or CR in there somewhere, it should work with your data.
PUB sendDataSerial|i,time,data
data := (NumScheduleItems/10)<<4+NumScheduleItems//10
ser.tx(data)'So that you know how many items there are
i:=1
repeat while i<numScheduleItems
time:=schedule[i]
ser.tx(time.byte[noparse][[/noparse]0])
ser.tx((time.byte/10)<<4+time.byte//10)
ser.tx((time.byte/10)<<4+time.byte//10)
ser.tx(time.byte)
i++
[/i]
This is the original VB code I had and is the way I would like it done.
Try
RichTextBox1.Text = ""
Dim NumSchedules As Byte() = New Byte(1) {}
Dim Data As Byte() = New Byte(1) {}
Dim i As Integer = 0
SerialPort1.Open()
SerialPort1.Write("s")
SerialPort1.Read(NumSchedules, 0, 1)
Label1.Text = NumSchedules(0)
For i = 0 To (NumSchedules(0) - 1)
SerialPort1.Read(Data, 0, 1) 'Read in 1 Bytes of information
RichTextBox1.Text += Data(0).ToString + " "
SerialPort1.Read(Data, 0, 1)
RichTextBox1.Text += Data(0).ToString + " "
SerialPort1.Read(Data, 0, 1)
RichTextBox1.Text += Data(0).ToString + " "
SerialPort1.Read(Data, 0, 1)
RichTextBox1.Text += Data(0).ToString + " "
RichTextBox1.Text += vbCrLf
Next
SerialPort1.Close()
Catch
End Try
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Post Edited (computer guy) : 2/13/2008 8:28:05 PM GMT
Hi computer guy, my mistake, I thought you were sending an ASCII·string from the prop when I saw the ASCII codes for Monday 01( 77·111·110·100·97·121·48·49·) .
So you should be able to display the day with the following modification to the way you want to do it.
RichTextBox1.Text·+=·Chr(Data(0).ToString)·+·"·"
That·should give you·part of your data but not all.
The code you provided didn't help.
It have worked after the modifications I made, however since I don't need that code to get it to work I have left it out.
@Jeff and Steven
The solution was this.
1. Upload the up to date code to the propeller chip.
This includes changing sendDataSerial back to.
data := (NumScheduleItems/10)<<4+NumScheduleItems//10
ser.tx(data)'So that you know how many items there are
i:=0
repeat while i<numScheduleItems
time:=schedule[i]
ser.tx(time.byte[noparse][[/noparse]0])
ser.tx(time.byte)
ser.tx(time.byte)
ser.tx(time.byte)
[/i]
2. Add the following just above the code that receives the data from the buffer.
Data(0 To 3) = 0
System.Threading.Thread.Sleep(100)
This blanks out the Byte Array and then pauses to give the prop time to send the new values (this is what was causing the random values).
3. Change the VB code back to what I had originally.
For i = 0 To (NumSchedules(0) - 1)
Data(0 To 3) = 0
System.Threading.Thread.Sleep(100)
SerialPort1.Read(Data, 0, 4) 'Read in 1 Bytes of information
'Display the data in a textbox
RichTextBox1.Text += Data(0).ToString + " "
RichTextBox1.Text += Data(1).ToString + " "
RichTextBox1.Text += Data(2).ToString + " "
RichTextBox1.Text += Data(3).ToString + " "
RichTextBox1.Text += vbCrLf
Next
Not needed but the code is allot simpler this way.
Like magic... It works.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Post Edited (computer guy) : 2/14/2008 5:43:04 AM GMT
Just a note:
It's good practice to close/flush· (check if not null first) sockets or database connections etc. in a Finally block.
Just declare·them as null·object·above the Try and close·them in the Finally.
This way, if they don't connect or throw an exception, before the method is exited an attempt will be made to close them.
Have fun!
Comments
All is well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
With this reading in of information am I doing it right.
I am doing the following.
1. Sending 's' to the prop to get it to call the sendDataSerial function.
2. Reading in the Number of schedules as a byte.
3. doing a For Loop to read in the long one byte at a time.
e.g
4. Display the data as a string.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
be
Will post the question on a VB forum and see if I get any answers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
With the original method is all the data sent as bytes representing the numbers.
How do you change a byte of 1's and 0's into an actual number again.
All I am doing is getting all four bytes and joining them together and displaying them as text.
Will ask on the VB forums anyway and see if I get any useful information.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
with this
It is consistent though.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Have to go to tafe. Will look forward to your response when I get back at 9:00pm.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Just started tonight.
Goes from 6 to 10.
Longest 4 hours of my life.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
When I was doing my mech eng adv diploma we did some welding but it was only 2 or 3 hours a week and that was enough
Thanks for the advice.
Will keep persevering with this code problem.
I think it is a problem with the conversion from byte to string, could be wrong though.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
When I add more entries I get a pattern.
is what I get with this.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Thank you, however I am currently using the serial component that comes with Visual Basic 2008 and it works fine with sending.
The only problem is that when receiving the data is getting fragmented and the wrong values are returned.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Public Delegate Sub capture(ByVal sData As String)
·Private Sub Text_Out(ByVal sData As String)
······· RichTextBox1.Text = RichTextBox1.Text & Chr(sData) 'this will write the ASCII code as a character
End Sub
then invoke the delegate from within the datareceived event
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
······· Do
············ Dim in_data As String
············ Dim capture_delegate As New capture(AddressOf Text_Out)
············ in_data = SerialPort1.ReadByte
············ RichTextBox1.Invoke(capture_delegate, in_data)
········ Loop Until SerialPort1.BytesToRead < 1·····
End Sub
you will probably have to drop a LF or CR in there somewhere, it should work with your data.
Jeff T.
Your code results in this data.
the code on the prop side is
This is the original VB code I had and is the way I would like it done.
Thank you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Post Edited (computer guy) : 2/13/2008 8:28:05 PM GMT
So you should be able to display the day with the following modification to the way you want to do it.
RichTextBox1.Text·+=·Chr(Data(0).ToString)·+·"·"
That·should give you·part of your data but not all.
Jeff T.
The code you provided didn't help.
It have worked after the modifications I made, however since I don't need that code to get it to work I have left it out.
@Jeff and Steven
The solution was this.
1. Upload the up to date code to the propeller chip.
This includes changing sendDataSerial back to.
2. Add the following just above the code that receives the data from the buffer.
This blanks out the Byte Array and then pauses to give the prop time to send the new values (this is what was causing the random values).
3. Change the VB code back to what I had originally.
Not needed but the code is allot simpler this way.
Like magic... It works.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
Post Edited (computer guy) : 2/14/2008 5:43:04 AM GMT
It's good practice to close/flush· (check if not null first) sockets or database connections etc. in a Finally block.
Just declare·them as null·object·above the Try and close·them in the Finally.
This way, if they don't connect or throw an exception, before the method is exited an attempt will be made to close them.
Have fun!
-Joe
Post Edited (JoMo) : 2/14/2008 5:39:36 AM GMT
Thank you, It is in a "Try Finally" block.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker