VB.net sending/recieving AT commands from SIM Card - vb.net

ok, so i have been using Vb for a while but brand new to communicating with devices.
I have a HP Elitebook 820 which has a SIM card slot, what id like to do is display the SIM card info - specifically the serial number. I have done a bit of searching and found lots of people talking about AT commands. after a bit more searching i gave it a try.
Dim com1 As SerialPort = New System.IO.Ports.SerialPort
com1.PortName = "COM6"
com1.Open()
If com1.IsOpen Then
com1.Write("AT+CIMI")
Dim result As String
result = com1.ReadExisting
MsgBox(result)
Else
MsgBox("port not open")
End If
No Errors but just blank string returned. Could anyone help me out by letting me know, first if this even possible and second am i going about it the right way?

Step 1. Fetch a copy of the V.250 modem standard and read at least all of chapter 5. That will teach you a lot of basic AT command handling, like for instance that an AT command line should be terminated with \r.
Step 2. The very best documentation is your modem manufacturer's specific documentation which you definitely should try to get hold of that, however for basic mobile phone commands like AT+CIMI you can use the 3GPP spec 27.007 as well (assuming the manufacturer has not deviated in its implementation. Sometimes they do for some commands so this is something to watch out for (hence my recommendation to first and foremost get the modem manufacturer's specific documentation). The AT+CIMI command is however so simple there is nothing to deviate from really.).
Step 3. The reception handling, e.g. result = com1.ReadExisting is way too simplistic. You MUST read and parse every single line of response from the modem until you get a Final result code back (most commonly OK or ERROR, but there are several others). Any other way cannot work reliably. See this answer for pseudo code structure of how to do it properly.

Related

SerialPort.ReadByte all of a sudden returns zero in stead of the version number of the attached cable

We use a USB to SerialPort converter for a long time now in our application. To check if the correct cable is attached we start with sending a command that requests the converter to return its version. We then read te returned data using
var version=SerialPort.ReadByte();
Which is expected to return &11 for version 1.1.
All of a sudden on Windows 10 1803 or later versions this checks starts to fail because ReadByte() returns first a zero then, when called a second time, &11.
This change in behaviour must be caused by a Windows update as we did not change this part of the code in years.
Can anyone shed some light on what might be going on? Is this a Windows 10 fluke that will be reversed soon, or is our implementation inherently wrong?
EDIT
I replaced ReadByte() with ReadExisting() and that came back with (in VB.Net) vbNullChar & vbNullChar & CharW(17).
So it seems that the first call to ReadByte returns the two nullchars and the second call returns the expected value of &11
EDIT
There is another, very likely cause as well: the two converters we used to test are from the same batch. They seemingly respond with two null chars the first time they are read.

nvmlDeviceGetPowerManagementMode() always returning NVML_ERROR_INVALID_ARGUMENT?

I am writing a code to measure the power usage of an NVIDIA Tesla K20 GPU (Kepler architecture) periodically using the NVML API.
Variables:
nvmlReturn_t result;
nvmlEnableState_t pmmode;
nvmlDevice_t nvmlDeviceID;
unsigned int powerInt;
Basic code:
result = nvmlDeviceGetPowerManagementMode(nvmlDeviceID, &pmmode);
if (pmmode == NVML_FEATURE_ENABLED) {
result = nvmlDeviceGetPowerUsage(nvmlDeviceID, &powerInt);
}
My issue is that nvmlDeviceGetPowerManagementMode is always returning NVML_ERROR_INVALID_ARGUMENT. I checked this.
The NVML API Documentation says that NVML_ERROR_INVALID_ARGUMENT is returned when either nvmlDeviceID is invalid or pmmode is NULL.
nvmlDeviceID is definitely valid because I am able to query its properties which match with my GPU. But I don't see why I should set the value of pmmode to anything, because the documentation says that it is a Reference in which to return the current power management mode. For the record, I tried assigning an enable value to it, but the result was still the same.
I am clearly doing something wrong because other users of the system have written their own libraries using this function, and they face no problem. I am unable to contact them. What should I fix to get this function to work correctly?
The problem here was not directly in the API call - it was in the rest of the code - but the answer might be useful to others. Before attempting this solution, one must know for a fact that Power Management mode is enabled (check with nvidia-smi -q -d POWER).
In case of the invalid argument error, it is very likely that the problem lies with the nvmlDeviceID. I said I was able to query the device properties and at the time I was sure it was right, but be aware of any API calls that modify the nvmlDeviceID value later on.
For example, in this case, the following API call had some_variable as an invalid index, so nvmlDeviceID became invalid.
nvmlDeviceGetHandleByIndex(some_variable, &nvmlDeviceID);
It had to be changed to:
nvmlDeviceGetHandleByIndex(0, &nvmlDeviceID);
So the solution is to either remove all API calls that change or invalidate the value of nvmlDeviceID, or at least to ensure that any existing API call in the code does not modify the value.

Does anyone know how to triangulate location using Arduino and SIM900?

I have a SIM900 and Arduino Leonardo. using the SIM900.h library I have it all working and receiving text messages, etc however I'm wondering how I can use it to either grab all the local tower information or grab the same and triangulate the LAT, LONG, ETC from that information.
You can get information about the local tower (and for a few neighboring towers) with the AT+CENG=2 command. This include things like tower ID and signal level. You'll need to know the geographic location of these towers and do the triangulation yourself.
I suggest you take a look at this project: http://www.open-electronics.org/mini-gsm-localizer-without-gps/. It has an open-source firmware that you may find useful.
Here’s sequence of AT commands needed to get location of module:
AT+SAPBR=3,1,"CONTYPE","GPRS" // set bearer parameter
OK
AT+SAPBR=3,1,"APN","internet" // set apn
OK
AT+SAPBR=1,1 // activate bearer context
OK
AT+SAPBR=2,1 // get context ip address
+SAPBR: 1,1,"10.151.43.104"
OK
AT+CIPGSMLOC=1,1 // triangulate
+CIPGSMLOC: 0,19.667806,49.978185,2014/03/20,14:12:27
OK
Location is not acurrate though, first test got me coordinates located around 4 kilometers away from my place. Usually it’s not that bad, enough for simple applications.
you can use AT+COPS? command to reach location of tower. the 4-digit number expresses the location. for decode the number yıu should use LAC.
i.e +CGREG: 1, A9F0, 200D6E
(the second term A9F0 is the location number of tower)

Creating robust real-time monitors for variables

We can create a real-time monitor for a variable like this:
CreatePalette#Panel#Row[{"x = ", Dynamic[x]}]
(This is more interesting and useful if x happens to be something like $Assumptions. It's so easy to set a value and then forget about it.)
Unfortunately this stops working if the kernel is re-launched (Quit[], then evaluate something). The palette won't show changes in the value of x any more.
Is there a way to do this so it keeps working even across kernel sessions? I find myself restarting the kernel quite often. (If the resulting palette causes the kernel to be automatically started after Quit that's fine.)
Update: As mentioned in the comments, it turns out that the palette ceases working only if we quit by evaluating Quit[]. When using Evaluation -> Quit Kernel -> Local, it will keep working.
Link to same question on MathGroup.
I can only guess, because on my Ubuntu here the situations seems buggy. The trick with the Quit from the menu like Leonid suggested did not work here. Another one is: on a fresh Mathematica session with only one notebook open:
Dynamic[x]
x = 1
Dynamic[x]
x = 2
gives as expected
2
1
2
2
Typing in the next line Quit, evaluating and typing then x=3 updates only the first of the Dynamic[x].
Nevertheless, have you checked the command
Internal`GetTrackedSymbols[]
This gives not only the tracked symbols but additionally some kind of ID where the dynamic content belongs. If you can find out, what exactly these numbers are and investigate in the other functions you find in the Internal context, you may be able to add your palette Dynamic-content manually after restarting the kernel.
I thought I had something like that with
Internal`SetValueTrackExtra
but I'm currently not able to reproduce the behavior.
#halirutan's answer jarred my memory...
Have you ever come across: Experimental/ref/ValueFunction? (documentation address)
Although the documentation contains no examples, the 'more information' section provides the following tidbit:
The assignment ValueFunction[symb] = f specifies that whenever
symb gets a new value val, the expression f[symb,val] should be
evaluated.

Get most frequently used applications in VB.NET

Is there a way that I can get the most used applications via VB.NET? I'm developing a sort of hobby project as a quick launcher kind of thing and thought this would sit perfectly on the main form.
If possible, would somebody be able to explain to me how add/remove applications manages to get the frequency of used applications? It would be good if I could get it in a list like the XP/Vista start menu as well.
Any guidance would be greatly appreciated. :)
It looks like you can find information on how often a program is run in the registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist\
There's more explanation here and a .NET program here that you could reverse engineer to get at the count values using VB.Net.
This might be a decent place to start. It seems like windows does a crappy job of determining frequency of applications use.
http://blogs.msdn.com/oldnewthing/archive/2004/07/09/178342.aspx
According to this posting the information is stored in the first 28 bytes of the SlowInfoCache Registry value found at the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Management\ARPCache
The format of the value is (in VB.Net):
Structure SlowInfoCache
Dim cLen As Integer ' size of the SlowInfoCache (552 bytes)
Dim Flag As Boolean ' has a name
Dim Size As Long ' program size in bytes
Dim LastUsed As Long ' API-style FILETIME
Dim Frequency As Integer ' 0-2 = rarely; 3-9 = occassionaly; 10+ = frequently
Dim Path As String ' remaining 524 bytes (max path of 260 + null) in unicode
End Structure
If you are interested in the other information displayed in Control Panel -> Add or Remove Programs you will find it listed for each product under the following Registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Or course these solutions only track when the shell (explorer.exe) is used to start a program via a shortcut (all start menu items are shortcuts). That's why it is so inaccurate.
FWIW I'm not aware of any microcomputer operating system that tracks the execution frequency of program images.
I suggest for your launcher tool that you initially popule it with the shortcuts from the quicklaunch bar and just make it really easy for the user to configure rather than trying to do anything automatic - automatic stuff that doesn't work in the way the user expects is one of the most annoying aspects of user interface design.
One question you should ask yourself is how are you going to determine frequency?
Are you going to base it on the number of times and application is run, or based on the length of time that an application is run for?