How to create/delete datapoint by script
- vy.nguyenthanh@biendongco.vn
- Posts:13
- Joined: Wed Sep 18, 2019 10:49 am
How to create/delete datapoint by script
I wanna create or delete automatically datapoint for datapoint type by script not manually. Can anyone help me?
- leoknipp
- Posts:2928
- Joined: Tue Aug 24, 2010 7:28 pm
Re: How to create/delete datapoint by script
For the creation/deletion of datapoints you can use the CTRL functions dpCreate()/dpDelete().
Best Regards
Leopold Knipp
Senior Support Specialist
Best Regards
Leopold Knipp
Senior Support Specialist
- Indrani125
- Posts:41
- Joined: Wed Aug 07, 2019 10:50 am
Re: How to create/delete datapoint by script
Hi,
Is when I tried to create data point by taking input from user..the script does not work..is it possible to create through user or creation of multiple data points through script?
Is when I tried to create data point by taking input from user..the script does not work..is it possible to create through user or creation of multiple data points through script?
- gschijndel
- Posts:376
- Joined: Tue Jan 15, 2019 3:12 pm
Re: How to create/delete datapoint by script
I do not think that there are any psychics here. So if you want to know why your script does not work, you should post your script code.
- Indrani125
- Posts:41
- Joined: Wed Aug 07, 2019 10:50 am
Re: How to create/delete datapoint by script
Hi,
Actually I wanted to know the possibility because when I am trying it is not happening.let me show my script and ui. Script is not working in case I want from user.It is working for script where I am defining type within script.attaching my UI also so that it can be related.
────────────────────────────────────────────────────────────────────────────────────────────────────
─// [PUSH_BUTTON1] [1] - [Clicked]
main()
{
if (dpExists("number_1")) DebugN("already exists");
else dpCreate("number_1","ExampleDP_Int"); // Create
dpCreate("TestDP", "PUMP1", 2); /*Create DP on the system with number 2*/
dpSetDescription("number_1.","Created through script");
DebugN(dpGetDescription("number_1."));
}
════════════════════════════════════════════════════════════════════════════════════════════════════
─// [PUSH_BUTTON2] [2] - [Clicked]
main()
{
string dpB = "number_1";
int retV;
retV = dpDelete(dpB);
DebugN(retV);
}
════════════════════════════════════════════════════════════════════════════════════════════════════
─// [TEXT_FIELD1] [8] - [Command]
// SimpleCtrlScriptStart {valid}
main()
{
EP_textFieldOut();
}
void EP_textFieldOut()
{
string sNewValue;
dyn_errClass err;
string sTmp;
getValue("", "text", sNewValue);
sTmp = sNewValue;
dpSetWait("System1:d1.type:_original.._value", sTmp);
err = getLastError();
if (dynlen(err) > 0)
errorDialog(err);
}
// SimpleCtrlScript {EP_textFieldOut}
// DP {System1:d1.type}
// Config {:_original.._value}
// DPType {string}
// SimpleCtrlScriptEnd {EP_textFieldOut}
════════════════════════════════════════════════════════════════════════════════════════════════════
─// [TEXT_FIELD2] [9] - [Command]
// SimpleCtrlScriptStart {valid}
main()
{
EP_textFieldOut();
}
void EP_textFieldOut()
{
string sNewValue;
dyn_errClass err;
string sTmp;
getValue("", "text", sNewValue);
sTmp = sNewValue;
dpSetWait("System1:d1.name:_original.._value", sTmp);
err = getLastError();
if (dynlen(err) > 0)
errorDialog(err);
}
// SimpleCtrlScript {EP_textFieldOut}
// DP {System1:d1.name}
// Config {:_original.._value}
// DPType {string}
// SimpleCtrlScriptEnd {EP_textFieldOut}
════════════════════════════════════════════════════════════════════════════════════════════════════
─// [PUSH_BUTTON3] [10] - [Clicked]
main()
{
if (dpExists("System1:d1.name:_original.._value")) DebugN("already exists");
else dpCreate("System1:d1.name:_original.._value","System1:d1.type:_original.._value"); // Create
dpCreate("TestDP", "PUMP1", 2); /*Create DP on the system with number 2*/
dpSetDescription("number_1.","created from user");
DebugN(dpGetDescription("System1:d1.name:_original.._value."));
}
════════════════════════════════════════════════════════════════════════════════════════════════════
─// [PUSH_BUTTON4] [11] - [Clicked]
main()
{
string dpB = "System1:d1.name:_original.._value";
int retV;
retV = dpDelete(dpB);
DebugN(retV);
}
════════════════════════════════════════════════════════════════════════════════════════════════════
Actually I wanted to know the possibility because when I am trying it is not happening.let me show my script and ui. Script is not working in case I want from user.It is working for script where I am defining type within script.attaching my UI also so that it can be related.
────────────────────────────────────────────────────────────────────────────────────────────────────
─// [PUSH_BUTTON1] [1] - [Clicked]
main()
{
if (dpExists("number_1")) DebugN("already exists");
else dpCreate("number_1","ExampleDP_Int"); // Create
dpCreate("TestDP", "PUMP1", 2); /*Create DP on the system with number 2*/
dpSetDescription("number_1.","Created through script");
DebugN(dpGetDescription("number_1."));
}
════════════════════════════════════════════════════════════════════════════════════════════════════
─// [PUSH_BUTTON2] [2] - [Clicked]
main()
{
string dpB = "number_1";
int retV;
retV = dpDelete(dpB);
DebugN(retV);
}
════════════════════════════════════════════════════════════════════════════════════════════════════
─// [TEXT_FIELD1] [8] - [Command]
// SimpleCtrlScriptStart {valid}
main()
{
EP_textFieldOut();
}
void EP_textFieldOut()
{
string sNewValue;
dyn_errClass err;
string sTmp;
getValue("", "text", sNewValue);
sTmp = sNewValue;
dpSetWait("System1:d1.type:_original.._value", sTmp);
err = getLastError();
if (dynlen(err) > 0)
errorDialog(err);
}
// SimpleCtrlScript {EP_textFieldOut}
// DP {System1:d1.type}
// Config {:_original.._value}
// DPType {string}
// SimpleCtrlScriptEnd {EP_textFieldOut}
════════════════════════════════════════════════════════════════════════════════════════════════════
─// [TEXT_FIELD2] [9] - [Command]
// SimpleCtrlScriptStart {valid}
main()
{
EP_textFieldOut();
}
void EP_textFieldOut()
{
string sNewValue;
dyn_errClass err;
string sTmp;
getValue("", "text", sNewValue);
sTmp = sNewValue;
dpSetWait("System1:d1.name:_original.._value", sTmp);
err = getLastError();
if (dynlen(err) > 0)
errorDialog(err);
}
// SimpleCtrlScript {EP_textFieldOut}
// DP {System1:d1.name}
// Config {:_original.._value}
// DPType {string}
// SimpleCtrlScriptEnd {EP_textFieldOut}
════════════════════════════════════════════════════════════════════════════════════════════════════
─// [PUSH_BUTTON3] [10] - [Clicked]
main()
{
if (dpExists("System1:d1.name:_original.._value")) DebugN("already exists");
else dpCreate("System1:d1.name:_original.._value","System1:d1.type:_original.._value"); // Create
dpCreate("TestDP", "PUMP1", 2); /*Create DP on the system with number 2*/
dpSetDescription("number_1.","created from user");
DebugN(dpGetDescription("System1:d1.name:_original.._value."));
}
════════════════════════════════════════════════════════════════════════════════════════════════════
─// [PUSH_BUTTON4] [11] - [Clicked]
main()
{
string dpB = "System1:d1.name:_original.._value";
int retV;
retV = dpDelete(dpB);
DebugN(retV);
}
════════════════════════════════════════════════════════════════════════════════════════════════════
- kilianvp
- Posts:443
- Joined: Fri Jan 16, 2015 10:29 am
Re: How to create/delete datapoint by script
even if the function to create a datapoint is already finished, in reality the datapoint is not yet created. it is therefore a good idea to wait until the datapoint exists.
- adaneau
- Posts:310
- Joined: Tue Feb 21, 2012 9:49 am
Re: How to create/delete datapoint by script
Good practice is always to wait for return value:
int iStatus = dpCreate("number_1","ExampleDP_Int");
BR
Alexandre
int iStatus = dpCreate("number_1","ExampleDP_Int");
BR
Alexandre
- Indrani125
- Posts:41
- Joined: Wed Aug 07, 2019 10:50 am
Re: How to create/delete datapoint by script
Hi,
I am getting problem basically for user defined data type creation.It is working fine for integer data.from user I am taking value of data point type and name setting it into d1.name and d1.type..when user is pressing enter..these two data points name is also changing..but when i am invoking dpcreate and dpdelete using d1.name and d1.type..basically script for Pushbutton3 and Pushbutton4 is not working where I am passing argument after user set via text field.
I am getting problem basically for user defined data type creation.It is working fine for integer data.from user I am taking value of data point type and name setting it into d1.name and d1.type..when user is pressing enter..these two data points name is also changing..but when i am invoking dpcreate and dpdelete using d1.name and d1.type..basically script for Pushbutton3 and Pushbutton4 is not working where I am passing argument after user set via text field.
- gschijndel
- Posts:376
- Joined: Tue Jan 15, 2019 3:12 pm
Re: How to create/delete datapoint by script
It is really basic, which everyone should be able to manage on their own (or at least after some basic training).
But anyway this code should work for the 'dpCreate'.
But anyway this code should work for the 'dpCreate'.
Code: Select all
if (dpExists(TEXT_FIELD2.text))
{
DebugN("already exists");
}
else
{
dpCreate(TEXT_FIELD2.text, TEXT_FIELD1.text); // Create
}
dpSetDescription(TEXT_FIELD2.text, "created from user");
string description;
dpGetDescription(TEXT_FIELD2.text, description);
DebugN(description);- Indrani125
- Posts:41
- Joined: Wed Aug 07, 2019 10:50 am
Re: How to create/delete datapoint by script
Hi,
Thank you..it is working for creation when I am taking text from textfield.I tried same for delete too..as I want to delete the data point node created dynamically through script so replaced number_1 with text from textfield..but in that case it is not working..can you please guide what went wrong?
main()
{
string dpB1 ="TEXT_FIELD2.text";
int retV1;
retV1 =dpDelete(dpB1);
DebugN(retV1);
}
Thank you..it is working for creation when I am taking text from textfield.I tried same for delete too..as I want to delete the data point node created dynamically through script so replaced number_1 with text from textfield..but in that case it is not working..can you please guide what went wrong?
main()
{
string dpB1 ="TEXT_FIELD2.text";
int retV1;
retV1 =dpDelete(dpB1);
DebugN(retV1);
}