cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Adding VirtualThing after threadpool is started

FL_10545404
4-Participant

Adding VirtualThing after threadpool is started

Hi,

 

I am creating an application with the .net sdk that will run virtual things in a process. But I would also like to connect some virtual thing at any moment in the process.

 

Example: I start my application with thing1 and thing2. Then a few hours later I want to add thing3.

 

How would I be able to do so? Is it possible?

 

Regards, 

 

François Lévesque

1 ACCEPTED SOLUTION

Accepted Solutions
nmutter
14-Alexandrite
(To:PaiChung)

I think the question is related to the creation of a new instance - in context of the SteamSensor Example - of a new SteamThing in the already running application.

https://support.ptc.com/help/thingworx/edge_sdk_dotnet/en/#page/dotnet_sdk/c_dotnet_sdk_reference_virtualthing_class.html#wwID0E3BIM

SteamSensorClient client = createClient(host, appKey);

/* (done in createClient call)
	// Create two Virtual Things 
	SteamThing sensor1 = new SteamThing("SteamSensor1", "1st Floor Steam Sensor", null, client);
	SteamThing sensor2 = new SteamThing("SteamSensor2", "2nd Floor Steam Sensor", "SN0002", client);

	// Bind the Virtual Things
	client.bindThing(sensor1);
	client.bindThing(sensor2);
*/

// Wait for the SteamSensorClient to connect, then process its associated things.
// As long as the client has not been shutdown, continue
while (!client.isShutdown())
{
	// Only process the Virtual Things if the client is connected
	if (client.isConnected())
	{
		ThreadPool.QueueUserWorkItem(client.runClient);
	}
	
	// Question: Can we here also create new SteamThings and bind it to the client?
	
	// Suspend processing at the scan rate interval
	Thread.Sleep(scanRate);
}

 

I did not yet do it like this. I cannot answer this question.

 

View solution in original post

7 REPLIES 7
PaiChung
22-Sapphire I
(To:FL_10545404)

You have a full set of services available that you could invoke after connection. So it is certainly possible to do things like auto create based on a trigger, or 'self-registration' there have been several threads on this, quite a long time ago, hopefully you can find it using a search.

FL_10545404
4-Participant
(To:PaiChung)

I've been searching all day for a post that would give me what I am looking for and I found nothing. Would it be possible to point me in the right direction please. Since I am new to the sdk and ThingWorx.

 

Regards

FL_10545404
4-Participant
(To:PaiChung)

So I've read the content and I think I did not explain my self clearly. I will try to do so.

 

I do not need to create things with the sdk.

 

I need to bindThings after I started a process with some Things in it.

 

What I've tried to do so is create a Thing that will manage the insertion of other Things.

 

But when I bind things they do not connect in ThingWorx web platform.

 

Can I bind things after I have started my process and what do I need to do?

 

Regards,

 

Frank

PaiChung
22-Sapphire I
(To:FL_10545404)

When you say bind, you are using devices and RemoteThings?

I think your explanation lacks a lot of context unfortunately.

But I would say that if something needs to be bound, as something is in progress, and that process needs the bound items,

you will likely run into a lot of latency/timing issues.

You probably want to carefully outline each step that is being taken and then create some sort of asynchronous approach that allows it to work.

nmutter
14-Alexandrite
(To:PaiChung)

I think the question is related to the creation of a new instance - in context of the SteamSensor Example - of a new SteamThing in the already running application.

https://support.ptc.com/help/thingworx/edge_sdk_dotnet/en/#page/dotnet_sdk/c_dotnet_sdk_reference_virtualthing_class.html#wwID0E3BIM

SteamSensorClient client = createClient(host, appKey);

/* (done in createClient call)
	// Create two Virtual Things 
	SteamThing sensor1 = new SteamThing("SteamSensor1", "1st Floor Steam Sensor", null, client);
	SteamThing sensor2 = new SteamThing("SteamSensor2", "2nd Floor Steam Sensor", "SN0002", client);

	// Bind the Virtual Things
	client.bindThing(sensor1);
	client.bindThing(sensor2);
*/

// Wait for the SteamSensorClient to connect, then process its associated things.
// As long as the client has not been shutdown, continue
while (!client.isShutdown())
{
	// Only process the Virtual Things if the client is connected
	if (client.isConnected())
	{
		ThreadPool.QueueUserWorkItem(client.runClient);
	}
	
	// Question: Can we here also create new SteamThings and bind it to the client?
	
	// Suspend processing at the scan rate interval
	Thread.Sleep(scanRate);
}

 

I did not yet do it like this. I cannot answer this question.

 

FL_10545404
4-Participant
(To:nmutter)

Hi, 

 

thanks for this answer it was actually what we were about to try.

 

The real reason it was not working was because I was assigning Identifiers to my things and those remotethings did not have an identifier.

Top Tags