private void btnOnekeyTest_Click(object sender, EventArgs e) { int i, k; FSystemID = 0; FChlAddr = 161; string sOutBSTR; int n1, nRet; Thread myThread = new Thread(ThreadMethod); starttime.Text = System.DateTime.Now.ToString(); //if (start == true) btnOnekeyTest.Enabled = false; btnExit.Enabled = true; runtime_i = 0; runtime.Text = "0:0"; //myThread.Start(); //start = true; stop_thread = false; test_string = true; second_count = 0; loop_count = 0; output_ampare = 0; runtime_hour = 0; { stop_thread = false; start = false; FTXObjCtrl.LoadObj(); // float temp = Convert.ToSingle(textBox1.Text); for (i = 0; i < 5; i++) { FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetProtect(FSsystemID[i], FChladdr[k], 1, 20F); FTXObjCtrl.SetProtect(FSsystemID[i], FChladdr[k], 3, 150F); FTXObjCtrl.SetFunctionMode(FSsystemID[i], FChladdr[k], 0); FTXObjCtrl.SetInput(FSsystemID[i], FChladdr[k], 1); //FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], Convert.ToSingle(ampere.Text)); } FTXObjCtrl.Close(); } myThread.Start(); } }
private void button1_Click(object sender, EventArgs e) { int i, k; start = true; stop_thread = true; for (i = 0; i < 5; i++) { FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetInput(FSsystemID[i], FChladdr[k], 0); } FTXObjCtrl.Close(); } btnExit.Enabled = false; btnOnekeyTest.Enabled = true; second_count = 0; FTXObjCtrl.FreeObj(); //FTXObjCtrl.FreeObj(); }
public void ThreadStart() { int nRet, i, j, k; if (loop_count < RUntime * 60) { if (second_count == 3600) { second_count = 0; } if (second_count <= 2760) { if (second_count == 0) { label6.Text = (second_count / 60 + 1).ToString(); output_ampare = 0; output_ampare1 = 0; j = (int)(second_count / 60); for (i = 0; i < 2; i++) { FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], output[i * 12 + k, j]); output_ampare = output[i * 12 + k, j] + output_ampare; } FTXObjCtrl.Close(); } for (i = 0; i < 3; i++) { FTXObjCtrl.OpenLAN(Device_Ip[i + 2], 7000, 1); if (i == 0) { for (k = 6; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i + 2], FChladdr[k], output[k - 6, j]); output_ampare1 = output[k - 6, j] + output_ampare1; } } else if (i == 1) { for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i + 2], FChladdr[k], output[k + 6, j]); output_ampare1 = output[k + 6, j] + output_ampare1; } } else if (i == 2) { for (k = 0; k < 6; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i + 2], FChladdr[k], output[k + 18, j]); output_ampare1 = output[k + 18, j] + output_ampare1; } } FTXObjCtrl.Close(); } FTXObjCtrl.OpenLAN(Device_Ip[2], 7000, 1); FTXObjCtrl.SetCCValue(FSsystemID[2], FChladdr[0], 0); FTXObjCtrl.Close(); FTXObjCtrl.OpenLAN(Device_Ip[4], 7000, 1); FTXObjCtrl.SetCCValue(FSsystemID[4], FChladdr[6], 0); FTXObjCtrl.Close(); ampere.Text = output_ampare.ToString(); label7.Text = output_ampare1.ToString(); } else if ((second_count % 60) == 0) { delaytime = second_count; label6.Text = (second_count / 60 + 1).ToString(); output_ampare = 0; output_ampare1 = 0; j1 = (int)(second_count / 60); i = 0; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], output[i * 12 + k, j1]); output_ampare = output[i * 12 + k, j1] + output_ampare; } FTXObjCtrl.Close(); } else if (delaytime != 0) { if ((second_count - delaytime) == 1) { i = 1; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], output[i * 12 + k, j1]); output_ampare = output[i * 12 + k, j1] + output_ampare; } FTXObjCtrl.Close(); ampere.Text = output_ampare.ToString(); } else if ((second_count - delaytime) == 2) { i = 0; FTXObjCtrl.OpenLAN(Device_Ip[i + 2], 7000, 1); if (i == 0) { for (k = 6; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i + 2], FChladdr[k], output[k - 6, j1]); output_ampare1 = output[k - 6, j1] + output_ampare1; } } FTXObjCtrl.Close(); } else if ((second_count - delaytime) == 3) { i = 1; FTXObjCtrl.OpenLAN(Device_Ip[i + 2], 7000, 1); if (i == 1) { for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i + 2], FChladdr[k], output[k + 6, j1]); output_ampare1 = output[k + 6, j1] + output_ampare1; } } FTXObjCtrl.Close(); } else if ((second_count - delaytime) == 4) { i = 2; FTXObjCtrl.OpenLAN(Device_Ip[i + 2], 7000, 1); if (i == 2) { for (k = 0; k < 6; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i + 2], FChladdr[k], output[k + 18, j1]); output_ampare1 = output[k + 18, j1] + output_ampare1; } } FTXObjCtrl.Close(); label7.Text = output_ampare1.ToString(); FTXObjCtrl.OpenLAN(Device_Ip[2], 7000, 1); FTXObjCtrl.SetCCValue(FSsystemID[2], FChladdr[0], 0); FTXObjCtrl.Close(); FTXObjCtrl.OpenLAN(Device_Ip[4], 7000, 1); FTXObjCtrl.SetCCValue(FSsystemID[4], FChladdr[6], 0); FTXObjCtrl.Close(); } } } else { if ((second_count % 60) == 0) { delaytime = second_count; label6.Text = (second_count / 60 + 1).ToString(); i = 0; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], 0); output_ampare = 0; } FTXObjCtrl.Close(); } else if ((second_count - delaytime) == 1) { { i = 1; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], 0); output_ampare = 0; } FTXObjCtrl.Close(); } } else if ((second_count - delaytime) == 2) { { i = 2; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], 0); output_ampare = 0; } FTXObjCtrl.Close(); } } else if ((second_count - delaytime) == 3) { { i = 3; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], 0); output_ampare = 0; } FTXObjCtrl.Close(); } } else if ((second_count - delaytime) == 4) { { i = 4; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], 0); output_ampare = 0; } FTXObjCtrl.Close(); label7.Text = output_ampare1.ToString(); } } ampere.Text = output_ampare.ToString(); } } else { if ((second_count % 60) == 0) { delaytime = second_count; label6.Text = (second_count / 60 + 1).ToString(); i = 0; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], 0); output_ampare = 0; } FTXObjCtrl.Close(); } else if ((second_count - delaytime) == 1) { { i = 1; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], 0); output_ampare = 0; } FTXObjCtrl.Close(); } } else if ((second_count - delaytime) == 2) { { i = 2; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], 0); output_ampare = 0; } FTXObjCtrl.Close(); } } else if ((second_count - delaytime) == 3) { { i = 3; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], 0); output_ampare = 0; } FTXObjCtrl.Close(); } } else if ((second_count - delaytime) == 4) { { i = 4; FTXObjCtrl.OpenLAN(Device_Ip[i], 7000, 1); for (k = 0; k < 12; k++) { FTXObjCtrl.SetCCValue(FSsystemID[i], FChladdr[k], 0); output_ampare = 0; } FTXObjCtrl.Close(); } label7.Text = output_ampare1.ToString(); } ampere.Text = output_ampare.ToString(); } if (second_count != 3600) { second_count = second_count + 1; } else { second_count = 0; } if (loop_count != (RUntime + Stoptime) * 60) { loop_count = loop_count + 1; } else { loop_count = 0; second_count = 0; } }