Welcome to Dream.In.Code
Become an Expert!

Join 137,212 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,264 people online right now. Registration is fast and FREE... Join Now!




open port attached with gsm modem in asp.net

 
Reply to this topicStart new topic

open port attached with gsm modem in asp.net

skmastanvali
14 Jul, 2008 - 04:37 AM
Post #1

New D.I.C Head
*

Joined: 14 Jul, 2008
Posts: 1

Hi All

I wanted to develop a web application using asp.net. I wanted code to open the port which was attached by a GSM Modem

Advance Thanks.
...SK.mastan Vali
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Open Port Attached With Gsm Modem In Asp.net
14 Jul, 2008 - 04:41 AM
Post #2

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,557



Thanked: 99 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
User is online!Profile CardPM
+Quote Post

thekenyanprince
RE: Open Port Attached With Gsm Modem In Asp.net
6 Sep, 2008 - 07:25 AM
Post #3

New D.I.C Head
*

Joined: 6 Sep, 2008
Posts: 1

QUOTE(gabehabe @ 14 Jul, 2008 - 05:41 AM) *

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.

this works well with desktop vb.net but it doesnt work for asp.net. i wrote it myself.
CODE

Public Class Phone
    Private StatusValue As String = "Ready"
    Private ComPort As IO.Ports.SerialPort
    Private SendNextMessage As Boolean = False
    Private PortOpenValue As Boolean = False
    Private TextEnabledValue As Boolean
    Private ComResponse As New Response
    Private ReadNextMessage As Boolean = False
    Private ListMessages As Boolean = False
    Private messageRead As Boolean = True
    Private ready As Boolean = True
    Private InboxValue As New ArrayList
    Private OutboxValue As New ArrayList
    Private InboxReadValue As New ArrayList
    Private InboxUnreadValue As New ArrayList
    Private ReceivedValue As New ArrayList
    Private DraftsValue As New ArrayList
    Private SentValue As New ArrayList
    Private Delegate Sub ReadResponseDelegate()
    Private Delegate Sub SendCommandDelegate(ByVal CommandValue As String, ByVal Delay As Boolean)
    Private WriteCommand As New SendCommandDelegate(AddressOf SendCommand)
    Private SerialPortNames As New List(Of String)

    Public Sub New()
        SerialPortNames.Clear()
        For index As Integer = 1 To My.Computer.Ports.SerialPortNames.Count
            SerialPortNames.Add(My.Computer.Ports.SerialPortNames(index - 1))
        Next
    End Sub

    Public ReadOnly Property SerialPorts() As List(Of String)
        Get
            Return SerialPortNames
        End Get
    End Property

    Public ReadOnly Property TextEnabled() As Boolean
        Get
            Return TextEnabledValue
        End Get
    End Property

    Public ReadOnly Property Inbox() As ArrayList
        Get
            Return InboxValue
        End Get
    End Property

    Public ReadOnly Property Outbox() As ArrayList
        Get
            Return OutboxValue
        End Get
    End Property

    Public ReadOnly Property InboxRead() As ArrayList
        Get
            Return InboxReadValue
        End Get
    End Property

    Public ReadOnly Property InboxUnread() As ArrayList
        Get
            Return InboxUnreadValue
        End Get
    End Property

    Public ReadOnly Property Received() As ArrayList
        Get
            Return ReceivedValue
        End Get
    End Property

    Public ReadOnly Property Drafts() As ArrayList
        Get
            Return DraftsValue
        End Get
    End Property

    Public ReadOnly Property Sent() As ArrayList
        Get
            Return SentValue
        End Get
    End Property

    Public ReadOnly Property Status() As String
        Get
            Return StatusValue
        End Get
    End Property
    Public ReadOnly Property PortIsOpen() As Boolean
        Get
            Return PortOpenValue
        End Get
    End Property

    Public ReadOnly Property FullResponse() As String
        Get
            Return ComResponse.FullResponse
        End Get
    End Property

    Public ReadOnly Property Response() As Response
        Get
            Return ComResponse
        End Get
    End Property

    Public Sub ReadAllMessages()
        Try
            InboxValue.Clear()
            OutboxValue.Clear()
            InboxReadValue.Clear()
            InboxUnreadValue.Clear()
            SentValue.Clear()
            DraftsValue.Clear()
            ListMessages = True
            WriteCommand.Invoke("AT+CMGL" & vbCrLf, True)
        Catch ex As Exception

        End Try
    End Sub
    Public Sub Connect(ByVal port As String)
        ComPort = My.Computer.Ports.OpenSerialPort(port, 9600)
        If ComPort.IsOpen = True Then
            PortOpenValue = True
        Else
            PortOpenValue = False
        End If

        ComPort.ReadExisting()

        Dim GetResponse As New ReadResponseDelegate(AddressOf ReadResponse)
        GetResponse.BeginInvoke(Nothing, Nothing)

        WriteCommand.BeginInvoke("AT" & vbCrLf, False, Nothing, Nothing)

        Try
            WriteCommand.Invoke("AT+CMGF=1" & vbCrLf, True)
        Catch
            TextEnabledValue = False
        End Try
    End Sub

    Sub Disconncect()
        ComPort.Close()
        If ComPort.IsOpen = False Then
            PortOpenValue = False
        Else
            PortOpenValue = True
        End If
    End Sub

    Public Sub DialNumber(ByVal number As String)
        WriteCommand.Invoke("AT+DT" & number & vbCrLf, True)
    End Sub

    Public Sub SaveTextMessage(ByVal text As String, ByVal number As String)
        SendNextMessage = False
        WriteCommand.Invoke("AT+CMGW=""" & number & """" & Microsoft.VisualBasic.ChrW(13) & text & Microsoft.VisualBasic.ChrW(26), True)
    End Sub

    Public Sub SendTextMessage(ByVal text As String, ByVal number As String)
        SendNextMessage = True
        WriteCommand.Invoke("AT+CMGW=""" & number & """" & Microsoft.VisualBasic.ChrW(13) & text & Microsoft.VisualBasic.ChrW(26), True)
    End Sub

    Public Sub SendSavedMessage(ByVal number As Integer)
        WriteCommand.Invoke("AT+CMSS=" & number & vbCrLf, True)
    End Sub

    Public Function ReadMessage(ByVal number As String) As TextMessage
        WriteCommand.Invoke("AT+CMGR=" & number & vbCrLf, True)
        ComResponse.TextMessage = New TextMessage(number, "", "")
        messageRead = False
        Do
            If messageRead = True Then
                Exit Do
            End If
        Loop
        Return ComResponse.TextMessage
    End Function

    Private Sub ReadResponse()
        Do
            ComResponse.Incoming = ComPort.ReadLine
            If ComResponse.Incoming Is Nothing Then
                Exit Do
            ElseIf Microsoft.VisualBasic.Asc(ComResponse.Incoming) = 13 Then

            Else
                StatusValue = "Busy"
            End If

            If Microsoft.VisualBasic.Left(ComResponse.Incoming, 6) = "+CMGW:" And SendNextMessage = True Then
                ComResponse.TextMessage = New TextMessage((Replace(ComResponse.Incoming, "+CMGW:", "")), "", "")
            End If

            If Microsoft.VisualBasic.Left(ComResponse.Incoming, 2) = "OK" Then
                ReadNextMessage = False
                messageRead = True
            End If

            If Microsoft.VisualBasic.Left(ComResponse.Incoming, 6) = "+CMGL:" And ReadNextMessage = True Then
                If ListMessages = True Then
                    If ComResponse.TextMessage.Type = "REC UNREAD" Then
                        InboxUnreadValue.Add(ComResponse.TextMessage)
                        ReceivedValue.Add(ComResponse.TextMessage)
                        InboxValue.Add(ComResponse.TextMessage)
                    ElseIf ComResponse.TextMessage.Type = "REC READ" Then
                        InboxReadValue.Add(ComResponse.TextMessage)
                        InboxValue.Add(ComResponse.TextMessage)
                    ElseIf ComResponse.TextMessage.Type = "STO SENT" Then
                        SentValue.Add(ComResponse.TextMessage)
                        OutboxValue.Add(ComResponse.TextMessage)
                    ElseIf ComResponse.TextMessage.Type = "STO UNSENT" Then
                        DraftsValue.Add(ComResponse.TextMessage)
                        OutboxValue.Add(ComResponse.TextMessage)
                    End If
                End If
                ReadNextMessage = False
            End If

            If ReadNextMessage = True Then
                ComResponse.TextMessage.Message &= ComResponse.Incoming
            End If

            If Microsoft.VisualBasic.Left(ComResponse.Incoming, 6) = "+CMGR:" Then
                ComResponse.TextMessage.Particulars() = ComResponse.Incoming
                ReadNextMessage = True
            End If

            If Microsoft.VisualBasic.Left(ComResponse.Incoming, 6) = "+CMGL:" Then
                ComResponse.TextMessage = New TextMessage("", "", "")
                ComResponse.TextMessage.Particulars() = ComResponse.Incoming
                ReadNextMessage = True
            End If

            If InStr(ComResponse.Incoming, "ERROR") > 0 Then
                WriteCommand.Invoke("AT" & vbCrLf, False)
                ReadNextMessage = False
                If messageRead = False Then
                    ComResponse.TextMessage.Message = "ERROR"
                    messageRead = True
                    If ListMessages = True Then ListMessages = False
                End If
                ready = True
                StatusValue = "Ready"
            End If

            If Microsoft.VisualBasic.Left(ComResponse.Incoming, 2) = "OK" Then
                ready = True
                If ListMessages = True Then ListMessages = False
                If SendNextMessage = True Then
                    SendNextMessage = False
                    WriteCommand.Invoke("AT+CMSS=" & CStr(CInt(ComResponse.TextMessage.Index)) & vbCrLf, True)
                End If
                StatusValue = "Ready"
            End If
        Loop
    End Sub

    Private Sub SendCommand(ByVal CommandValue As String, ByVal Delay As Boolean)
        If Delay = True Then
            Do Until ready = True

            Loop
        End If
        ComPort.Write(CommandValue)
        ready = False
        StatusValue = "Ready"
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class

User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: Open Port Attached With Gsm Modem In Asp.net
6 Sep, 2008 - 04:11 PM
Post #4

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 379



Thanked: 19 times
Dream Kudos: 25
My Contributions
if you are wanting to open a port on the client-side, then you will need to use javascript
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 01:21PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month