tags:

views:

204

answers:

4

Hi

i'm creating a windows form to send/receive data to/from serial port.

At first : i send the data as string to the serial port .

Second: i tried to read the string again for test the successfull transmission , but i recieved empty string

this is my code :

Try


Dim SerialPort1

As New SerialPort("Com1",9600, Parity.None, 8, StopBits.One)

SerialPort1.Open()

SerialPort1.DtrEnabled=True

SerialPort1.WriteLine("This is my test message ." )


' ================= Read from serial port

Label1.Text=SerialPort1.ReadExisting()    ' this returns empty string


 Catch ex As Exception 


MessageBox.Show(


"Error writing to serial port:" & ex.Message) 


Finally

SerialPort1.Close()


End Try

i need to ask another question:

is it required to connect device to serial port to send/recieve data successfully ????

please i need an urgent help

thanks

+1  A: 

ReadExisting returns the data sent by the device you are communicating with, not the data sent by you.

Heinzi
+3  A: 

As Heinzi already mentioned, if you want to see data you need to have some coming in. There is no automatic echo of data you send out.

To answer your other question: Yes, you need to have another device connected to your serial port in order to send/receive data successfully. With no other device, what would be the point?

Fortunately for you, the "device" you connect can be as simple as a plug with some wires. Here is a set of instructions and diagrams for building a so-called loopback plug: http://www.airborn.com.au/serial/rs232.html

This will allow you to echo your output to your input using very simple hardware. If you're not into soldering up your own plug, you can use a so-called breakout box: http://www.bb-elec.com/product.asp?sku=232BOB1

Carl Smotricz
A: 

You will need a device through which your application will send and receive data.

For testing, you might consider creating a virtual serial port with software like this Virtual Serial Port Driver. It allows you to create serial ports that aren't actually connected to any physical device. You can then debug your program with another program or with something like HyperTerminal or PuTTY.

Jason R. Coombs
+1  A: 

You could try to use com0com for generating a virtual serial port pair, then you can rename one of these virtual ports to common name like "COM4". You should open other SW like hyperterminal for serial communication, then set to open the remaining port from the pair.

You may try to use com0com fist with two hyperterminals.

Douglas Gemignani
+1. For most serial port coding, com0com or a nullmodem cable are pretty essential.
Jason Williams