LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Datasocket shared variable api

I ran into the following the other day whilst debugging some code:

 

We had a type mismatch when sending data however, when testing the DataSocket API did not return this error information, nut the Shared Variable API did.

DS just returned default data with a change in the timestamp)

 

 

24150i64CF729FAE47BFC4

 

This got me thinking:

Is using Shared Variable API the way to go? Is it a better (more refined) API?

Are there different reasons for using one over the other? (I do like that DS's refnum is not datatyped, which means that I have to provide the datatype on the read as opposed to the SV-API).  

 

With respect to the type mismatch, I found that I could actually initialise the Variable with either datatype and it worked (only) for that datatype.

It would only error when the other datatype was used.

Does that mean the Variable does not know what its datatype actually is when a cluster is used?

 

Cheers

 

-JG

Certified LabVIEW Architect * LabVIEW Champion
0 Kudos
Message 1 of 33
(6,139 Views)

Sorry forgot to change the title from search mode.

Mods feel free to update to something that makes sense

Thanks

Certified LabVIEW Architect * LabVIEW Champion
0 Kudos
Message 2 of 33
(6,129 Views)

jgcode:

 

The Shared Variable API is more comprehensive when dealing with shared variables, so it's probably the way to go in that case. The benefit of DataSockets is that they're far more versatile. They can be used in a variety of applications (OPC, http, shared variables, etc.). Honestly, it's more a matter of programmer's preference in a lot of situations.

 

I'm not sure I quite follow your question regarding datatypes. It looks like the error is being returned because a variable cannot contain a cluster. You can do arrays, but not clusters, so that's probably why the SV API is complaining about the type input.

 

Let me know if that answers your question!

Caleb Harris

National Instruments | http://www.ni.com/support
0 Kudos
Message 3 of 33
(6,054 Views)

Hi,

Sorry if I am asking in the way I should not, but I am using Datasocket to read Shared Variables published on remote computer's project. 

 

When publishing and reading on the same computer, I used the URL "psp://localhost/library/variablename" format to Datasocket Open connection, and it worked perfectly. 

 

But, while accessing the shared variable on DataSocket on another computer, the above URL (with correct ip address) doesn't seem to work. Or in other words, I do not read any data in the client computer. The normal dstp:// URL works Ok (the connection is Ok).

I am using LV 8.6. 

 

Is there any KB article which gives step by step guide to use Datasocket with Shared Variable? The help pages and KB articles I saw do not answer my question. Everywhere, the psp URL is given to datasocket connection in. But it doesn't resolve my issue. 

 

Any tips are appreciated. 

Vaibhav
0 Kudos
Message 4 of 33
(6,019 Views)

Ok, I could get it working. 

 

Just supplied the PSP URL again to Datasocket nodes and it works fine. Strange. The new URL string is "apparently" the same - didn't even notice any spelling mistake. 

 

But my URL is very simple text string, not like the ones in this thread, in the first post - in violet colour. Reading several threads to see other aspects of Datasocket with Shared Variable. 

I wanted a queue like behaviour on network, hence selected Datasocket, and I wasn't sure if the Shared Variable (accessing the same variable on several computers, simultaneously) shares all the data on each of the computer (each computer will have its own copy of the new data, just like in Datasocket) or not. Will start a thread with results of my findings. 

 

Thanks anyways. 

Vaibhav
0 Kudos
Message 5 of 33
(6,005 Views)

Vaibhav:

 

It sounds like you're definitely on the right track. Here are a couple articles you might be interested in:

 

KnowledgeBase 3ZIH79SF: How Do I Read/Write to a Shared Variable with the DataSocket API?

LabVIEW 2010 Help: Sharing Live Data Programmatically

 

Good luck!

Caleb Harris

National Instruments | http://www.ni.com/support
0 Kudos
Message 6 of 33
(5,997 Views)

@charris wrote:

 

I'm not sure I quite follow your question regarding datatypes. It looks like the error is being returned because a variable cannot contain a cluster. You can do arrays, but not clusters, so that's probably why the SV API is complaining about the type input.

 


Hi Caleb

 

My question was relating to the fact that if the variable is not initialized on one PC, and I try reading from it on another PC, specifying the datatype to read back, then I get an error using the SV API but no error from DataSocket.

 

My use case was for a Cluster.

I didn't check whether it was Cluster-specific or occurs for every datatype.

I assumed Cluster-only as Clusters differ when setting up the Shared Variable.

I.e. All standard datatypes are available in a drop-down, but you need to select Custom Control for a Cluster.

 

So the last question was asking could I theoretically use any Cluster with a SV-Cluster as long it is the same when I do a Read and Write.

I.e. When using the DS/SV-API the Shared Variable does not know (/have information on) what its datatype actually is when a Cluster is used - it relies on what datatype is used to initialize it? 

 

Hope that makes sense.

 

Cheers

 

Jon

Certified LabVIEW Architect * LabVIEW Champion
0 Kudos
Message 7 of 33
(5,983 Views)

Caleb:

 

Thank you for the response.

The articles confirm that I am on the right track. 

But still want to explore the relationship between Shared Variable and Datasocket. 

 

 

Jon:

 

Can you tell me please, how do you get (or for what purpose is) that URL in purple box in your first post's images? I am just curious and want to explore more functionalities involving Shared Variables.

 

 

All:

 

Also, want to make sure I will not have some more bottlenecks in the future by selection of wrong approach (as I had in the case of Datasocket), so I just want to know how things work indeed. 

How do I get those other Shared Variable APIs / Functions? Is there a way to "monitor" Shared Variable Engine (and the data currently in the Shared Variable) ? 

 

Thanks ahead!

Vaibhav
0 Kudos
Message 8 of 33
(5,966 Views)

 


@Vaibhav wrote:

 

Jon:

 

Can you tell me please, how do you get (or for what purpose is) that URL in purple box in your first post's images? I am just curious and want to explore more functionalities involving Shared Variables.

 

 


 

Hi Vaibhav

There are different types of the purple URLs, for different APIs ->

You can get access to them via the Shared Variable API and also when you have DSC installed they are exposed in the palette. 

 

Certified LabVIEW Architect * LabVIEW Champion
0 Kudos
Message 9 of 33
(5,962 Views)

Hi Jon,

Thank you for your reply.

 

And how do I get to those Shared Variable API?

In the Functions Palette in Data Communication>Shared Variable, I see only two functions. So not sure where will be the Shared Variable API.

Is there any place where I can "open and watch" Shared Variable Engine?

 

And as for the DSC, I think I might have excluded it from the installation. I still haven't installed LV2010 on my computer. And not sure in which DVD of the LV8.6 was DSC module. 

 

 

Vaibhav
0 Kudos
Message 10 of 33
(5,958 Views)