So, I'm working with the RS232 communication again and started amending my code. The section I'm working with is this:
This wasn't working originally and when communicating to some microcontrollers, I was sending "a" and getting "97" back (which makes sense). Then the next time I sent it an "a", one sends back a "10" (carriage return), which makes sense, and the other one sends a "63" (question mark), which makes no sense. Regardless, I figured it was my programming sending a character and following up with those characters so I added a line to discard the in buffer. It then looked like this:
This seems to work pretty well for the most part but I want to be able to read strings in and get them sent back. It would also be nice to receive the actual characters back, rather than the hex binary values. Any suggestions as to where I can look? I tried using SerialPort1.ReadLine() but because one microcontroller is sending question marks (binary 63) rather than character returns (binary 10), it's just hanging the program.
One possibility I've thought of is it reading the incoming string in character by character until it reaches a 10 or 63 and then I could use the write line. Not sure if that's the best way to do it or even how to go about it just yet but it's an idea. Maybe you guys have some better suggestions.
Any help you guys could give me would be greatly appreciated. Thanks!
Correction: It was showing binary 63, not 67. My bad.
VB.NET:
Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
SerialPort1.WriteLine(TextBox4.Text)
ListBox1.Items.Add("Sent: " + TextBox4.Text)
ListBox1.Items.Add("Received: " & SerialPort1.ReadChar())
End Sub
This wasn't working originally and when communicating to some microcontrollers, I was sending "a" and getting "97" back (which makes sense). Then the next time I sent it an "a", one sends back a "10" (carriage return), which makes sense, and the other one sends a "63" (question mark), which makes no sense. Regardless, I figured it was my programming sending a character and following up with those characters so I added a line to discard the in buffer. It then looked like this:
VB.NET:
Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
SerialPort1.DiscardInBuffer()
SerialPort1.WriteLine(TextBox4.Text)
ListBox1.Items.Add("Sent: " + TextBox4.Text)
ListBox1.Items.Add("Received: " & SerialPort1.ReadChar())
End Sub
This seems to work pretty well for the most part but I want to be able to read strings in and get them sent back. It would also be nice to receive the actual characters back, rather than the hex binary values. Any suggestions as to where I can look? I tried using SerialPort1.ReadLine() but because one microcontroller is sending question marks (binary 63) rather than character returns (binary 10), it's just hanging the program.
One possibility I've thought of is it reading the incoming string in character by character until it reaches a 10 or 63 and then I could use the write line. Not sure if that's the best way to do it or even how to go about it just yet but it's an idea. Maybe you guys have some better suggestions.
Any help you guys could give me would be greatly appreciated. Thanks!
Correction: It was showing binary 63, not 67. My bad.
Last edited: