Click here to Skip to main content
15,895,667 members
Home / Discussions / C#
   

C#

 
GeneralRe: static property with polymorphism Pin
Luc Pattyn8-Apr-10 6:59
sitebuilderLuc Pattyn8-Apr-10 6:59 
GeneralRe: static property with polymorphism Pin
PIEBALDconsult8-Apr-10 8:13
mvePIEBALDconsult8-Apr-10 8:13 
AnswerSolved: static property with polymorphism Pin
lukeer9-Apr-10 2:59
lukeer9-Apr-10 2:59 
QuestionCOM port send/receive Pin
mprice2148-Apr-10 4:02
mprice2148-Apr-10 4:02 
AnswerRe: COM port send/receive Pin
PIEBALDconsult8-Apr-10 4:16
mvePIEBALDconsult8-Apr-10 4:16 
GeneralRe: COM port send/receive Pin
mprice2148-Apr-10 4:23
mprice2148-Apr-10 4:23 
GeneralRe: COM port send/receive Pin
PIEBALDconsult8-Apr-10 5:25
mvePIEBALDconsult8-Apr-10 5:25 
GeneralRe: COM port send/receive Pin
mprice2148-Apr-10 8:42
mprice2148-Apr-10 8:42 
I have pasted below the code that I am now using. As I am new to this, I thought a timer could be relatively easy to implement instead of the btnStart_Click event. Also, I know timing could really mess things up, but not sure how to deal with that either...

private void btnStart_Click(object sender, EventArgs e)
        {
             //Makes sure serial port is open before trying to write
            try
            {
                if (!sp1.IsOpen)
                    sp1.Open();

                sp1.Write("*X01\r");

            }
            catch (Exception ex)
            {
                MessageBox.Show("Error opening/writing to serial port :: " + ex.Message, "Error!");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // all of the options for a serial device
            // can be sent through the constructor of the SerialPort class
            // PortName = "COM1", Baud Rate = 9600, Parity = odd, 
            // Data Bits = 7, Stop Bits = One, Handshake = None
            sp1 = new SerialPort("COM1", 9600, Parity.Odd, 7, StopBits.One);
            sp1.Handshake = Handshake.None;
            sp1.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
            sp1.ReadTimeout = 500;
            sp1.WriteTimeout = 500;
            sp1.Open();
        }

        void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Thread.Sleep(100);
            string data = sp1.ReadExisting();
            this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { data });
        }

        private void si_DataReceived(string data)
        {
            char[] charsToTrim = {'X','0','1'};
            textBox1.Text = data.TrimStart(charsToTrim);
            
        }

GeneralRe: COM port send/receive Pin
PIEBALDconsult8-Apr-10 11:25
mvePIEBALDconsult8-Apr-10 11:25 
GeneralRe: COM port send/receive Pin
mprice2148-Apr-10 14:20
mprice2148-Apr-10 14:20 
GeneralRe: COM port send/receive Pin
PIEBALDconsult8-Apr-10 17:13
mvePIEBALDconsult8-Apr-10 17:13 
GeneralRe: COM port send/receive Pin
mprice2149-Apr-10 2:25
mprice2149-Apr-10 2:25 
GeneralRe: COM port send/receive Pin
PIEBALDconsult9-Apr-10 3:22
mvePIEBALDconsult9-Apr-10 3:22 
GeneralRe: COM port send/receive Pin
mprice2149-Apr-10 3:46
mprice2149-Apr-10 3:46 
GeneralRe: COM port send/receive Pin
PIEBALDconsult9-Apr-10 4:09
mvePIEBALDconsult9-Apr-10 4:09 
AnswerRe: COM port send/receive Pin
Rajesh Anuhya9-Apr-10 2:36
professionalRajesh Anuhya9-Apr-10 2:36 
GeneralRe: COM port send/receive Pin
mprice21412-Apr-10 4:42
mprice21412-Apr-10 4:42 
GeneralRe: COM port send/receive Pin
mprice21412-Apr-10 7:51
mprice21412-Apr-10 7:51 
QuestionC# : Dispaly data in paragraph format Pin
Member 34895988-Apr-10 2:55
Member 34895988-Apr-10 2:55 
AnswerRe: C# : Dispaly data in paragraph format Pin
Abhinav S8-Apr-10 3:29
Abhinav S8-Apr-10 3:29 
QuestionGetting strings and ints of another class Pin
BuggingMe8-Apr-10 2:15
BuggingMe8-Apr-10 2:15 
AnswerRe: Getting strings and ints of another class Pin
Sunil Scaria8-Apr-10 2:43
Sunil Scaria8-Apr-10 2:43 
AnswerRe: Getting strings and ints of another class Pin
Arun Jacob8-Apr-10 2:48
Arun Jacob8-Apr-10 2:48 
GeneralRe: Getting strings and ints of another class Pin
BuggingMe8-Apr-10 2:52
BuggingMe8-Apr-10 2:52 
GeneralRe: Getting strings and ints of another class Pin
Sunil Scaria8-Apr-10 2:58
Sunil Scaria8-Apr-10 2:58 

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.