Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending data through an RS232 port

Status
Not open for further replies.

dpdoug

Programmer
Nov 27, 2002
455
US
I have some code I downloaded written in VB.NET that was written to send data throught the Serial Port (RS232). I have been experimenting with it and it does send data -- 2 characters at a time, no matter how many characters I try to send all at once in a string. So I assume that it can only send so many bits at a time and then clear the buffer before sending more.

That's what it appears to be -- correct me if I'm wrong.

With that assumption, I simply write to the port one character at a time looping through the string until I get to the end then close the port.

This works fine while I'm in debug mode with a break point at the Next statement, and pressing the F5 button once every time it goes through the loop.

But when I let it run by itself, it skips over characters and truncates the last part of the string.

It seems as though the computer just goes too fast for the port, so I have to somehow slow the loop down so that it will give the port a chance to handle the flow of data through it.

Is there any way to make the loop run slower?

Am I even on the right track? Is my assmption right about the number of bits that can be sent at one time?

I've tried different settings such as baud rate, but the default speed of 9,600 is the only one that will work.


Here's the code where I loop through the string and send it character by character:

Code:
(open comm port)

str = "this is a test" & Chr(9) & "Start Date" & Chr(9) & Chr(9) & _ "Location" & Chr(9) & "End Date"

lngth = str.Length - 1

For i = 0 To lngth
	moRS232.PurgeBuffer(Rs232.PurgeBuffers.TxClear Or _ Rs232.PurgeBuffers.RXClear)
	ch = str.Substring(i, 1)
	moRS232.Write(ch)
Next i

(close comm port)



 
Hey Doug,

Did you manage to get your problem sorted out. Did you use any of the code that Chris pointed you to. I am about to start working on a web based application that will need to be able to communicate with an electronic balance through an RS232 port. It will need to be able to read and write to the port.

Can you give me any pointers?

Mighty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top