Add new VISA network device to resources - c#

I'm setting up a test environment including several instruments connected via LAN(TCP/IP) or USB. A Software shall be written in C# using the Ivi.Visa library. The instruments (which will change over time) get their IP address from a DHCP server so they won't show up in the Resources discovered byIVI.Visa.interop.ResourceManager.FindRsrc() unless they've been previously added by the Keysight Connection manager Software (or equivalent NI tool).
ResourceManager rMgr = new ResourceManager();
string[] enumRcrs = rMgr.FindRsrc("?*INSTR");
How does one achieve to discover new VISA Network devices in C# and add them to the resources list without having to use the external software before?

Modern instruments may support discovery via mDNS (see LXI specification here). I'm not familiar with Ivi.Visa library, but you may want to look over its documentation for instrument discovery feature. If it is not supported then you can probably implement mDNS request in your C# code.

Related

Bluetooth Consistency between devices

This is quite a general question I think but searching online I can't really find that much information. I have an embedded system with a Bluetooth chip that I often use to connect to another embedded device. This connection is very robust and never fails.
However the embedded system can also connect to windows via a virtual serial port. I've written a piece of software to handle the connection using the 32Foot inthehand bluetooth library. It works very consistently on some computers (including my own) but entirely fails or is very flakey on others. One of which is actually an identical system ( same hardware/ same version of windows)
Is there anything I should specifically be looking at in my software to improve reliability accross different computers/ versions of windows when it comes to bluetooth pairing, creation of virtual com ports etc.
Thanks
I write software that runs on Windows and connects to an embedded device via a virtual serial port using the 32Foot library. I've experienced similar issues to you, and from experience the main problems are:
Conflicts between Bluetooth radio on Windows:
Is more than one Bluetooth radio installed/attached? I find that if on a Windows machine there is both an external Bluetooth dongle plugged in, and the internal Bluetooth is switched on, it won't work.
Widcomm/Broadcom and BlueSoleil stacks:
These don't support authentication, and Widcomm/Broadcom don't support setting of a pin. You can check if BluetoothRadio.PrimaryRadio is not null, and if so find out the SoftwareManufacturer of the Bluetooth Radio. If the Manufacturer enum is Bluesoleil, Widcomm or Broadcom then just don't use authentication or SetPin when initializing the BluetoothClient.
Toshiba stack:
This isn't supported at all
Is a supported Bluetooth radio and stack even currently available?:
You can handle a PlatformNotSupportedException which will tell you if there is no currently available supported Bluetooth stack on the machine. This won't let you know if there is more than one radio attached however.
Finally, from experience, internal Bluetooth chips don't always have a good range and interference can really affect the connection. I have had better luck with an external Bluetooth dongle.

Getting the wired network name and security level on Windows

And by this question I mean the user assigned names windows lets you type in like: "My home network" "Basement" "Garage" not the ssid (though I would also like to read that one for the wifi connections)
and I especially want to read the windows security levels that can be chosen for networks: Home/Office/Public
I want to use this information to switch programs on and off automatically when connecting to various networks.
Update:
Thanks to the answer of #Damien_The_Unbeliever I was able to solve my question and find the following information, I hope it will help others too:
Network awareness in windows 7 and vista (MSDN, Unmanaged)
Windows API Code Pack (Microsoft, managed wrapper for
NetworkListManager and others)
How to use the windows NLM API to get notified of new network
connectivity (Codeproject, Managed)
It sounds like you want to use the Network List Manager:
The Microsoft Windows networking environment allows multihomed computers to connect to several networks simultaneously. There may be multiple wireless networks available along with LAN and dial-up connections. Network List Manager identifies available networks and returns network attribute data to the application.
It's a COM API, I'm not aware of a managed equivalent.

Bluetooth send/receive text without pairing using C# on 2 Windows 7 Computers

I have read that pairing is a must before communicating anything over bluetooth, but I want to know,
Can I create an application which would read a text which is
broadcasted by another bluetooth App without being paired.
Because we can see the names of other bluetooth devices around a device. So can't we set our bluetooth radio to a state that it would read any bluetooth boradcasting text message.
Example: there is createInsecureRfcommSocketToServiceRecord() & listenUsingInsecureRfcommWithServiceRecord() in android but aren't there such in C# for windows?
Thanks
My Ultimate Goal :-)
is creating an application running on windows 7 PCs, which create instant Bluetooth network for peer to peer file transfer and chat
Scenario
There is a group of people, each has this app on each computer, one wants to share a file, (may be an eBook, PDF or anything) with the rest. He sets his network "net" ( or any other name) in his app configuration and others also put that same name on each app. Finally each user can see the list of other Bluetooth nodes around them in their apps display, configured to same network name "net". so each can send files to selected nodes in the same network.
Design
Each user only turns on the Bluetooth radio and then enters a desired Network name in then app
Each application on PCs will communicate iteratively to reachable Bluetooth devices, through temporarily created connections (without pairing or user involvement), check their network names and list discoverable PCs with similar network names
Then they will share these lists among each other, so one PC knows the computers in their same network even though they are not in range directly.
Send files from one computer to one or many computers through a path resolved by an algorithm, even send chat texts.
All of this is going to be achieved through simple temporarily Bluetooth connections established between each application time to time, which requires no pairing or authentication, other than the Network Name. ( Because I don't know how to create Piconets using C#, or how to create bluetooth routing protocols.
No other security is implemented.
Please let me know of any other better design or way. Thank you very much for reading the lengthy text. Also include any helpful code which can help me achieve the above.
I make tens of un-paired connections every day... I don't know where this rumour comes from. :-,)
As you note on Android the default was for an authenticated connection -- maybe that's where the rumour started from? Even there, as you note, there are ways to request a 'pairing-not-required' connection e.g. listenUsingInsecureRfcommWithServiceRecord.
So, on the Microsoft stack on Windows one uses Bluetooth (RFCOMM) through a socket (winsock). By default that connection does not require authentication (pairing), nor encryption -- in fact to request auth/enc one must set a socket options. Similarly with Widcomm, you specify when you create the connection what security level you want, and that can be 'None'. Similarly on Bluetopia, similarly on BlueZ on Linux.
So if you use my library 32feet.NET, just use BluetoothClient and BluetoothListener and do not set cli.Authenticate=true etc. :-)
Some code examples
What's your ultimate goal? I've just realised that you were asking about file-transfer in another question... :-)
Anyway for transferring text... On the server-side have code like shown at: http://32feet.codeplex.com/wikipage?title=Bluetooth%20Server-side and on the client like: http://32feet.codeplex.com/wikipage?title=General%20Bluetooth%20Data%20Connections Don't know if you know TextWriter/-Reader sublclasses on .NET, anyway on one side:
....
var wtr = new StreamWriter(peerStream);
wtr.WriteLine("hello");
wtr.Flush();
and on the other:
....
var wtr = new StreamReader(peerStream);
var line = wtr.ReadLine();
MessageBox.Show(line);
There's code in the BluetoothChat which pretty much does something like that.
Alan

Mock Device connecting through USB

I have a device and the drivers for this device. What I would like to do is build an application that mocks a USB device to communicate with a third party application.
More specifically, I am attempting to build an application that can mock a USB device that mimics a Microsoft Zune. I want to make it so my application can register as a zune device and then communicate with the client. I have added several DLL's to my application in order to attempt to determine the calls that tell the software a connected device is a legitimate zune, but so far I haven't had much luck.
I'm new to this type of development - that is mimicking hardware devices, and I'm not very experienced in importing dll's that were written in C/C++. I am using Visual Studio 2010 (.net 4.0) to develop my app, and I would appreciate any help anyone can offer me towards mimicking the hardware. I do have the device drivers, which Visual studio refuses to reference directly. I also have an actual physical device, so I can see what the drivers are that it uses in Device Manager.
The goal is as follows
Application registers itself as a usb device, mimicking a Microsoft Zune in a similar fashion to how Virtual Clone Drive mimics a DVD player.
Application is recognized by zune client as a valid microsoft zune.
Zune Software works with application as it does the hardware device (syncing, etc)
I just found something called the Device Simulation Framework, which might be exactly what you need. It will still require significant research into how USB works to finish your solution, though. And probably still typically done using C or C++.
The Zune uses a modified version of the MTP protocol called MTPZ, but I found this sample using the Device Simulation Framework to simulate a regular MTP device. It's called The MTP Device Simulator. I can't tell if source code is available.
Are you able to replace the DLLs used by the zune client software with your own DLLs? In that case, you could wrap the original DLLs with your DLLs and intercept the operations.
Update: To find out the signatures of the functions in the DLL, take a look at the Dependency Walker tool, which will list the exported functions (and lots of other information). I'm guessing you will want to write your replacement DLL in C.
Otherwise, you'll have to write drivers that register a USB device with the proper endpoints. I'm not sure how to do this on Windows - I've only done USB coding on the firmware side, not the driver side. You should be able to use any tutorial for creating a Windows USB driver, like Getting Started with USB Driver Development
Zune specifics information might also be useful. Perhaps this blog post and its sequels could help: Inside the Zune/USB Protocol: Part 1

How to Create a Virtual Network Adapter in .NET?

I would like to create/add a virtual network adapter to a client operating system at runtime (via code), preferably in C#. Something similar to that of what VirtualBox/VMware/Himachi creates when you install their software. I am guessing this will require some C/C++ shenanigans for the driver integration, but if it is doable with only C#, all the better.
I am aware of OpenVPN, their stuff is primarily in C, and I am also aware of the TUN/TAP drivers floating around, I just didn't know if these were the only solutions not requiring me creating a fully loaded network driver for Windows.
If you need simple funcionality then you can use Microsoft Loopback Adapter. To install it use devcon tool. Here is some info about it http://support.microsoft.com/kb/311272.
devcon -r install %WINDIR%\Inf\Netloop.inf *MSLOOP After that you can use WMI query with C# to obtain new connection name and then netsh to configure it (ie. netsh int ip set address name="Local Area Connection 2" static 192.168.0.3 255.0.0.0)

Categories

Resources