How to create a OPC tag runtime - opc

I have a Kepware OPC server and I am able to connect with my client (OPC Foundation UA lib). I created a device in Kepware and a group inside. I would like to read opc tags from the database and create them dynamically.
How do I create an item with address in PLC dynamically ?

I can recommend you take a look at KepServerEX Configuration API. Basically, it gives you complete remote management and configuration control over all your KEPServerEX instances. In your case, you can dynamically generate tags through a simple RESTful API call at the device level after reading required information (e.g. tag name, tag address, tag datatype) from your database.
Please refer to this guide for more information in order to enable and test Configuration API.
I also copied the following piece of code from Kepware's sample project to give you an idea:
function createTag(inputServer, inputChannel, inputDevice, inputTag, inputTagAddr) {
console.log("Creating " + inputTag + " with address " + inputTagAddr);
$.ajax({
type: 'POST',
url: 'http://' + inputServer + '/config/v1/project/channels/' + inputChannel + '/devices/' + inputDevice + '/tags',
data: '{"common.ALLTYPES_NAME":"' + inputTag + '","servermain.TAG_ADDRESS":"' + inputTagAddr + '","servermain.TAG_DATA_TYPE":' + inputTagType + '}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(JSON, status, xhr) {
console.log(inputTag + " created under " + inputDevice);
},
error: function(JSON, status, xhr) {
console.log("Creation of " + inputTag + " failed!");
}
});
}

Within the Kepware Configuration, only certain drivers have the ability to dynamically create tags. For example, most of the Allen-Bradley suite can dynamically search and add tags while lower level drivers like Modbus can not. So it always depends on what driver the device in Kepware is using. To find individual configuration manuals for each driver, search here:
https://www.kepware.com/en-us/products/kepserverex/product-search/

Related

Access TFS RESTful API from Angular web app

I think TFS RESTful api has a bug. I am trying to access it using an Angular web app. Our TFS server is corporate internal. Here is my code:
var path = 'http://tfs.mycompany.com/tfs/mycompany/_apis/wit/queries?$depth=1&$expand=all&api-version=2.2';
var config = { withCredentials: true };
$http.get(path, config)
.then(function (response) {
$scope.resultList = response.data.d.results || [ response.data.d ];
$scope.message = 'Found ' + $scope.resultList.length + ' item' + ($scope.resultList.length == 1 ? '':'s');
}, function (response) {
$scope.resultList = [];
$scope.message = 'Error ' + response.status + ' ' + JSON.stringify(response.data);
});
The request goes to the server, and the server responds with OK 200. However, the browser (Chrome) blocks the data, and tells me:
A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header
when the credentials flag is true. Origin 'http://localhost' is therefore
not allowed access. The credentials mode of an XMLHttpRequest is controlled
by the withCredentials attribute.
The request headers have Origin:http://localhost
The response headers have Access-Control-Allow-Origin:*
Is there any way for me to tell TFS to not return * in the Access-Control-Allow-Origin? This seems like a serious bug in TFS, which renders the RESTful api practically useless for web apps!
You may check Cross-origin resource sharing (CORS) example below to add Authorization in your code:
$( document ).ready(function() {
$.ajax({
url: 'https://fabrikam.visualstudio.com/defaultcollection/_apis/projects?api-version=1.0',
dataType: 'json',
headers: {
'Authorization': 'Basic ' + btoa("" + ":" + myPatToken)
}
}).done(function( results ) {
console.log( results.value[0].id + " " + results.value[0].name );
});
});
Also, check this case to see whether it is helpful:
AJAX cross domain issue with Visual Studio Online REST API

Video steaming recived but not playing in WebRTC

I am trying to create a audio broadcasting app using WebRTC. To make it compatible with IE I am using Teamsys plugin from Attlasian.
In most of the demos available on internet I have seen two audio/video controls on a single page. But I am trying it with two page application. one for sender and another for reciever.
I am sending my stream description using XHR to a database where it is received by the another user and used as local description for the peer connection on receiver end.
Here is the code :
Sender
function gotStream(stream) {
console.log('Received local stream');
// Call the polyfill wrapper to attach the media stream to this element.
localstream = stream;
audio1 = attachMediaStream(audio1, stream);
pc1.addStream(localstream);
console.log('Adding Local Stream to peer connection');
pc1.createOffer(gotDescription1, onCreateSessionDescriptionError);
}
function gotDescription1(desc) {
pc1.setLocalDescription(desc);
console.log('Offer from pc1 \n' + desc);
console.log('Offer from pc1 \n' + desc.sdp);
$.ajax({
type: "POST",
url: '../../home/saveaddress',
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ SDP: desc }),
dataType: "json",
success: function (result) {
if (result) {
console.log('SDP Saved');
}
});
}
function iceCallback2(event) {
if (event.candidate) {
pc1.addIceCandidate(event.candidate,
onAddIceCandidateSuccess, onAddIceCandidateError);
console.log('Remote ICE candidate: \n ' + event.candidate.candidate);
}
}
At Receiver End
var pcConstraints = {
'optional': []
};
pc2 = new RTCPeerConnection(servers, pcConstraints);
console.log('Created remote peer connection object pc2');
pc2.onicecandidate = iceCallback1;
pc2.onaddstream = gotRemoteStream;
$.ajax({
type: "GET",
url: '../../home/getsavedaddress',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
if (result) {
gotDescription1(result);
}
},
error: function () {
}
});
function gotDescription1(desc) {
console.log('Offer from pc1 \n' + desc.sdp);
console.log('Offer from pc1 \n' + pc2);
pc2.setRemoteDescription(new RTCSessionDescription(desc));
pc2.createAnswer(gotDescription2, onCreateSessionDescriptionError,
sdpConstraints);
}
Using this I get the SDP from server , vedio tag has a source now. but video is not playing not showing anything.a an y clues..
also I am using asp.net for site , do I need to use node js in this project.
Thanks
Your question is lacking information, but I will give my opinion on it.
Are you supporting Trickle ICE? It seems you may be sending the SDP too fast!
When you do a
pc1.setLocalDescription(desc);
The ICE Candidates start being gathered based on the TURN and STUN server configured in your code here (servers parameter):
pc2 = new RTCPeerConnection(servers, pcConstraints);
That said, they are not yet included in your SDP. It can take a few milliseconds before the media ports are set in the localDescription Object. Your first error is that you are sending the "desc" Object from gotDescription1 instead of the post setLocalDescription SDP. That SDP doesn't have the proper media ports yet.
In your code, you are sending the SDP right away without waiting. My guess is that the SDP is not yet completed and you are not supporting Trickle. Because of that, even if signalling might look good, you will not see any media flowing.

Create DocumentSet with REST api

How would one format the rest uri to create a document set in SP?
The JSOM code below works fine, but I would prefer to use the REST in order to be able to call it from a workflow.
var dsresult = SP.DocumentSet.DocumentSet.create(context, parentFolder, "docsetfromjsom", docsetCtId);
I tried this format based on this MSDN article
var restQueryUrl = spAppWebUrl + "/_api/SP.AppContextSite(#target)/SP.DocumentSet.DocumentSet.create('serverrelativeurl','docsetname','ctid')?#target='spHostUrl'";
Tried other formats as well but none successful. In jsom you also need to include the context, but I am assuming that for the rest call you don't need to use it (i think). Anyone tried this before?
Thanks!
I've already answered a similar question at SharePoint StackExchange.
To summarize, it does not seem possible to create Document Set using SharePoint 2013 REST API since SP.DocumentSet.DocumentSet.create function is not accessible via REST. But you could utilize SharePoint 2010 REST API instead for that purpose.
The following example demonstrates how to create a Document Set using SharePoint 2010 REST Interface:
function getListUrl(webUrl,listName)
{
return $.ajax({
url: webUrl + "/_api/lists/getbytitle('" + listName + "')/rootFolder?$select=ServerRelativeUrl",
type: "GET",
contentType: "application/json;odata=verbose",
headers: {
"Accept": "application/json;odata=verbose"
}
});
}
function createFolder(webUrl,listName,folderUrl,folderContentTypeId)
{
return $.ajax({
url: webUrl + "/_vti_bin/listdata.svc/" + listName,
type: "POST",
contentType: "application/json;odata=verbose",
headers: {
"Accept": "application/json;odata=verbose",
"Slug": folderUrl + "|" + folderContentTypeId
}
});
}
function createDocumentSet(webUrl,listName,docSetName)
{
return getListUrl(webUrl,listName)
.then(function(data){
var folderUrl = data.d.ServerRelativeUrl + '/' + docSetName;
return createFolder(webUrl,listName,folderUrl,'0x0120D520');
});
}
Usage
Create Document Set named Orders in Documents library:
createDocumentSet(webUrl,'Documents','Orders')
.done(function(data)
{
console.log('Document Set ' + data.d.Name + ' has been created succesfully');
})
.fail(
function(error){
console.log(JSON.stringify(error));
});

how to set basic authorization header for GET service in sapui5?

Can I get a sample code to set basic authorization as header along with other headers ( like x-csrf-token : fetch) in eclipse ?
You can do something like this with jQuery (which is of course included with UI5) for basic authentication:
function ajaxBeforeSend(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(user + ":" + password));
}
$.ajax({
type: "GET",
url: url,
dataType: "json",
beforeSend: function(xhr) {
ajaxBeforeSend(xhr);
}
}).done(function(data) { /* do something */ }
This is what I've used in some developments and it works well. You can set other headers this way as well.
See http://www.w3schools.com/jsref/met_win_btoa.asp for details on btoa() which base64 encodes the user:pass string.
Your question says: "in eclipse". I don't know what that means as the javascript will work regardless of what editor you use.
Here's the jQuery doco which describes the method used above: http://api.jquery.com/jQuery.ajax/.
(Watch out for CORS issues if service is not on the same host as your app. For CORS I find you also need to add xhr.withCredentials = true; inside the above ajaxBeforeSend() function.)

Calling of webservice in titanium mobile application code always return response with status code 0

I am new to titanium appcelerator family. Also I am not sure if somebody has posted the same problem before. I couldn't found it so posting it here.
I am developing one mobile application. And in my application I am trying to call one web service which is hosted on my local environment, but it is always returning response with status code 0 and error message "Can't reach host". So I thought that there should be some problem with my web service that I deployed on remote location. And hence I have tried to call some other web services like twitter, but it's same.. :( It is giving me an error while calling twitter web service also.
I also check for a cross domain policy issue. So I have also tried to set rule on server for web service, but it didn't work out. Following is code snippet and environment details that I am using.
Application type: Mobile
Titanium SDK: 2.1.4 GA
Device: Web Browser
Host Operating System: Windows 7
Titanium Studio: Titanium Studio, build: 2.1.2.201208301612
Files for sample web service which is I am calling is present on following locations:
http://db.tt/XoSCujux (api.php)
http://db.tt/bJG2A5XT (Rest.inc.php)
http://db.tt/Hxt6Oojx (.htaccess)
Code:
//declare the http client object
var xhr = Titanium.Network.createHTTPClient();
//this method will process the remote data
xhr.onload = function() {
//check to see if we are refreshing the data via our
//pull and release mechanism
//create a json object using the JSON.PARSE function
result = JSON.parse(this.responseText);
Ti.API.info(result);
console.log(result);
var msgTitle = "data:";
var msgText = result;
var alertBox = Ti.UI.createAlertDialog({
title: msgTitle,
message: msgText
});
alertBox.show();
};
//this method will fire if there's an error in accessing the remote data
xhr.onerror = function(e) {
//log the error to our titanium developer console
Ti.API.error(this.status + ' - ' + this.statusText);
console.log(this.status + ' - ' + this.statusText);
var msgTitle = "Error : " + this.status;
var msgText = "Error Text : " + this.statusText;
var alertBox = Ti.UI.createAlertDialog({
title: msgTitle,
message: msgText
});
alertBox.show();
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT: " + this.responseText);
Ti.API.debug("ERROR: " + e.error);
alert('There was an error retrieving the remote data. Try again.' + e.error);
};
//open up the recipes xml feed
xhr.open("POST", "http://127.0.0.1/rest_example/api.php?rquest=locations");
//finally, execute the call to the remote feed
xhr.send();
Any help would be really appreciated.