using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.IO.Ports;
namespace CSSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Perform process when Button1 is pressed
private void button1_Click(object sender, EventArgs e)
{
StreamWriter sw;
string recvstr;
int i;
try
{
button1.Enabled = false; //Disable buttons during communication........(a)
button2.Enabled = false;
//Communication port setting.......................(b)
SerialPort1.PortName = "COM1";
SerialPort1.BaudRate = 9600;
SerialPort1.DataBits = 8;
SerialPort1.Parity = Parity.None;
SerialPort1.StopBits = StopBits.One;
SerialPort1.NewLine = "\r\n"; //Terminator setting..........................(c)
SerialPort1.ReadTimeout = 2000; //2 seconds time out.........................(d)
SerialPort1.Open(); //Open a port
SendSetting(); //Instrument settings
sw = new StreamWriter(@"data.csv"); //Create text file to be saved.............(e)
for (i = 0; i < 10; i++)
{