Reading GPS reading using serial library - gps

I am using python to read NMEA values from GPS sensor. I am unable to understand the difference between
str1 = serial.readline(serial.in_waiting).decode()
and
str1 = serial.readline().decode()
When using 1, the code executes faster but when I use 2, its slower. It would be helpful to understand whats the difference in behavior between these commands.
Thanks in advance.

Related

How to get a halide buffer with data on GPU?

I'm new to halide. Now I have a pointer which points to data on GPU. I want to get a halide buffer from this pointer without copying data. I have searched a lot and found this /halidebuffer-on-gpu . It says using Buffer::device_wrap_native will be helpful. And I have read the docs of itBuffer::device_wrap_nativeBut I'm little confused about what value should I pass to device_interface? docs of device_interface don't help me much.
For device_interface you want to pass either halide_cuda_device_interface(), or halide_opencl_device_interface(), or similar. These methods are all defined in HalideRuntime*.h. Here's the full list:
HalideRuntimeCuda.h: halide_cuda_device_interface();
HalideRuntimeD3D12Compute.h: halide_d3d12compute_device_interface();
HalideRuntimeHexagonDma.h: halide_hexagon_dma_device_interface();
HalideRuntimeHexagonHost.h: halide_hexagon_device_interface();
HalideRuntimeMetal.h: halide_metal_device_interface();
HalideRuntimeOpenCL.h: halide_opencl_device_interface();
HalideRuntimeOpenGL.h: halide_opengl_device_interface();
HalideRuntimeOpenGLCompute.h: halide_openglcompute_device_interface();

VB.net sending/recieving AT commands from SIM Card

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.

How do I read the position data from a GPS (NMEA) device?

I'm trying to read data from a GPS device (NMEA). I am getting the data successfully. However, as soon as I start using it, it gives me gibbirish. This is what I get from the GPS:
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPRMC,120556.000,A,2546.0985,S,02816.0193,E,0.22,276.44,291013,,,A*7A
$GPGGA,120557.000,2546.0984,S,02816.0191,E,1,11,0.8,1396.3,M,21.5,M,,0000*71
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPGSV,3,1,12,31,50,165,19,14,48,055,27,16,43,304,42,32,36,265,38*76
$GPGSV,3,2,12,29,24,119,31,06,19,355,34,20,14,238,41,25,10,138,19*78
$GPGSV,3,3,12,27,09,351,33,22,06,008,36,03,05,341,36,23,,221,*7F
$GPRMC,120557.000,A,2546.0984,S,02816.0191,E,0.17,274.76,291013,,,A*7D
$GPGGA,120558.000,2546.0982,S,02816.0189,E,1,11,0.8,1396.0,M,21.5,M,,0000*72
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPRMC,120558.000,A,2546.0982,S,02816.0189,E,0.07,220.52,291013,,,A*7B
$GPGGA,120559.000,2546.0981,S,02816.0187,E,1,11,0.8,1395.7,M,21.5,M,,0000*7A
$GPGSA,A,3,20,25,31,22,14,29,03,16,32,06,27,,1.5,0.8,1.3*33
$GPRMC,120559.000,A,2546.0981,S,02816.018
The above was received by doing the following:
//inside a 100ms ticker
Dim data As String = GpsPort.ReadExisting()
CommentBox.AppendText(data)
As soon as I do Dim strArr() As String = data.Split("$") then output it using:
CommentBox.AppendText(strArr(0).ToString) // inside the same ticker
the output is:
034.000,2546.0985,S,02816.0298,E,1,11,0.8,1360.6,M,21.5,M,,0000*77
3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
MC,121034.000,A,2546.0985,S,02816.0298,E,0.01,236.13,291013,,,A*75
.000,2546.0983,S,02816.0297,E,1,11,0.8,1359.9,M,21.5,M,,0000*7A
A,A,3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
,121035.000,A,2546.0983,S,02816.0297,E,0.06,283.04,291013,,,A*72
036.000,2546.0982,S,02816.0296,E,1,11,0.8,1359.3,M,21.5,M,,0000*73
3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
MC,121036.000,A,2546.0982,S,02816.0296,E,0.03,190.30,291013,,,A*72
.000,2546.0981,S,02816.0296,E,1,11,0.8,1358.6,M,21.5,M,,0000*75
A,A,3,20,29,14,22,31,25,03,16,32,06,27,,1.5,0.8,1.3*33
3,1,12,31,49,161,28,14,46,052,20,16,45,301,39,32,36,268,35*79
3,2,12,29,23,122,18,06,21,355,27,20,15,240,40,27,11,351,37*78
Can anyone assist me in getting the GPS co-ordinates from the GPGGA strings? Because splitting them clearly doesn't work.
You have to read the data line by line.
Each line is one NMEA sentence.
Once you detect "$GPGGA" (or you also could use the RMC message)
you have this line:
$GPGGA,120557.000,2546.0984,S,02816.0191,E,1,11,0.8,1396.3,M,21.5,M,,0000*71
Now you splitt by delimiter ","
Then this is latitude : 2546.0984,S
And this is longitude 02816.0191,E
read at NMEA spec which format the coordinates are: I think: the first to digits in latitdue are degrees, the rest is minutes: 25° 46.0984 minutes. If "S" multiply the result with -1.
slightly different for longitude:
02816.0191,E
first 3 digits degrees, rest minutes. 27° 16.0191 minutes. multiply with -1 if "W".
Basically, the messages you are seeing are part of a rather complicated message format. Each part means something different and the meanings depend on the message type.
You may want to look at some of the code in this open source project. I wrote this library with a colleague and it parses out those messages from a specific GPS device, but it should work with pretty much any device putting out the same data.

Connecting a Matlab Neural Network with a VB.NET program

I developed a neural network to train for face detection of the extracted images. However my program is built on VB.NET and I need to know the techniques by which I could load this neural network (Exported using NNTOOL) into memory and call it from VB.NET
So far I was only able to find this,
Dim MatLab As Object
Dim Result As String
Dim MReal(1, 3) As Double
Dim MImag(1, 3) As Double
Dim RealValue As Double
MatLab = CreateObject("matlab.application")
Result = MatLab.Execute("a = [1 2 3 4; 5 6 7 8;]")
Call MatLab.GetFullMatrix("a", "base", MReal, MImag)
I do not quite understand how this works, any suggestions on whether I could conenct the Neural network to VB.NET using this code and if so could you please explain to me about the Matlab.Execute and Matlab.GetFullMatrix functions. (What arguements would it support
In this article, three possible solutions are described. If you don't care much about performance, go with the first solution (use COM interop). Else, go with the third option (PInvoke), which is the fastest one. If you do choose to use PInvoke, a great resource is PInvoke.net

Streaming non-PCM raw audio using NAudio

I'm hell bent on making this work with NAudio, so please tell me if there's a way around this. I have streaming raw audio coming in from a serial device, which I'm trying to play through WaveOut.
Attempt 1:
'Constants 8000, 1, 8000 * 1, 1, 8
Dim CustomWaveOutFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, SampleRate, Channels, AverageBPS, BlockAlign, BitsPerSample)
Dim rawStream = New RawSourceWaveStream(VoicePort.BaseStream, CustomWaveOutFormat)
'Run in background
Dim waveOut = New WaveOut(WaveCallbackInfo.FunctionCallback())
'Play stream
waveOut.Init(rawStream)
waveOut.Play()
This code works, but there's a tiny problem - the actual audio stream isn't raw PCM, it's raw MuLaw. It plays out the companding like a Beethoven's 5th on cheese-grater. If I change the WaveFormat to WaveFormatEncoding.MuLaw, I get a bad format exception because it's raw audio and there are no RIFF headers.
So I moved over to converting it to PCM:
Attempt 2:
Dim reader = New MuLawWaveStream(VoicePort.BaseStream, SampleRate, Channels)
Dim pcmStream = WaveFormatConversionStream.CreatePcmStream(reader)
Dim waveOutStream = New BlockAlignReductionStream(pcmStream)
waveOut.Init(waveOutStream)
Here, CreatePcmStream tries to get the length of the stream (even though CanSeek = false) and fails.
Attempt 3
waveOutStream = New BufferedWaveProvider(WaveFormat.CreateMuLawFormat(SampleRate, Channels))
*add samples when OnDataReceived()*
It too seems to suffer from lack of having a header.
I'm hoping there's something minor I missed in all of this. The device only streams audio when in use, and no data is received otherwise - a case which is handled by (1).
To make attempt (1) work, your RawSourceWaveStream should specify the format that the data really is in. Then just use another WaveFormatConversionStream.CreatePcmStream, taking rawStream as the input:
Dim muLawStream = New RawSourceWaveStream(VoicePort.BaseStream, WaveFormat.CreateMuLawFormat(SampleRate, Channels))
Dim pcmStream = WaveFormatConversionStream.CreatePcmStream(muLawStream);
Attempt (2) is actually very close to working. You just need to make MuLawStream.Length return 0. You don't need it for what you are doing. BlockAlignReductionStream is irrelevant to mu-law as well since mu law block align is 1.
Attempt (3) should work. I don't know what you mean by lack of a header?
In NAudio you are building a pipeline of audio data. Each stage in the pipeline can have a different format. Your audio starts off in Mu-law, then gets converted to PCM, then can be played. A buffered WaveProvider is used for you want playback to continue even though your device has stopped providing audio data.
Edit I should add that the IWaveProvider interface in NAudio is a simplified WaveStream. It has only a format and a Read method, and is useful for situations where Length is unknown and repositioning is not possible.