Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i read continuous values which are displayed on a device(ESP 301 Motion Controller) in GUI using C# (WFA).

I have a RS232 cable connected.

Correct me if i am wrong .Is't like i add the device's .dll(File) as reference to the file and then use the Data sheet's ASCII commands to read (display) which is on Device's Panel..?

What I have tried:

C#
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO.Ports;


namespace MotionController
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
            getavailableports();
        }
        void getavailableports()
        {
            String[] ports = SerialPort.GetPortNames();
            comboBox1.Items.AddRange(ports);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "") 
               {
                MessageBox.Show("Select the COM Port", "Error" ,
                                 MessageBoxButtons.OKCancel,
                                 MessageBoxIcon.Error);
               }
            else
            {
                SerialPort SerialPort1 = new SerialPort("COM1", 9600);
                SerialPort1.Open();
                button1.BackColor = Color.Green;
                button2.BackColor = Color.Transparent;
                if (SerialPort1.IsOpen)//if the serialport is open
                {
                    button1.Enabled = false;//disable the start button
                    button2.Enabled = true;//enable the stop button
                                      
                }
            }
        }
            

        private void button2_Click(object sender, EventArgs e)
        {
            SerialPort SerialPort1 = new SerialPort("COM1", 9600);
            SerialPort1.Close();
            button2.BackColor = Color.Red;
            button1.BackColor = Color.Transparent;
            button1.Enabled = false;//disable the start button
            button2.Enabled = true;//enable the stop button
       }
  

// Uncomplete Code - Displaying Values..?

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            SerialPort SerialPort1 = new SerialPort("COM1", 9600);
            SerialPort1.Open();
            if (SerialPort1.IsOpen == true)
            {
                int OpenInstrument(string strCOM1,int 9600);
                string strCOMPort: SerialPort.Port(); 
                int baudrate: 9600;
                SerialPort1.ReadLine(3MD?);
                return;
            }


        }
    }
    }
Posted
Updated 26-Sep-17 17:16pm
v2
Comments
Richard MacCutchan 26-Sep-17 11:06am    
It all depends on the form of the information you receive from the device. You need to study the documentation for the device in order to decide how to process and display it.
Member 13430881 27-Sep-17 5:47am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900