Click here to Skip to main content
15,909,614 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
is there problem in asp.net of serial port?
its works in vb.net not in asp.net
please i am troubling.
but i have open port when i connect it you may see this code
Try
            With SerialPort1
                .PortName = ComboBox1.Text
                .BaudRate = 9600
                .Parity = Parity.None
                .StopBits = StopBits.One
                .DataBits = 8
                .Handshake = Handshake.RequestToSend
                .DtrEnable = True
                .RtsEnable = True
                .NewLine = vbCrLf
                .Open()
               txtbox.text=("Connected")


            End With
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

then i use this when try to send sms
Try
            If SerialPort1.IsOpen Then
                With SerialPort1
                    .Write("AT" & vbCrLf)
                    .Write("AT+CMGF=1" & vbCrLf)
                    .Write("AT+CMGS=" & Chr(34) & TextBox1.Text & Chr(34) & vbCrLf)
                    .Write(RichTextBox1.Text & Chr(26))
                    MsgBox("sms Sent")

                End With
            Else
               txtbox.text=("ERROR MSG ON PORT")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try



i am getting problem please help me if any one can please
it woks in vb.net Application but not in asp.net with vb.net please help me
it just goes here
txtbox.text=("ERROR MSG ON PORT")
Posted
Updated 24-Sep-13 1:46am
v5
Comments
ridoy 20-Sep-13 15:07pm    
but what language you used?asp.net isn't a language!
irfanansari 20-Sep-13 15:13pm    
you may see i am using VB.NET
you can see in Coding
Sergey Alexandrovich Kryukov 20-Sep-13 15:27pm    
Please don't re-post. Better create only one question, but a good one. Use the page of your first question, using "Improve question".
—SA
irfanansari 20-Sep-13 16:35pm    
ok and please help me
[no name] 20-Sep-13 17:06pm    
You need to debug your code and see if you are getting any exceptions when you open the port. MsgBox in an ASP.NET application? What is that you think that is going to do?

1 solution

The chances are that you don't properly understand how ASP.NET works - it is very different to a Windows application.

Since you say you are getting the message "ERROR MSG ON PORT", that implies it is failing the IsOpen test - which implies that the Open method either hasn't been called, or the attempt to open failed. Since you are using MsgBox in your VB code - which runs on the Server, not the Client - the user will not see any error messages at all! They will show up on the server, and probably annoy the heck out of your web host administrator.

What I suspect is that you are doing the first chunk of code is a different method to the second, and that it is being called when you open the page for the first time, or with a different page altogether. With a Windows app that will work, because the application is alive for the entire duration that the user can see the forms. This is not the case with a web site, where the data you created in a page when it is loaded is thrown away when the page events have been handled, and an open serial port will be closed again. When you user enters the number and data he wants to send, the original serial port instance is not longer available and you get a new, unopened one.

Try this: amalgamate the two pieces of code, so that is the port is not open it tries to do it immediately, and replace the MsgBox calls with a display to txtbox.Text instead so the user stands a chance of seeing any errors.

It may fix your problem in the short term, but in the long term, this code probably is not going to work well: there is only one modem to send the messages, and the internet is all about multiple users at the same time - your can't make the modem do two things at the same time!
 
Share this answer
 
Comments
irfanansari 24-Sep-13 8:11am    
i also try to use this in asp.net but it just show connected ok then when i try to send to it so it just goes here

txtbox.text=("ERROR MSG ON PORT")
OriginalGriff 24-Sep-13 8:24am    
As I said: combine the two together, so it checks first:
If Not SerialPort1.IsOpen Then
open the port with your port code above.
Then continue with your other code, all in the same method, at the same time.
irfanansari 24-Sep-13 8:33am    
ok i will then i will ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900