need help in sms project using vb .net - vb.net

I am doing a sms project using VB .net to connect to my gsm modem via serialport. All the connection and everything was working great and I can send and receive sms.
Then here come a problem, I need to send long sms more than 160 chars. I read and did some research and I know that I need to use the pdu and udh. I managed to understand slightly of the pdu packet but is still quite confuse on that part.
Anyone can briefly explain the exact way to do the concatented sms (long sms)?
Another problem is how can I use vb to encode the data into pdu gsm 7bit data? Is there any built in functions or do I need to write them myself?

This may help out with the concatenated SMS and GSM encoding, but I've never used a GSM modem so hopefully somebody else can fill in the gaps.
To convert your .NET string to a GSM encoded string, I've written an open-source library available on Github that might help you. However it doesn't do the 7 bit packing you might need.
For the long message support you need to add a User Data Header at the start of each message.
First split the message in to multiple parts each 153 GSM (7bit) bytes long. Don't forget that extended characters such as { take two bytes, see the GSM character set for a full list.
Then add the UDH bytes to the beginning that allow concatenation. I've put an example below for a two part message.
First SMS: 05 00 03 A6 02 01 .. bytes that make up the first part text..
Second SMS: 05 00 03 A6 02 02 .. bytes that make up the second part text..
Bytes Description
05 (UDHL) Length of the UDH. So the following five bytes are UDH
00 (IEI) This identifier says this is a concatenated message
03 (IEDL) It says that next 3 bytes are the data for this IE.
A6 Reference number of this concatenated message.
02 There are two parts to this concatenated message.
01or02 This indicates whether the SMS is the first or second part.
UHDL = User Data Header Length
IEI = Information Element Identifier (00 is a concatenated message)
IEDL = Information Element Data Length (A concatenated message header length is always 3)
For the reference number, the easiest way is just to assign an random number in the range 0-255, each part of the message must have the same reference number.

Related

Reading PLC register using ModBusTCPCom in .Net results in address not found

I have to update an old WinForms application. The application uses the AdvancedHMI .NET software.
I am connecting to the PLC (AutomationDirect DirectLogic 06 Series) with no issues, and various other registers are being read accurately.
I am expecting to get a 4 digit value from the register.
I am reading it like so:
Dim rawValue As String = BeltSpeedModbusTcpCom.Read("V3103")
When I read the register I get address not found.
The ladderlogic diagram I am was given is:
I have tried adjusting the address, using 03103, F3103, and other combinations. We can view the address values in real time in the PLC using software the customer has.
According to Page 4-13 of the DL-06 manual, the “V” register number is Octal. Try reading “1603”, which is octal 3103 converted to decimal.

Gps nmea output getting valid $GPGSV but not valid $GPGGA $GPRMC

I'm trying to parse gps nmea output from a modem connected to serial port of a cubietruck board (ARM® Cortex™-A7 Dual-Core). The configuration is done succesfully I get 4g network form modem but when I try to see nmea outout of the gps module, I get the following :
$GPRMC,,V,,,,,,,,,,N*53
$GPGSV,2,1,08,07,49.9,43.6,28.2,28,49.9,158.9,29.2,02,3.5,239.1,,05,49.9,286.9,E
$GPGSV,2,2,08,06,,,,08,9.8,68.9,,09,31.6,104.1,,13,20.4,299.5,,1*5E
$GNGNS,112218.9,,,,,NNN,,,,,,*03
$GPVTG,,T,,M,,N,,K,N*2C
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GNGSA,A,1,,,,,,,,,,,,,,,*00
$GPGGA,,,,,,0,,,,,,,,*66
$GPRMC,,V,,,,,,,,,,N*53
$GPGSV,2,1,08,07,49.9,43.6,27.9,28,49.9,158.9,29.7,02,3.5,239.1,,05,49.9,286.9,F
$GPGSV,2,2,08,06,,,,08,9.8,68.9,,09,31.6,104.1,,13,20.4,299.5,,1*5E
$GNGNS,112219.9,,,,,NNN,,,,,,*02
Looking in http://aprs.gids.nl/nmea/ I found that $GPGSV is GPS Satellites in view. So what I understand is that I get 2 satellites. Is this perhaps the case that I don't get valid $GPGGA $GPRMC or should I check something else?
You don't have a positional "fix" and therefore get empty values in some of the telegrams. As you probably know, there should be latitude, longitude and other data instead of empty values between the commas. Two satellites are not enough to get a fix, you need at least 3 or 4 to get the position.
The NMEA 0183 standard is weakly defined and doesn't mention what GPS units should do when they don't have a positional fix. Sending empty values is pretty common, but some units might act differently. You can easily tell whether the data is valid or not from the A and V letters. V means void and A means active. In the RMC telegram, you can see a V, meaning the entire thing is void.
The reason you get values in the GSV telegrams is because the GPS is able to see two satellites and therefore calculate the values needed in the telegram.
The third field, 08, is the theoretical number of satellites you would be able to see in good conditions.
So what you have to do is to take the GPS outdoors or connect it to a proper antenna. It will start sending proper values when it's able to see the satellites.
Actually by your two GPGSV sentences you can see 08 satellites - eight of them. You have 2 'sentences' of GSV 2,1,08 means 1 of 2 sentences describing 08 satellites, and 2,2,08 means 2 of 2 sentences describing 08 satellites

Confused by the report ID when using HIDAPI through USB

I am a USB HID newbie and I am trying to use the HIDAPI for my application.
I have a question about using HIDAPI (in Visual Studio) regarding the report ID.
When I try to use the HIDAPI and connect to the Microchip Custom Demo,
I am confused about this aspect: The 65-byte report does not make sense to me!
Even if I don't want to set a report ID, I need to set the first byte to 0 and send the 65-byte buffer to the device, but I only receive 64 bytes of data from the Microchip device (because the report is 64 bytes long).
It looks like:
**Host** **Device**
*write_hid*
65 byte --------------->
*read_hid*
<------------------ 64byte
However, it seems weird to me.
Isn't the report that is sent or received always 64 bytes? Because the specifications say the report should have a 64-byte maximum and be sent every 1 ms.
If the answer is yes, why does the API maintain 65 bytes for 1-byte report ID?
Is the report ID contained in the 64 bytes?
The 65-byte data length does not make sense to me.
If your application does not include a Report ID in the HID descriptor, then there shouldn't be a Report ID prepended.
As you can see in the documentation of hid_write, HIDAPI should only send 64-bytes if the first byte is 0 (i.e. there is no Report ID):
unsigned char data[65];
buf[0] = 0; /* Single report */
// Fill report starting at buf[1]
hid_write(device, data, sizeof(data));
When looking at the source code for the libusb implementation, you can see that the Report ID is correctly stripped. On Windows however, the data is passed straight to Windows. I don't know Windows programming, but perhaps this makes a difference. Try testing this on Linux instead.

usbmon, the usb spec and endianness/byte-order

I am trying to decipher a trace of USB I/O traffic produced by usbmon and am having some issues getting my head around the endianness. For the sake of example, here are two lines from the trace I am working with:
ffff8800650e7000 433121059 S Ci:2:000:0 s 80 06 0100 0000 0040 64 <
ffff8800650e7000 433121661 C Ci:2:000:0 0 18 = 12010002 00000040 da0b8781 00010102 0301
I initially had no suspicion whatsoever of anything other than big-endianness in the trace, but then I saw da0b8781 in the second line, which corresponds to the identity of the USB device I am tracing which has a vendor ID of 0x0bda and product ID of 0x8187 (note the reversal of byte-order in the trace).
So at this point I thought that maybe within a given field of a usbmon trace, the bytes were always in reverse byte order and should be interpreted as such. But to the contrary, let's examine a small part near the end of the first trace line, ... 0040 64
0040 is a hex field representing the maximum accepted response size. 64 is a decimal field that should represent exactly the same thing. 0x0040 = 64 decimal, without switching the byte order to 0x4000, which would then != 64 decimal. So it's at this point I started to get a bit uncertain about the byte-order of the different parts of the usbmon trace.
Next I thought, maybe it's just the data portions of the usbmon trace that are in reverse byte order. So I thought perhaps I should really be reading
...12010002 00000040 da0b8781 00010102 0301
as
1030 20101000 1878b0ad 04000000 20001021...
Nope, that doesn't seem to be right either. The USB Specification states that the vendor Id (0x0bda in my case) should be at byte offset 8 for this particular string. If we leave the above string in its original order, then the vendor Id does start at byte offset 8 (12010002 00000040 consumes the first 8 bytes), but if we reverse it as I have above, then it starts at byte offset 6 (1030 20101000 only consumes the first 6 bytes).
So my best guess now is that usbmon displays everything big-endian, accept that it switches to reverse byte order within each 4-byte word, but for data only. Can anyone offer some clarification on whether this is correct, or whether there may be something else I'm missing?
May be a bit late for you but I've tried usbmon (and found it OK)
you may want to take a look at evtest
http://www.freedesktop.org/wiki/Evtest

Reading Packet Id from Byte

I have a packet that I need to send to a client with an ID of 255. I've had no problems sending packets with IDs of 0, 1, and 2. The ID has to be 255. For some reason, after the translation has happened, both me with my server, and the client, get "63" for any Id greater than 127.
This is the code I am using:
Console.WriteLine(Asc(System.Text.ASCIIEncoding.ASCII.GetString(System.Text.ASCIIEncoding.ASCII.GetBytes(Chr("255")))))
Now, This is an overly complicated version of what the server does. You may consider this a bit unnecessary but the inverse functions performed are for your viewing reasons only.
Where it says "255" is the Packet Id I need sent in the format above. As I said, anything larger than 127 returns "63". Very annoying.
Any help is appreciated.
Taken from here:
ASCIIEncoding corresponds to the Windows code page 20127. Because ASCII is a 7-bit encoding, ASCII characters are limited to the lowest 128 Unicode characters, from U+0000 to U+007F.
So you can't use that technique, because 255 is not a valid ASCII character.