public void Dispose() { MyBK.CloseSocket(); }
//Função para fazer o Update do ValueRead do Array DI //Função executada pelo Thread para Escrita/Leitura de Entradas/Saídas de PLC private void IOReadWrite() { do { //----------------------------------------------------------------------- //Ciclo de Leitura de Entradas Digitais: //----------------------------------------------------------------------- if (bk_Read_DI.Length > 0) { MyBK.ReadDigitalInput(0, (Int16)bk_Read_DI.Length, bk_Read_DI); UpdateArrayDI(); Thread.Sleep(10); } //----------------------------------------------------------------------- //Ciclo de Leitura de Saidas Digitais: //----------------------------------------------------------------------- if (bk_Read_DO.Length > 0) { MyBK.ReadDigitalOutput(0, (Int16)bk_Read_DO.Length, bk_Read_DO); UpdateArrayDO(); Thread.Sleep(10); } //----------------------------------------------------------------------- //Ciclo de Escrita de Saídas Digitais: //----------------------------------------------------------------------- if (bk_Write_DO.Length > 0 && NeedToWrite) { UpdateBK_Write(); MyBK.WriteMultipleDigitalOutputs(0, (Int16)bk_Write_DO.Length, bk_Write_DO); NeedToWrite = false; Thread.Sleep(10); } //----------------------------------------------------------------------- //Ciclo de Leitura de Entradas Analógicas: //----------------------------------------------------------------------- if (bk_Read_AI.Length > 0) { for (int i = 0; i < Dt_AI.Rows.Count; i++) { var valorAnalogica = 0; MyBK.ReadAnalogInput((short)(i * 2 + 1), ref valorAnalogica); Dt_AI.Rows[i]["Value"] = valorAnalogica; Thread.Sleep(10); } } //----------------------------------------------------------------------- //Ciclo de Escrita de Saidas Analógicas: //----------------------------------------------------------------------- if (bk_Write_AO.Length > 0) { if (NeedToWriteAO) { for (int i = 0; i < Dt_AO.Rows.Count; i++) { var valorAnalogica = 0.0; if (double.TryParse(Dt_AO.Rows[i]["Value"].ToString(), out valorAnalogica)) { MyBK.WriteAnalogOutput((short)(i * 2 + 1 + (Dt_AI.Rows.Count * 2)), (double)valorAnalogica * 32767 / 10); NeedToWriteAO = false; } } Thread.Sleep(10); } } //----------------------------------------------------------------------- //Ciclo de Leitura de Saidas Analógicas: //----------------------------------------------------------------------- if (bk_Write_AO.Length > 0) { if (NeedToWriteAO) { for (int i = 0; i < Dt_AO.Rows.Count; i++) { var valorAnalogica = 0.0; if (double.TryParse(Dt_AO.Rows[i]["Value"].ToString(), out valorAnalogica)) { MyBK.WriteAnalogOutput((short)(i * 2 + 1 + (Dt_AI.Rows.Count * 2)), (double)valorAnalogica * 32767 / 10); NeedToWriteAO = false; Thread.Sleep(10); } } } } //if (Safety == null) { Safety.Dt_DI = Dt_DI; } CycleRunning = true; } while (MyBK.wsStatus == 1); CycleRunning = false; }