-
Nov 29th, 2017, 06:26 AM
#1
Thread Starter
New Member
unreliable serial port comunications
Im trying to send some information over a serial port to an ardiuno , I had the whole porbgram working perfectly but now it only works some times. I beleive the problem lies in the following code
SerialPort1.Write("w")
SerialPort1.Write(textbox1.Text)
SerialPort1.Write("\n")
Is this an acceptable way to write to serial , it seems to work but only sometimes, If i send the same nubers to the arduino with a serial monitor is responds as expected so it must be the way it is set here.
Is there any other possibilities
-
Nov 29th, 2017, 09:31 AM
#2
Re: unreliable serial port comunications
Don't see a problem with the code. You might consider constructing the string and using WriteLine, like this
Code:
Dim s As String = "w" & TextBox1.Text
SerialPort1.WriteLine(s)
-
Nov 29th, 2017, 09:41 AM
#3
Thread Starter
New Member
Re: unreliable serial port comunications
If I add a 500 ms delay using a while loop after the serial writes it seems to work. but this doesn't seem like a real solution and like it might have issues later.
-
Nov 30th, 2017, 09:36 AM
#4
Re: unreliable serial port comunications
Originally Posted by simon100
If I add a 500 ms delay using a while loop after the serial writes it seems to work. but this doesn't seem like a real solution and like it might have issues later.
Make certain that you have the same setup at both ends of the port. This could be an issue with the Ardiuno end.
After you do the write are you closing the port? Are you using flow control?
-
Nov 30th, 2017, 10:13 AM
#5
Addicted Member
Re: unreliable serial port comunications
A serial port has a max baud rate and if i rember rite from my schooling, its a one way street... in the sence only one can speak on the line. So if you send something while the other is responding to you first message, the messages will all be lost.
So i think it's a good idea to wait a little while after sending you second message. 500 ms feels a bit long , but none the less 100 ms or so seems to me to be normal....
on the otherhand i might be talking rubbish.... seeing my scholing is a little while behind me...
Utterly useless, but always willing to help
As a finishing touch god created the dutch
-
Nov 30th, 2017, 01:43 PM
#6
Re: unreliable serial port comunications
I would be surprised if you should be doing
SerialPort1.Write("\n")
I would have though it should be along the lines of
SerialPort1.Write(vbLf)
I admit I didn't test to see if the Write function in .Net excepts C-style escape sequences, but I'm pretty sure it wasn't something you could do in earlier versions of VB.
-
Nov 30th, 2017, 05:18 PM
#7
Thread Starter
New Member
Re: unreliable serial port comunications
Originally Posted by dbasnett
Make certain that you have the same setup at both ends of the port. This could be an issue with the Ardiuno end.
After you do the write are you closing the port? Are you using flow control?
I'm not closing the port is this required ? and am not using any flow control, i was not aware of flow control i searched and from what i understand it is one end confirming it has finished receiving before the other transmits again ?
-
Nov 30th, 2017, 05:59 PM
#8
Thread Starter
New Member
Re: unreliable serial port comunications
Originally Posted by Goggy
A serial port has a max baud rate and if i rember rite from my schooling, its a one way street... in the sence only one can speak on the line. So if you send something while the other is responding to you first message, the messages will all be lost.
So i think it's a good idea to wait a little while after sending you second message. 500 ms feels a bit long , but none the less 100 ms or so seems to me to be normal....
on the otherhand i might be talking rubbish.... seeing my scholing is a little while behind me...
i think the usb connection is a differential pair set up so only one could talk at a time but i was under the impression the usb controller at each end handled this . im only running at 9600 baud but even at that there should be heaps of time for what is happening.
To be a bit more specific the arduino ( actually a teensy lc) sends a message every 100ms thats about 5 characters long , when the synch button is clicked in the vb program it then sends the message pictured at the top of the thread 5 times with different details. Its looking like i need to do some learning about usb vs the serial i would use between 2 arduino
-
Dec 1st, 2017, 09:17 AM
#9
Re: unreliable serial port comunications
Originally Posted by simon100
i think the usb connection is a differential pair set up so only one could talk at a time but i was under the impression the usb controller at each end handled this . im only running at 9600 baud but even at that there should be heaps of time for what is happening.
To be a bit more specific the arduino ( actually a teensy lc) sends a message every 100ms thats about 5 characters long , when the synch button is clicked in the vb program it then sends the message pictured at the top of the thread 5 times with different details. Its looking like i need to do some learning about usb vs the serial i would use between 2 arduino
There should not be an issue with simultaneous send / receive (full duplex) communication at a physical level. That does not mean that the application software is written to do that. Based on what you have described it shouldn't be an issue.
-
Dec 1st, 2017, 05:15 PM
#10
Re: unreliable serial port comunications
Did you try changing your line termination method?
Either use vbLf instead of ("/n") or use WriteLine for the last substring (or combine the substrings like dbasnett suggested in post #2).
Code:
SerialPort1.Write("w")
SerialPort1.Write(TextBox2.Text)
SerialPort1.Write(vbLf)
'---Or---
SerialPort1.Write("w")
SerialPort1.WriteLine(TextBox2.Text)
'---Or---
Dim s As String
s = "w" & TextBox1.Text
SerialPort1.WriteLine(s)
s = "w" & TextBox2.Text
SerialPort1.WriteLine(s)
'etc...
I did verify that SerialWrite does not convert "/n" into a linefeed character, so at least that is one known thing that is wrong with your intentions.
Last edited by passel; Dec 1st, 2017 at 05:20 PM.
-
Dec 7th, 2017, 07:03 PM
#11
Thread Starter
New Member
Re: unreliable serial port comunications
Originally Posted by passel
Did you try changing your line termination method?
Either use vbLf instead of ("/n") or use WriteLine for the last substring (or combine the substrings like dbasnett suggested in post #2).
Code:
SerialPort1.Write("w")
SerialPort1.Write(TextBox2.Text)
SerialPort1.Write(vbLf)
'---Or---
SerialPort1.Write("w")
SerialPort1.WriteLine(TextBox2.Text)
'---Or---
Dim s As String
s = "w" & TextBox1.Text
SerialPort1.WriteLine(s)
s = "w" & TextBox2.Text
SerialPort1.WriteLine(s)
'etc...
I did verify that SerialWrite does not convert "/n" into a linefeed character, so at least that is one known thing that is wrong with your intentions.
ok thanks I will try and change that but it makes me wonder how it is working at all
-
Dec 7th, 2017, 07:30 PM
#12
Thread Starter
New Member
Re: unreliable serial port comunications
I tried vblf and it seems to work perfect now thanks for the solution, on the arduino end i was using "Serial.readStringUntil('\n');" to get the message but there was also a time out on this so i asume it was actually the time out that was making it all work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|