Getting Wifi RSSI or signal strength using WlanAPI and IpHlpAPI [closed] - c#

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 24 days ago.
Improve this question
I'm trying to recreate the functionality of the wifi icon inside the Windows task bar using this library and C#.
https://github.com/dahall/Vanara
To get the current network interface I am calling GetBestInterface from IpHlpAPI and it seems to be returning the right index. However I'm struggling on how to get the RSSI or signal strength value of the wifi network that's attached to this interface. Using this data I could recreate the wifi icon with 1 bars, 2 bars, 3 bars, ect..
Using WlanAPI I can call WlanGetAvailableNetworkList which returns a list that has the signal strength value for each network. There doesn't seem to be any data to connect these two things, so obviously I'm missing something.
Anyone have any ideas on the approach I should take?

You could try to use WlanQueryInterface function with wlan_intf_opcode_current_connection to query various parameters of a specified interface. You could get a percentage value that represents the signal quality of the network from WLAN_ASSOCIATION_ATTRIBUTES structure.

Related

How to get number of cores of VM in azure [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to find an api or Microsoft inbuilt functions which can help me retrieve the number of cores in a particular VM
Unfortunately there's no straight forward way to get this information.
As far as REST API go, you would need to make 2 API calls:
Get Virtual Machine: First API you would need to call is get the details about your VM using Virtual Machines - Get. The properties that are of interest to you are the location of the VM and VM Size Type.
Get Resource SKU: This is the next API you would need to call using Resource Skus - List. This will give you the details about all the VM SKUs. Now this is going to be a very long list and unfortunately very limited filtering capability is available (at least at the time of answering this question). Only filtering capability available is that by location (that's why getting location information in the 1st step is important).
Once you get the list of all available SKUs, you will need to first filter out by resourceTypes where the value is virtualMachines and name where the value is the VM Size Type obtained in the 1st step.
Once you do that, the number of cores can be obtained in vCPUs attribute under capabilities property.
Here you go:
GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/vmSizes?api-version=2019-07-01
edit: if you need it for the running VM you need to get the hardware profile of the VM and use that first call to determine the number of cores. But its kinda static, so you might as well hardcore the results

Read data from serial port and keep track of most recent lines read [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Here is my problem. I have about 20 different types of messages coming in through a port. they can all be identified and come in at different rates (some come multiple times per second, some once every couple of seconds.)
I need to keep a log of these items, but only log them every 30 minutes. I would like to constantly read the port, and update an array of some sort. then when the timer event occurs, log the data from the array.
I am doing this in C# .net 4.5.2
You can use a dictionary of lists to organize this type of in-memory log. If you create say
public enum EventTypes
{
A,
B
};
and assuming your data points are integers, you could use
Dictionary<EventTypes, List<int>> inMemoryLog = new Dictionary<EventTypes, List<int>>();
Then you could log like this:
inMemoryLog[EventTypes.A].Add(myDataPoint);
When you're ready to flush the log to memory, persist the inMemoryLog to disk, removing each entry that you have written out. It may be a good strategy to create a copy of inMemoryLog to use to write to disk (and then re-initialize the imMemoryLog instance you use for logging) so that in-memory logging can continue without interruption.

How to turn wireless radio on/off in Windows? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm looking for an API to programmatically toggle a wireless radio on and off in Windows, just like the following Windows 10 UI element does:
Need to toggle on/off Wi-Fi, Bluetooth, or mobile broadband
For Windows 7, 8 and 10
This is NOT a phone
C#/.NET4.5 would be ideal, but C++/Win32 would work too
For Windows 10, you can use the Radio Manager APIs to control different radio states. You can find the full sample apps here (both C# and C++).
First you need to get access to all of the system radios. This must be called in a UI thread:
var accessLevel = await Radio.RequestAccessAsync();
Then, you can find all radios on the system (the sample describes other ways to access the radios):
var radios = await Radio.GetRadiosAsync();
Given a radio object, you can then change state by the following:
Radio radio = SOME_RADIO;
radio.StateChanged = Radio_StateChangedCallback; // Called when the radio state completes the change
radio.SetStateAsync(RadioState.On); // Or RadioState.Off
So in general what you need to do is to enumerate the network adapters (filter out Wireless, Bluetooth and Mobile Broadband) and toggle their state?
No wonders that there are 3 close votes since SO is full of related questions and answers:
This demonstrates C# + WMI
This demonstrates C++ + WINAPI Device Installation API
One of those should be a fair starting point to put together what you need.
Well I know you can manipulate the wireless connection with
netsh interface set interface name="Local Area Connection" via cmd line.
So maybe in c# you could do a Process.Start("netsh", "set name=\"Local Area Connection\""); to change the wifi settings. I'm sure you could download a bluetooth cmd line utility and do something similar with that.
I'll be able to test later when I get on my windows machine, but I can't right now, hopefully this helps.

How to determine on which monitor will my applications run? c# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
On my computer I have two monitors(regular one and usb elo display) and I wont my application only opens on usb display...any idea?
You have to use Screen class. It provides information about number of screens, which one is a primary screen etc. It also has the following method Screen.FromControl. It returns information about the screen that contains the largest part of the application. You can run it on the startup. If the method returns usb display then you should move the application to the second screen. See also this question.
Here is an example that verifies if the current screen is the primary one. If not it finds it and changes the location of the application based on the bounds of the found primary screen. You can also use DeviceName to determine if the current screen is the correct one.
var current = Screen.FromControl(this);
if (!current.Primary) //you can also use device name e.g." s.DeviceName.Contains("...")
{
var primary = Screen.AllScreens.Single(s => s.Primary);
SetBounds(primary.Bounds.Left, primary.Bounds.Top, Width, Height);
}
You should get the rectangle of required monitor first:
Rectangle rect = Screen.AllScreens[n].WorkingArea; //n stands for the index of monitor you'd like to use
Then you should invoke the Windows API SetWindowPos to move it via Process.MainWindowHandle.

How to release a communication port in C# (RS-232 COM port) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
My program uses a serial communication port such as COM1. But sometimes this port get locked in a port in use state because of a program failure or something else.
Suppose that another software use it. Can I force using that port?
I would like to use that port anyway. Is it possible?
#MaxMommersteeg if there is method such as DLL func ,WinApi it would be great.
It isn't hard getting the available COM ports, and it is easier than you think.
public List<string> GetAllAvailableComPorts()
{
return System.IO.Ports.SerialPort.GetPortNames().ToList();
}
Refer to Get Port Names Method (MSDN) for the GetPortnames method.
The code above will return you a List<string> filled with all available COM ports.
You can call it with code below:
//Create new list<string>
List<string> availableComPorts = new List<string>();
//Fill list with list<string> returned from GetAllAvailableComports method.
availableComPorts = GetAllAvailableComports();
All COM ports in the list are available, and COM ports that are currently in use will not appear in the list. You can use the List<string> to check if COM1 is available. If so, you can connect to it, and if not, you can give the user a message that it is in use (users will get an "Acces denied" message when connecting to an unavailable port.)
I think you are using Windows Forms, since you tagged C# and SerialPort and I don't think ASP and WPF are able to use the SerialPort class (correct me if I am wrong). So I would create a listbox, filled with all available COM ports and let the user choose which COM port to use. The user isn't able to pick the wrong COM port, since they aren't in the list.
If you need more information about this, you can just leave a comment below. I still got enough code in head left since my last created application which used a serialport connection as well.
I would like to refer you to my own question below. It has some more information:
Get list of available COM ports

Categories