# PVI - C# Example of connecting and reading variables in simulator

**URL:** <https://community.br-automation.com/t/pvi-c-example-of-connecting-and-reading-variables-in-simulator/4856>\
**Category:** Programming\
**Tags:** pvi\
**Created:** [November 12, 2024, 5:48pm UTC](https://community.br-automation.com/t/pvi-c-example-of-connecting-and-reading-variables-in-simulator/4856 "2024-11-12T17:48:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mSartoriOptrel](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/msartorioptrel/32/11882_2.png) [@mSartoriOptrel](https://community.br-automation.com/u/mSartoriOptrel)\
**Post date:** [November 12, 2024, 5:48pm UTC](https://community.br-automation.com/t/pvi-c-example-of-connecting-and-reading-variables-in-simulator/4856/1 "2024-11-12T17:48:16Z")

</div>

Hello  
I am not able to find an example of c# application to understand:

- how to connect to a simulator instance (127.0.0.1)
- how to read a variable  
with PVI 4.11

Is there someone that has an example or a snippet?  
Thank you very much in advance

Marco Sartori

---

<div class="post-metadata">

**Author:** ![kovarj](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/kovarj/32/537_2.png) [@kovarj](https://community.br-automation.com/u/kovarj)\
**Post date:** [November 12, 2024, 6:21pm UTC](https://community.br-automation.com/t/pvi-c-example-of-connecting-and-reading-variables-in-simulator/4856/2 "2024-11-12T18:21:14Z")

</div>

Hi, all official sample you can find in PVI installation folder. Default path is C:\BrAutomation\PVI\V4.11\Samples

---

<div class="post-metadata">

**Author:** ![mSartoriOptrel](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/msartorioptrel/32/11882_2.png) [@mSartoriOptrel](https://community.br-automation.com/u/mSartoriOptrel)\
**Post date:** [November 13, 2024, 8:54am UTC](https://community.br-automation.com/t/pvi-c-example-of-connecting-and-reading-variables-in-simulator/4856/3 "2024-11-13T08:54:23Z")

</div>

Yes, but there is no example where ArSim is used…

Question is: which properties should be set on connection?

 ![image](https://europe1.discourse-cdn.com/brcommunity/original/2X/3/3c2c168f114a89c8dd206829698fbb8aba2f71ce.png)

Thanks

---

<div class="post-metadata">

**Author:** ![michael\_w](https://avatars.discourse-cdn.com/v4/letter/m/FF8800/32.png) [@michael\_w](https://community.br-automation.com/u/michael_w)\
**Post date:** [November 13, 2024, 9:12am UTC](https://community.br-automation.com/t/pvi-c-example-of-connecting-and-reading-variables-in-simulator/4856/4 "2024-11-13T09:12:58Z")

</div>

Hi,

adapting the code to your needs requires looking at the generated documentation.

Going from the [CPU object](https://help.br-automation.com/#/en/6/automationnet%2Fpviservices%2Fclassreference%2Ft_br_an_pviservices_cpu.htm) to the type of its’ [Connection object](https://help.br-automation.com/#/en/6/automationnet/pviservices/classreference/t_br_an_pviservices_connection.htm) and looking at [DeviceType](https://help.br-automation.com/#/en/6/automationnet/pviservices/classreference/t_br_an_pviservices_devicetype.htm):

The example would get you something like this (I didn’t bother to change the style to that older line-by-line one):

```auto
cpu = new Cpu(service, "Cpu") {
	Connection = {
		DeviceType = DeviceType.ANSLTcp,
		ANSLTcp = {
			DestinationIpAddress = "127.0.0.1"
		},
		ResponseTimeout = 5
	}
};

```

---

<div class="post-metadata">

**Author:** ![michael\_w](https://avatars.discourse-cdn.com/v4/letter/m/FF8800/32.png) [@michael\_w](https://community.br-automation.com/u/michael_w)\
**Post date:** [November 14, 2024, 11:03am UTC](https://community.br-automation.com/t/pvi-c-example-of-connecting-and-reading-variables-in-simulator/4856/5 "2024-11-14T11:03:43Z")

</div>

@mSartoriOptrel waiting patiently for a reply 🙂

---

<div class="post-metadata">

**Author:** ![mSartoriOptrel](https://dub1.discourse-cdn.com/brcommunity/user_avatar/community.br-automation.com/msartorioptrel/32/11882_2.png) [@mSartoriOptrel](https://community.br-automation.com/u/mSartoriOptrel)\
**Post date:** [November 14, 2024, 7:18pm UTC](https://community.br-automation.com/t/pvi-c-example-of-connecting-and-reading-variables-in-simulator/4856/6 "2024-11-14T19:18:56Z")

</div>

Ahahah.  
Many thanks @michael_w  
Sorry for the late reply. I had the chance only to test the connection and it worked perfectly.  
Hope this help someone else that has basic knowledges on c# like me 😂

Thanks again  
Marco Sartori
