ocaccy
asked on
A quick "fix" is place "Application.DoEvents();"
My problem is with the event.
I have 6 devices that need to access it in one second for data collection.
It should work like this:
Pressed the button that will access the devices automatically every 10 seconds.
Let's call a timer with 10 seconds INTERVAL.
The application sends the command ID01 to the serial port and awaiting a response.
If do not answer or the answer that comes is different from what I hope, that Reeves command.
In the fifth time, warns that not received the response.
So changes to ID01, and repeat the steps above.
If has answer and what is expected.
So changes to ID02 and repeat the above steps.
Thus even ID06.
Expect the cycle of 10 seconds and restarts the cycle.
I have 6 devices that need to access it in one second for data collection.
It should work like this:
Pressed the button that will access the devices automatically every 10 seconds.
Let's call a timer with 10 seconds INTERVAL.
The application sends the command ID01 to the serial port and awaiting a response.
If do not answer or the answer that comes is different from what I hope, that Reeves command.
In the fifth time, warns that not received the response.
So changes to ID01, and repeat the steps above.
If has answer and what is expected.
So changes to ID02 and repeat the above steps.
Thus even ID06.
Expect the cycle of 10 seconds and restarts the cycle.
private void button10_Click(object sender, EventArgs e)
{
textBox2.Clear();
CommPort com = CommPort.Instance;
for (int i = 0; i <= 6; i++)
{
for (int x = 0;x <= 5;x++)
{
string vstr = "ID0" + i.ToString();
string s_ID_compare = "0"+i.ToString();
vstr = ConvertEscapeSequences(vstr);
com.Send(vstr);
if(returned data = s_ID_compare)
{
..................
x= 6;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Angellll,
You help me to write the routine or method or class as you described above.
Why is the code I developed, is defective.
Regards,
ocaccy
You help me to write the routine or method or class as you described above.
Why is the code I developed, is defective.
Regards,
ocaccy
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok.
I understand.
I reanalyzed the code and return to continue.
I understand.
I reanalyzed the code and return to continue.
ASKER
The method with the command to the serial port is below.
But I can not solve this little problem.
In 10 hours of testing.
Not received data 3 times. This is unacceptable for my application.
How to solve?
But I can not solve this little problem.
In 10 hours of testing.
Not received data 3 times. This is unacceptable for my application.
How to solve?
private void timer_01_Tick(object sender, EventArgs e)
{
#region TRABALHA ID01
this.dataReceived = false;
string s_ID01_c = "id01";
CommPort com = CommPort.Instance;
s_ID01_c = ConvertEscapeSequences(s_ID01_c); ;
com.Send(s_ID01_c);
// Wait for data
DateTime start = DateTime.UtcNow;
while (!this.dataReceived)
{
// Timeout if has not completed in 5 seconds
if (DateTime.UtcNow.Subtract(start).TotalSeconds > 5)
throw new TimeoutException();
//Thread.Sleep(10);
Application.DoEvents();
}
//Thread.Sleep(150); // Dorme por 150 segundos
//com.Send(s_ID01_c);
timer_02.Enabled = true;
timer_01.Enabled = false;
#endregion
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
We had a problem of not receiving data, and receive duplicate data from the serial port with 6 devices RS485/USB, connected to the pc by a converter USB/RS485.
We solve the problem.
I used the code below.
Best Regards,
ocaccy.
We solve the problem.
I used the code below.
Best Regards,
ocaccy.
// timer-10 interval= 10000ms
// timer-01 interval= 200ms
// timer-02 interval= 200ms
// timer-03 interval= 200ms
// timer-04 interval= 200ms
// timer-05 interval= 200ms
// timer-06 interval= 200ms
private void GetData_Click(object sender, EventArgs e)
{
timer_10.Enabled = true;
}
private void timer_10_Tick(object sender, EventArgs e)
{
timer_01.Enabled = true;
}
#region timer_01_Tick
private void timer_01_Tick(object sender, EventArgs e)
{
#region WORKING ID01
this.dataReceived = false;
send_t = 0;
free1.Enabled = true;
#endregion
}
private void free1_Tick(object sender, EventArgs e)
{
if (send_t == 3)
{
this.dataReceived = true;
}
if (this.dataReceived == false)
{
string s_ID01_c = "id01";
CommPort com = CommPort.Instance;
s_ID01_c = ConvertEscapeSequences(s_ID01_c);
com.Send(s_ID01_c);
send_t = send_t + 1;
}
else
{
free1.Enabled = false;
timer_02.Enabled = true;
timer_01.Enabled = false;
}
}
#endregion
// After ends 01, chage to 02, to 03...........
ASKER
Thank you.
Yall do not give me a code, but show me the way.
Best Regards,
ocaccy
Yall do not give me a code, but show me the way.
Best Regards,
ocaccy
ASKER
I have the button code above.
And the code below.
I know there are errors in both: logic and code; Why am I suffering from it.
What I need is this:
The method should run automatically at intervals of 10 seconds.
// We have 6 devices: ID01, ID02, ID03, ID04, ID05, ID06
Send the command to CommPort ID01.
Returned?
Yes! These data and stores it in variables to write to. CSV file after ID06 is checked. Next.
No! 1 second interval. Resends the command ID01.
Repeat this cycle 5 times, If it returns! He did not return the fifth time. Error Alert. Stores this error alert in variable. Next.
We repeat the above steps with the ID02, ID03, ID04, ID05, ID06 and save the data in a file CSV, and location of the data ID that did not return a warning and Error Alert.
Clear the variables and restart the cycle in ID01.
I need a error code for any problems occurs in this method too.
Regards,
ocaccy
Open in new window
Open in new window