|
-
Jun 9th, 2009, 11:56 PM
#1
Thread Starter
New Member
Using Serial Port to Read String
Dear All,
I have an application in Electronics to communicate with serial port. With using VB I have succesfully read a character using
Code:
Serialport1.ReadByte
or
Code:
Serialport1.ReadChar
. Does anybody know how to read a whole string directly?
Regards,
Elektronika
-
Jun 10th, 2009, 12:00 AM
#2
Re: Using Serial Port to Read String
What other members does the SerialPort class have? I can see three other methods that all start with "Read". Have you read the documentation for those to see if they are suitable for what you want to do?
-
Jun 10th, 2009, 12:25 AM
#3
Thread Starter
New Member
Re: Using Serial Port to Read String
Actually I -last time- use this code in a timer :
Code:
SerialPort1.Write("A")
kalimatarray(d) = SerialPort1.ReadExisting
RichTextBox1.Text = RichTextBox1.Text & g & vbNewLine
The Electronics will send just a "HELLO" string to the PC, if it receives an "A" from the PC. This works but the vbNewLine is never there on the RichTextBox1.
I am using the PC to receive some string of numbers, like :
"1235 3303 2101 3030"
First time I send them byte per byte and it is rather slow to read.
Now I am considering making them a string and just send them in one step only. Do you have any Idea? I am new in VB so I don't understand 100% about the classes.
-
Jun 10th, 2009, 02:34 AM
#4
Member
Re: Using Serial Port to Read String
Wouldn't the SerialPort.ReadLine method be more appropriate?
Also does your electronics sends a newline character at the end of the string to mark the end of it?
-
Jun 10th, 2009, 02:45 AM
#5
Thread Starter
New Member
Re: Using Serial Port to Read String
I will try it. . .and will post the result soon.
-
Jun 10th, 2009, 08:54 AM
#6
Thread Starter
New Member
Re: Using Serial Port to Read String
Nope, still not working (working if I put "\nHELLO\n") and even after some time it freezes. (the electronics software is in C, and I have set everything correct there.)
I have another idea. Does anyone knows on how the serial port knows that it has data on its buffer, so it is like polling (always check the buffer) and if something goes inside, it reads it immediately. What happens in my experiment is the data get deposited inside the buffer. (I realize it when I unplug the electronics, serialport1 still reads for some time, before actually freezes, and the longer I deposit the data, the longer I can have it read without the electronics.)
Regards,
Elektronika
Code:
SerialPort1.Write("A")
'I think of putting some code here, to check whether the buffer already has some data
RichTextBox1.Text = RichTextBox1.Text & SerialPort1.ReadLine & vbNewLine
Tags for this Thread
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
|