Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

confused on RS232 serial comms

trying to do a mini "hyperterm" like test applet for my boss (more proof of concept than anything) and i'm having problems utilizing SerialSession, here's what I have embedded into my form. basically I want to send command from the text box, and show what's currently being  seen from the unit in the RTFbox.
 

alInstruments;

using

NationalInstruments.UI;

using

NationalInstruments.UI.WindowsForms;

using

NationalInstruments.VisaNS;

using

System;

using

System.Collections.Generic;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Text;

using

System.Windows.Forms;

namespace

relaycommstest

{

public partial class Form1 : Form

{

SerialSession RS232 = new SerialSession("COM1");

public Form1()

{

try

{

RS232.AnyCharacterReceived +=

new SerialSessionEventHandler(RS232_AnyCharacterReceived);

RS232.BaudRate = 9600;

InitializeComponent();

}

catch (Exception e)

{

MessageBox.Show(e.Message);

}

}

void RS232_AnyCharacterReceived(object sender, SerialSessionEventArgs e)

{

try

{

richTextBox1.Text += RS232.ReadString();

}

catch (Exception exc)

{

MessageBox.Show(exc.Message);

}

}

private void textBox1_KeyDown(object sender, KeyEventArgs e)

{

try

{

if (e.KeyCode == Keys.Enter)

{

RS232.Write(textBox1.Text);

textBox1.Text =

"";

}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

}

}

}

0 Kudos
Message 1 of 4
(3,835 Views)

Hi,

Have you looked at the Serial examples that are shipped with NI-VISA? Please take a look at this document to see where they might be located on your system. This will be a great starting point for your applications.

 
Rasheel
0 Kudos
Message 2 of 4
(3,820 Views)
which example are you refering to? I don't see anything for serial comms...
0 Kudos
Message 3 of 4
(3,817 Views)
Hi Daniel,

Try this location:
C:\Documents and Settings\All Users\Documents\National Instruments\NI-VISA\Examples\DotNET2.0\SimpleReadWrite
Rasheel
0 Kudos
Message 4 of 4
(3,805 Views)