Jump to content
  • Advertisement
Sign in to follow this  
da_cobra

serial communication in C#

This topic is 4163 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to communicate with a digital voltmeter through IR communication which failes for now : All I have is this document : specification for Fluke 189 Voltmeter I can open my connection :
SerialPort sp = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);

// open serial port
sp.Open();
                
// set read time out to 500 ms
sp.ReadTimeout = 500;        



Sending works, without any errors, but when I try to receive I get a timeout error.
private void btnGetID_Click(object sender, EventArgs e)
        {
            try
            {
                //write line to serial port
                //sp.WriteLine(txtText.Text);
                sp.WriteLine("ID\r");
                
                //clear the text box
                txtText.Text = "";
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            try
            {
                //clear the text box
                txtTextReceive.Text = "";
                                
                //read serial port and displayed the data in text box
                txtTextReceive.Text = sp.ReadLine();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }



I'm 100% sure that the cable and the settings are correct, because I have an official application that can connect to my Voltmeter on the COM3 port with those settings. Maybe it has something to do with the carriage return? => <CR> or \r ?!? I hope someone can help me out here. Thanx in advance...

Share this post


Link to post
Share on other sites
Advertisement
What happens if you use sp.Write("ID\r") instead of sp.WriteLine("ID\r")? I don't know if it makes a difference but I suppose sp.WriteLine("ID\r") sends "ID\r\r\n" on windows (the documentation states that it appends Environment.NewLine).

Share this post


Link to post
Share on other sites
Try connecting to the device with HyperTerminal (connect directly to Com3, with the right parameters), then type "ID"[enter] and see what you get.

If it works with HyperTerminal, probably the .WriteLine is your problem.
If it doesn't work with HyperTerminal you have some problem with the hardware.

Also, if HyperTerminal doesn't work the first time, you might want to go in device manager, select the com port under 'ports (com & lpt) goto 'port settings', click 'advanced' and uncheck the box where it says "Use FIFO buffers (requires 16550 compatible UART)", some devices don't use a 16550 UART but a 8250 and I found it very hard to connect to this kind of devices with that option checked.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!