08-05-2008 03:01 PM
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);}
}
}
}
08-06-2008
04:57 PM
- last edited on
10-29-2025
08:33 PM
by
Content Cleaner
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.
08-06-2008 05:14 PM
08-07-2008 10:26 AM