473,698 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connection between two GSM Modems using RS232

4 New Member
I'm a rookie with C# and VB programming languages, but I need to make a connection of two GSM Modems for Remote Monitoring. I've done some web research and i've found a C# code to make the two modems dialing. I converted that code to VB but something's wrong... When i run the program, there's an error and i can't find it's origins. Could someone help me?

Code in VB:

Imports System
Imports System.Windows
Imports System.Threadin g 'Para elaboração da função OnComm
Imports System.Diagnost ics 'Para utilização da função para contar o nº de 'elementos de um array


Public Class Form1

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

End Sub

Private Sub InitComPort()

Me.AxMSComm1.Co mmPort = 1 'Porta de comunicações a alterar

If Me.AxMSComm1.Po rtOpen = True Then 'Caso a porta de 'comunicações esteja aberta, procede-se ao seu fecho

Me.AxMSComm1.Po rtOpen = False

End If

Me.AxMSComm1.RT hreshold = 1 'Abre-se a porta de comunicações 'sempre que se recebem dados

Me.AxMSComm1.Se ttings = "9600, n, 8, 1"

'Me.AxMSComm1.D TREnable = true 'Usa-se quando se pretende manter o modem em espera

Me.AxMSComm1.RT SEnable = True '????

Me.AxMSComm1.Ha ndshaking = MSCommLib.Hands hakeConstants.c omNone 'Não é utilizado o handshaking - 'garantia de não perder dados

Me.AxMSComm1.In putMode = MSCommLib.Input ModeConstants.c omInputModeText 'Usa-se a linha de 'comunicações para entradas de arrays de bytes

Me.AxMSComm1.In putLen = 0 'Procede-se à leitura de todos os dados 'que se encontram em espera quando ocorre entrada de dados através da porta 'de comunicações

Me.AxMSComm1.Nu llDiscard = False 'Garante que os bytes nulos não 'são desprezados

'************** *************** *************** ***************
'* 'com.OnComm += new System.EventHan dler(this.OnCom m)
'* 'QUAL O OBJECTIVO DESTA LINHA DE COMANDOS???
'************** *************** *************** ***************
Me.AxMSComm1.Po rtOpen = True

End Sub

'************** *************** *************** *************** *************** *******
'* !!!!!!FUNÇÃO OnComm!!!!!!
'************** *************** *************** *************** *************** *******

Private Sub OnComm(ByVal sender As System.Object, ByVal e As System.EventArg s)

Thread.Sleep(20 0)

If Me.AxMSComm1.In BufferCount > 0 Then

Try

'Caso se pretenda receber os dados em modo binário, devem-se 'tirar de comentário as duas linhas abaixo e colocar em comentário as linhas 'para processamento em modo de texto

'Dim b1 As Byte = Convert.ToByte( Me.AxMSComm1.In put)
'ProcessRespons eBinary(b1)

Dim response As String = Convert.ToStrin g(Me.AxMSComm1. Input) 'Processa-se os dados em modo de 'texto
ProcessResponse Text(response)

Catch ex As Exception

MessageBox.Show (ex.Message, "Falha no processamento dos 'dados recebidos!", MessageBoxButto ns.OK, MessageBoxIcon. Information)

End Try

End If

End Sub

Private Sub ProcessResponse Binary(ByVal response() As Byte) 'Função 'para apresentação dos dados recebidos na caixa de texto

Dim i As Integer

For i = 0 To (response.Lengt h - 1) 'Percorre-se o array de bytes 'elemento a elemento

RichTextBox1.Ap pendText(Conver t.ToString(resp onse(i)) + " ")

Next

RichTextBox1.Ap pendText("\n")

End Sub

Private Sub ProcessResponse Text(ByVal input As String) 'Processamento 'de dados recebidos em modo de texto

If input.Trim() = "RING" Then

RichTextBox1.Cl ear()
RichTextBox1.Te xt = "Ring..."

ElseIf input.Trim() = "CONNECT 9600" Then

MessageBox.Show (input.Trim(), "Ligação conseguida!", MessageBoxButto ns.OK, MessageBoxIcon. Information)

Else

MessageBox.Show (input.Trim(), "Falha na ligação!", MessageBoxButto ns.OK, MessageBoxIcon. Information)
RichTextBox1.Te xt = input.Trim()

End If

RichTextBox1.Ap pendText(input + "\n")

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click

If TextBox1.Text.T rim() = "" Then 'Caso não se tenha introduzido o nº 'GSM

MessageBox.Show ("Especifiqu e o nº GSM!", "", MessageBoxButto ns.OK, MessageBoxIcon. Information)

TextBox1.Focus( )

Return

End If

If Not Me.AxMSComm1.Po rtOpen Then 'Caso a porta de 'comunicações não esteja aberta

Me.AxMSComm1.Po rtOpen = True 'Abre-se

End If

Dim gsm_command As String = "ATD" 'ATD - Attention Dial
Dim phone_number As String = TextBox1.Text.T rim()
Dim command1 As String = gsm_command + phone_number + "\n"
Dim command_to_dial () As Byte = System.Text.ASC IIEncoding.Defa ult.GetBytes(co mmand1)

Me.AxMSComm1.Ou tput = command_to_dial

RichTextBox1.Cl ear()
RichTextBox1.Te xt = "Dialing... "

End Sub



Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button3.Click

If Me.AxMSComm1.Po rtOpen Then 'Caso a porta de comunicações 'esteja aberta

Me.AxMSComm1.Po rtOpen = False 'Fecha-se

MessageBox.Show ("Disconnected. ..", "", MessageBoxButto ns.OK, MessageBoxIcon. Information)

RichTextBox1.Cl ear()

End If

End Sub



Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click

Dim msg As String = ""

If TextBox2.Text.T rim() = "" Then 'Caso não se esteja a enviar 'qualquer mensagem

MessageBox.Show ("Please specify command!", "", MessageBoxButto ns.OK, MessageBoxIcon. Information)
TextBox2.Focus( )

Return

End If

If Not Me.AxMSComm1.Po rtOpen Then 'Caso a porta de comunicações 'esteja fechada

Me.AxMSComm1.Po rtOpen = True 'Abre-se

End If

msg = TextBox2.Text.T rim() + "\n"

Me.AxMSComm1.Ou tput = System.Text.ASC IIEncoding.Defa ult.GetBytes(ms g)

RichTextBox1.Cl ear()
RichTextBox1.Te xt = "Message Sent..."

End Sub

End Class



Best Regards.
Oct 15 '08 #1
0 1644

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1433
by: Bootstrap Bill | last post by:
Does anyone know if there is a Microsoft .net library for working with voice modems? Also, do standard voice modems support speach recognition? I want to write a menu system for voice modems that is also speach enabled if possible.
1
3978
by: Daniel Passwater via DotNetMonster.com | last post by:
I've written an app in C# in the compact framework. I've got a serial connection with a device running embedded C. We are using no flow control. That's not optional at this point. We are talking at 19200 baud, 8 bits, no parity, one stop bit. I can't get stable communication into my side. Symptoms: If we put interrupts in the embedded C (also not an option), I get my data just fine. However, without the interrupts, I only get the first byte....
1
4289
by: Jonas Hei | last post by:
I need to develop support for communications using modems (AT compatible modems) in my application? Where do I start? Would you recommend using TAPI? Or would it be a better idea to directly access com port and use AT commands for dialing out, etc? Any other approach?
5
3376
by: delimiter | last post by:
Okay, this problem is a problem that arose out of .NET coding rather than a hardware problem. I have a hard time trying to figure out how I can determine the port the modem is connected to, in Win 98 en ME using the registry entries. This is n0t a problem with Win 2K and XP. Neither with Win NT4 with WMI installed. With WMI, I can determine this with the following registry key:
6
9131
by: Ken Breit | last post by:
I am using the RS232.vb class to talk to the serial port. The problem I am having is when I try to read if anything is on the comm port. I call the read method, with the number of bytes I am expecting to read. As long as I know the length of the command that I will be getting on the input of the port it works great. The problem is when I don't know how long the data I am receiving is. If I request more bytes than I know I am getting...
4
5501
by: Dave Harry | last post by:
I found the RS232 class from MS's 101 VB samples. Writing to the port works fine. (I've got hyperterminal on the other comm port and a crossover cable between COM1 and COM2) The port is opened with: Public switchcom As New Rs232 switchcom.Open(2, 57600, 8, Rs232.DataParity.Parity_None, Rs232.DataStopBit.StopBit_1, 512)
5
5140
by: sreeramravi | last post by:
I would like to programatically check the connection speed at which a user has connected. Based on the connection speed, I would like to launch an application with specific parameters. Is there a way to do this in WMI / VBS / C++ / Win API ?
2
5495
by: egress | last post by:
Forgive me for stupid questions for I am new to serial IO programming. I am developing an app that will need to communicate with a device via RS232 protocol using a standard 9 pin serial cable. From what I understand this can be accomplished relativly easy using .net 2.0 SerialPort component over a COM port. My question: because most newer computers don't have 9 pin serial ports (COM), can the SerialPort component use a USB connection...
1
5135
by: theVOID1 | last post by:
Hi guys! Im building an application where I want to be able to have 3 USB UMTS modems in one computer. Does anyone have experience in using several modems at the same time? I also want them to be able to be up and runninng at the same time,each connected to a different network through VPN tunnels. So far, I have connected two Option Globetrotter Mini PCI Express cards with USB cradles (this is the option embedded development kit) But...
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7732
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.