Click here to Skip to main content
15,886,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..


I have 3 forms,form1,form2 and form3. I have to perform following things

1. Send data from form1 to serial port.

2. when form1 get value '1', show second form.
3. when click a button in form2 show form3.
4. when click a send button call a function in form1 and send data to serial port.
5. Wait for response.
6. When get a response again send data without clicking the button.
7. wait for response.
8. When get a response again send data without clicking the button.
9. continues this procedure so many times

But my problem is that how can I manage this with timer. after getting acknowledgement am sending next data and I stop the timer. But when I get acknowledgement I cant send data, because I already stopped the timer. Is there any solution to this?


C#
code in form3


 private void button1_Click(object sender, EventArgs e)
    {
        int temp =Convert.ToInt32( comboBox1.Text);
        if (comboBox1.Text == "25")
        {
            tempp[0] = 0;

        }
        else if (comboBox1.Text == "30")
        {
            tempp[0] = 1;
        }
        else if (comboBox1.Text == "37")
        {
            tempp[0] = 2;
        }
        int filter = Convert.ToInt32(comboBox2.Text);
        int asp = Convert.ToInt32(textBox1.Text);
        int prnt = Convert.ToInt32(textBox2.Text);
        int abs = Convert.ToInt32(textBox3.Text);
        byte[] cmdt = BitConverter.GetBytes(Form1.SETTEMPERATURE);
        byte[] nn = BitConverter.GetBytes(Form1.SETFILTER);
        byte[] len = new byte[1];
        byte[] ERR = new byte[1];
      // byte[] val = new byte[1];
       len[0] = 3;
       ((Form1)this.Owner).SerialPortValueUpdated(len, cmdt, ERR, tempp);

    }

    private void Filter_Load(object sender, EventArgs e)
    {
        timer1.Start();
    }


    private void timer1_Tick(object sender, EventArgs e)
    {
        if (Form1.tflag == 1&&Form1.filflag==0)
        {
            label7.Text = "FILTER...";
              rrr = 1;
        }
        if (Form1.filflag == 1&&Form1.tflag==0)
        {

            label7.Text = "ACK...";
            fltflag = 1;
        }
                  // }
        if (rrr == 1)
        {
           // Form1.tflag = 0;

            byte[] nn = BitConverter.GetBytes(Form1.SETFILTER);
            byte[] len = new byte[1];
            byte[] ERR = new byte[1];
            byte[] val = new byte[1];
            len[0] = 3;
            ((Form1)this.Owner).SerialPortValueUpdated(len, nn, ERR, val);
             timer1.Stop();
        }
        if (fltflag == 1)
        {
            Form1.filflag = 0;
          byte[] nn = BitConverter.GetBytes(Form1.GETRAWADS);
            byte[] len = new byte[1];
            byte[] ERR = new byte[1];
            byte[] val = new byte[1];
            len[0] = 3;
            ((Form1)this. Owner).SerialPortValueUpdated(len, nn, ERR, val);

        }
     }
Posted
Comments
AndrewCharlz 26-Sep-14 0:41am    
y do u stop your timer
Member 10994712 26-Sep-14 1:01am    
if I didn't stop the timer it will send the data repeatedly. because I write send command in timer tick event.
ZurdoDev 26-Sep-14 10:34am    
1. Please reply to comment so user is notified.
2. I don't follow what the issue is with the timer but it sounds like you just need to set a flag so that when the timer ticks you check the flag to know what it is you are doing.
Member 10994712 26-Sep-14 23:20pm    
am receiving data from serial port in form1. when data is received, a flag is set. Then in form4's timer checking that flag in form1 is set or not. if set, sending data to serial port.after getting acknowledgement am sending next data and I stop the timer. But when I get acknowledgement I cant send data, because I already stopped the timer. How can I solve this?
ZurdoDev 27-Sep-14 7:49am    
You just repeated what you already said which doesn't clarify the problem.

So, don't stop the timer. Set a different flag so you know what is happening.

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