Wednesday, October 23, 2013

[VB.NET] Basic Modem Communication (Initializing a ZTE MF627 Modem)

This article is based on my unfinished(again) project called the "Project Dashboard Clone" :D. The project aims to make a modem dashboard to be a lot simpler, removing most features of an official dashboard so I/you can include this module to your project that is related to modem, internet, vpn etc. Unfortunately I stopped the project because I only have a ZTE modem and my actual plan was to release a universal dashboard that supports ZTE and Huawei modems which are the only available devices that currently distributed here in my country by the telecom companies.

Temporarily I will only give minor codes and concept. Other codes are to follow for I'm not the one who wrote them.

Ok let's start!

First rule. You can't communicate with the modem or it doesn't get detected unless the CD drive that is loaded at first insert of the device gets ejected.

Dim CDROMDeviceQuery As New SelectQuery("Win32_CDROMDrive")
Dim CDROMDeviceSearch As New ManagementObjectSearcher(CDROMDeviceQuery)
Dim CDROMDeviceInfo As ManagementObject
For Each CDROMDeviceInfo In CDROMDeviceSearch.Get()
 If CDROMDeviceInfo("caption").ToString.Contains("ZTE") Then
   Dim tst As New VolumeEject
   tst.Eject(CDROMDeviceInfo("drive").ToString.Replace(":", ""))
 End If
Next

The code above will try to enumerate all available DVD/CD ROM drives in your computer and search for the ZTE CD drive, then ejects it. After it ejects the drive, the modem will then be detected and you can start using it.

Now that the modem is available and ready we will now try to initialize it. In this example I'm going to put the port number manually but of course the best way is to enumerate all ports especially if you have multiple modems installed.

Dim serialport As New IO.Ports.SerialPort
With serialport
 .PortName = "COM14"
 .BaudRate = 96000
 .Parity = Parity.None
 .DataBits = 8
 .StopBits = StopBits.One
 .Handshake = Handshake.RequestToSend
 .ReadTimeout = 300
 .WriteTimeout = 300
 .Encoding = Encoding.GetEncoding("iso-8859-1")
 .DtrEnable = True
 .RtsEnable = True
 .NewLine = vbCrLf
End With
serialport.Open()

TO BE CONTINUED... LOL

Unknown

I'm a modern human swiss knife. Not sure why I'm a coder I can't even rember the simplest syntax in any language lol. But I'll do anything for food so yeah I'm a programmer. And a fast one *wink*

0 comments:

Post a Comment

 

Copyright 2017 Code Monkey