Click here to Skip to main content
15,896,730 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help with serial data display Pin
turbosupramk310-Nov-10 2:23
turbosupramk310-Nov-10 2:23 
GeneralRe: Help with serial data display Pin
ColinBurnell10-Nov-10 21:20
professionalColinBurnell10-Nov-10 21:20 
AnswerRe: Help with serial data display Pin
Luc Pattyn9-Nov-10 7:26
sitebuilderLuc Pattyn9-Nov-10 7:26 
GeneralRe: Help with serial data display Pin
turbosupramk39-Nov-10 7:42
turbosupramk39-Nov-10 7:42 
AnswerRe: Help with serial data display Pin
Luc Pattyn9-Nov-10 7:50
sitebuilderLuc Pattyn9-Nov-10 7:50 
GeneralRe: Help with serial data display Pin
turbosupramk39-Nov-10 10:31
turbosupramk39-Nov-10 10:31 
GeneralRe: Help with serial data display Pin
Luc Pattyn9-Nov-10 10:52
sitebuilderLuc Pattyn9-Nov-10 10:52 
GeneralRe: Help with serial data display Pin
turbosupramk39-Nov-10 16:24
turbosupramk39-Nov-10 16:24 
Hi Luc,

Here is what it looks like with the OE program, so it is working correctly. There has to be something I'm missing here?

<

>

http://img221.imageshack.us/img221/4316/serialterminal.png[^]


Here is my code after all kinds of tweaks or attempts to get this to work, if you'd like anything else just let me know. Thanks!


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;


namespace SimpleSerial
{
    public partial class Form1 : Form
    {
        // Add this variable

        string RxString;

        public Form1()
        {
            InitializeComponent();
            string[] theSerialPortNames = System.IO.Ports.SerialPort.GetPortNames();
            /*MessageBox.Show(theSerialPortNames[0]);
            MessageBox.Show(theSerialPortNames[1]);
            MessageBox.Show(theSerialPortNames[2]);
            MessageBox.Show(theSerialPortNames[3]);*/
            //MessageBox.Show(theSerialPortNames[4]);
            //MessageBox.Show(theSerialPortNames[5]);
        }


        private void buttonStart_Click(object sender, EventArgs e)
        {
            serialPort1.PortName = "COM7";
            serialPort1.BaudRate = 115200;

            serialPort1.Handshake = Handshake.None;



            serialPort1.Open();
            if (serialPort1.IsOpen)
            {
                buttonStart.Enabled = false;
                buttonStop.Enabled = true;
                textBox1.ReadOnly = false;
            }
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
            {
                serialPort1.Close();
                buttonStart.Enabled = true;
                buttonStop.Enabled = false;
                textBox1.ReadOnly = true;
            }

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (serialPort1.IsOpen) serialPort1.Close();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            // If the port is closed, don't try to send a character.

            if(!serialPort1.IsOpen) return;

            // If the port is Open, declare a char[] array with one element.
            char[] buff = new char[1];

            // Load element 0 with the key character.

            buff[0] = e.KeyChar;

            // Send the one character buffer.
            serialPort1.Write(buff, 0, 1);

            // Set the KeyPress event as handled so the character won't
            // display locally. If you want it to display, omit the next line.
            e.Handled = true;
        }

        private void DisplayText(object sender, EventArgs e)
        {
            textBox1.AppendText(RxString);

        }

        private void serialPort1_DataReceived
          (object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            RxString = serialPort1.ReadExisting();
            //RxString = serialPort1.ReadLine();
            serialPort1.Parity = Parity.None;
            serialPort1.StopBits = StopBits.One;
            serialPort1.DataBits = 8;
            serialPort1.NewLine = "(13)";
            this.Invoke(new EventHandler(DisplayText));
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void comboBox1_Click(object sender, EventArgs e)
        {

        }
    }
}

GeneralRe: Help with serial data display Pin
Luc Pattyn9-Nov-10 16:48
sitebuilderLuc Pattyn9-Nov-10 16:48 
GeneralRe: Help with serial data display Pin
turbosupramk310-Nov-10 3:03
turbosupramk310-Nov-10 3:03 
GeneralRe: Help with serial data display Pin
NedPat10-Nov-10 19:38
NedPat10-Nov-10 19:38 
GeneralRe: Help with serial data display Pin
ShafiqA11-Nov-10 18:29
ShafiqA11-Nov-10 18:29 
GeneralRe: Help with serial data display Pin
Adam Yonce10-Nov-10 2:50
Adam Yonce10-Nov-10 2:50 
GeneralRe: Help with serial data display Pin
turbosupramk310-Nov-10 3:05
turbosupramk310-Nov-10 3:05 
NewsRe: Help with serial data display Pin
turbosupramk310-Nov-10 14:41
turbosupramk310-Nov-10 14:41 
AnswerRe: Help with serial data display Pin
davidwz9-Nov-10 19:04
davidwz9-Nov-10 19:04 
AnswerRe: Help with serial data display Pin
DarthDana10-Nov-10 4:59
professionalDarthDana10-Nov-10 4:59 
QuestionHow can I get the filename and sourcepath of a running process? Pin
Erik8-Nov-10 23:52
Erik8-Nov-10 23:52 
AnswerMessage Closed Pin
9-Nov-10 0:15
stancrm9-Nov-10 0:15 
GeneralRe: How can I get the filename and sourcepath of a running process? Pin
RaviRanjanKr9-Nov-10 3:56
professionalRaviRanjanKr9-Nov-10 3:56 
AnswerRe: How can I get the filename and sourcepath of a running process? Pin
RaviRanjanKr9-Nov-10 3:55
professionalRaviRanjanKr9-Nov-10 3:55 
AnswerRe: How can I get the filename and sourcepath of a running process? Pin
Luc Pattyn9-Nov-10 4:10
sitebuilderLuc Pattyn9-Nov-10 4:10 
GeneralRe: How can I get the filename and sourcepath of a running process? Pin
RaviRanjanKr9-Nov-10 4:24
professionalRaviRanjanKr9-Nov-10 4:24 
GeneralRe: How can I get the filename and sourcepath of a running process? Pin
ShilpaKumari10-Nov-10 0:20
ShilpaKumari10-Nov-10 0:20 
GeneralRe: How can I get the filename and sourcepath of a running process? Pin
RaviRanjanKr10-Nov-10 1:29
professionalRaviRanjanKr10-Nov-10 1:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.