473,469 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
Create 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.Threading 'Para elaboração da função OnComm
Imports System.Diagnostics 'Para utilização da função para contar o nº de 'elementos de um array


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub InitComPort()

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

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

Me.AxMSComm1.PortOpen = False

End If

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

Me.AxMSComm1.Settings = "9600, n, 8, 1"

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

Me.AxMSComm1.RTSEnable = True '????

Me.AxMSComm1.Handshaking = MSCommLib.HandshakeConstants.comNone 'Não é utilizado o handshaking - 'garantia de não perder dados

Me.AxMSComm1.InputMode = MSCommLib.InputModeConstants.comInputModeText 'Usa-se a linha de 'comunicações para entradas de arrays de bytes

Me.AxMSComm1.InputLen = 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.NullDiscard = False 'Garante que os bytes nulos não 'são desprezados

'************************************************* **********
'* 'com.OnComm += new System.EventHandler(this.OnComm)
'* 'QUAL O OBJECTIVO DESTA LINHA DE COMANDOS???
'************************************************* **********
Me.AxMSComm1.PortOpen = True

End Sub

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

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

Thread.Sleep(200)

If Me.AxMSComm1.InBufferCount > 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.Input)
'ProcessResponseBinary(b1)

Dim response As String = Convert.ToString(Me.AxMSComm1.Input) 'Processa-se os dados em modo de 'texto
ProcessResponseText(response)

Catch ex As Exception

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

End Try

End If

End Sub

Private Sub ProcessResponseBinary(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.Length - 1) 'Percorre-se o array de bytes 'elemento a elemento

RichTextBox1.AppendText(Convert.ToString(response( i)) + " ")

Next

RichTextBox1.AppendText("\n")

End Sub

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

If input.Trim() = "RING" Then

RichTextBox1.Clear()
RichTextBox1.Text = "Ring..."

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

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

Else

MessageBox.Show(input.Trim(), "Falha na ligação!", MessageBoxButtons.OK, MessageBoxIcon.Information)
RichTextBox1.Text = input.Trim()

End If

RichTextBox1.AppendText(input + "\n")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

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

MessageBox.Show("Especifique o nº GSM!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)

TextBox1.Focus()

Return

End If

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

Me.AxMSComm1.PortOpen = True 'Abre-se

End If

Dim gsm_command As String = "ATD" 'ATD - Attention Dial
Dim phone_number As String = TextBox1.Text.Trim()
Dim command1 As String = gsm_command + phone_number + "\n"
Dim command_to_dial() As Byte = System.Text.ASCIIEncoding.Default.GetBytes(command 1)

Me.AxMSComm1.Output = command_to_dial

RichTextBox1.Clear()
RichTextBox1.Text = "Dialing..."

End Sub



Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

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

Me.AxMSComm1.PortOpen = False 'Fecha-se

MessageBox.Show("Disconnected...", "", MessageBoxButtons.OK, MessageBoxIcon.Information)

RichTextBox1.Clear()

End If

End Sub



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim msg As String = ""

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

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

Return

End If

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

Me.AxMSComm1.PortOpen = True 'Abre-se

End If

msg = TextBox2.Text.Trim() + "\n"

Me.AxMSComm1.Output = System.Text.ASCIIEncoding.Default.GetBytes(msg)

RichTextBox1.Clear()
RichTextBox1.Text = "Message Sent..."

End Sub

End Class



Best Regards.
Oct 15 '08 #1
0 1632

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

Similar topics

0
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...
1
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...
1
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...
5
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...
6
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...
4
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...
5
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...
2
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. ...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.