/// <summary> /// Creates a PI point on the PI server with a given value /// </summary> /// <param name="value"></param> private void createPIPoint(float value) { try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { string usertag = textBox_tag.Text;//set new value to a certain point //Creating a point myPI.createPiPoint(usertag, 2); // Setting the value of the point // Also have the power to only update the value on an existing // tag instead of creating a new tag. myPI.setPiPointValue(usertag, myTruncate(value, 6)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { } }
/// <summary> /// Change frequency to accomplish desired flow rate /// </summary> /// <param name="desiredFlowRate">Desired flow rate</param> public static void freqConversion(object desiredFlowRateObj) { //convert obj into float float desiredFlowRate = (float)desiredFlowRateObj; //point variables PointVal currentFlowValue; PointVal currentFreqValue; List <PointVal> freqList; List <PointVal> flowList; //Set up OSI PI OSIPI myPI = new OSIPI(); myPI.connect_Server("ESMARTSERVER-PC"); //put current flow rate in a saved PI point flowList = myPI.searchPiPoints("SP14VICE_Flow", DateTime.Now.ToString(), DateTime.Now.ToString()); currentFlowValue = flowList.ElementAt(0); //Check if flow varies by +/- 1 GPM while (float.Parse(currentFlowValue.value) > (desiredFlowRate + 1) || float.Parse(currentFlowValue.value) > (desiredFlowRate - 1)) { //put current frequency in a saved PI point freqList = myPI.searchPiPoints("SP14VICE_Freq", DateTime.Now.ToString(), DateTime.Now.ToString()); currentFreqValue = freqList.ElementAt(0); //set new frequency if (float.Parse(currentFlowValue.value) > (desiredFlowRate + 5)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) + 10, 6)); } else if (float.Parse(currentFlowValue.value) < (desiredFlowRate - 5)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) - 10, 6)); } else if (float.Parse(currentFlowValue.value) > (desiredFlowRate + 2)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) + 5, 6)); } else if (float.Parse(currentFlowValue.value) < (desiredFlowRate - 2)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) - 5, 6)); } else if (float.Parse(currentFlowValue.value) > (desiredFlowRate + 1)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) + 2, 6)); } else if (float.Parse(currentFlowValue.value) < (desiredFlowRate - 1)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) - 2, 6)); } Thread.Sleep(6000); // sleep 6 sec for flow rate to change //put current flow rate in a saved PI point -- hopefully it changes in 8 sec flowList = myPI.searchPiPoints("SP14VICE_Flow", DateTime.Now.ToString(), DateTime.Now.ToString()); currentFlowValue = flowList.ElementAt(0); } }
public void parseVal(string letter, string value) { string lockVal = "SP14VICE_Lock"; string connection = "SP14VICE_Connection"; string frequency = "SP14VICE_Freq"; string vfdState = "SP14VICE_VfdState"; string temp = "SP14VICE_Temp"; string flow = "SP14VICE_Flow"; string desiredFlow = "SP14VICE_DesiredFlow"; string pressure = "SP14VICE_Pressure"; string voltage = "F13APA_Voltage"; string currenttop = "F13APA_CurrentTOP"; string currentbot = "F13APA_CurrentBOTTOM"; string powertop = "F13APA_Power_Top"; string powerbot = "F13APA_Power_Bot"; switch (letter) //checks first value in string for command { case "C": //if connection try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(connection, (float.Parse(value))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "L": //if Lock try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(lockVal, (float.Parse(value))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "FR": //if frequency try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(frequency, (float.Parse(value))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "VS": //if VFD State try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(vfdState, (float.Parse(value))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "PR": //if Pressure try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(pressure, (float.Parse(value))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "T": //if Temperature try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(temp, (float.Parse(value))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "F": //if Flow try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(flow, (float.Parse(value))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "DF": //if DesiredFlow try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(desiredFlow, (float.Parse(value))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "V": //if voltage string vtemp = voltage + outlet.ToString(); try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(vtemp, ((((float.Parse(value)) * 120) / Math.Pow(2, 23)) / .6)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "IT": //if current TOP outlet string currenttoptemp = currenttop + outlet.ToString(); try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(currenttoptemp, ((((float.Parse(value)) * 15) / (Math.Pow(2, 24) - 1)) / .6)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "IB": //if current BOT outlet string currentbottemp = currentbot + outlet.ToString(); try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(currentbottemp, ((((float.Parse(value)) * 15) / (Math.Pow(2, 24) - 1)) / .6)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "PT": //POWER TOP string powertoptemp = powertop + outlet.ToString(); try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(powertoptemp, 1 - ((float.Parse(value)) / (Math.Pow(2, 23) - 1))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "PB": //POWER BOT string powerbottemp = powerbot + outlet.ToString(); try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue(powerbottemp, 1 - ((float.Parse(value)) / (Math.Pow(2, 23) - 1))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "S": //set outlet Status outlet = int.Parse(value); break; case "STM": //set outlet Status stream = int.Parse(value); break; case "OO": //command from Web Service try { myPI.connect_Server("ESMARTSERVER-PC"); if (myPI.check_connection()) { //Setting the value of the point myPI.setPiPointValue("F13APA_STATUS", int.Parse(value)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } switch (value) //case for outlet switching from web service { case "00": { if (outlet == 1) { PythonComm.sendTCP(EWO1, 9750, "<,RT=0,RB=0,TM=" + stream.ToString() + ",>"); } else if (outlet == 2) { PythonComm.sendTCP(EWO2, 9750, "<,RT=0,RB=0,TM=" + stream.ToString() + ",>"); } } break; case "11": { if (outlet == 1) { PythonComm.sendTCP(EWO1, 9750, "<,RT=1,RB=1,TM=" + stream.ToString() + ",>"); } else if (outlet == 2) { PythonComm.sendTCP(EWO2, 9750, "<,RT=1,RB=1,TM=" + stream.ToString() + ",>"); } } break; case "10": { if (outlet == 1) { PythonComm.sendTCP(EWO1, 9750, "<,RT=1,RB=0,TM=" + stream.ToString() + ",>"); } else if (outlet == 2) { PythonComm.sendTCP(EWO2, 9750, "<,RT=1,RB=0,TM=" + stream.ToString() + ",>"); } } break; case "01": { if (outlet == 1) { PythonComm.sendTCP(EWO1, 9750, "<,RT=0,RB=1,TM=" + stream.ToString() + ",>"); } else if (outlet == 2) { PythonComm.sendTCP(EWO2, 9750, "<,RT=0,RB=1,TM=" + stream.ToString() + ",>"); } } break; } break; default: break; } }
/// <summary> /// Change frequency to accomplish desired flow rate /// </summary> /// <param name="desiredFlowRate">Desired flow rate</param> public static void freqConversion(object desiredFlowRateObj) { //convert obj into float float desiredFlowRate = (float)desiredFlowRateObj; //point variables PointVal currentFlowValue; PointVal currentFreqValue; List<PointVal> freqList; List<PointVal> flowList; //Set up OSI PI OSIPI myPI = new OSIPI(); myPI.connect_Server("ESMARTSERVER-PC"); //put current flow rate in a saved PI point flowList = myPI.searchPiPoints("SP14VICE_Flow", DateTime.Now.ToString(), DateTime.Now.ToString()); currentFlowValue = flowList.ElementAt(0); //Check if flow varies by +/- 1 GPM while (float.Parse(currentFlowValue.value) > (desiredFlowRate + 1) || float.Parse(currentFlowValue.value) > (desiredFlowRate - 1)) { //put current frequency in a saved PI point freqList = myPI.searchPiPoints("SP14VICE_Freq", DateTime.Now.ToString(), DateTime.Now.ToString()); currentFreqValue = freqList.ElementAt(0); //set new frequency if (float.Parse(currentFlowValue.value) > (desiredFlowRate + 5)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) + 10, 6)); } else if (float.Parse(currentFlowValue.value) < (desiredFlowRate - 5)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) - 10, 6)); } else if (float.Parse(currentFlowValue.value) > (desiredFlowRate + 2)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) + 5, 6)); } else if (float.Parse(currentFlowValue.value) < (desiredFlowRate - 2)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) - 5, 6)); } else if (float.Parse(currentFlowValue.value) > (desiredFlowRate + 1)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) + 2, 6)); } else if (float.Parse(currentFlowValue.value) < (desiredFlowRate - 1)) { myPI.setPiPointValue("SP14VICE_Freq", myTruncate(float.Parse(currentFreqValue.value) - 2, 6)); } Thread.Sleep(6000); // sleep 6 sec for flow rate to change //put current flow rate in a saved PI point -- hopefully it changes in 8 sec flowList = myPI.searchPiPoints("SP14VICE_Flow", DateTime.Now.ToString(), DateTime.Now.ToString()); currentFlowValue = flowList.ElementAt(0); } }