Can anyone provide me with the right code for sending these AT commands using the new

Heavenly

Well-known member
Joined
Aug 22, 2005
Messages
53
Location
Puerto Rico
Programming Experience
1-3
Can anyone provide me with the right code for sending these AT commands using the new SerialPort class?

Serial Port Setup
COM2
1 start bit
8 bit data
No parity
1 stop bit

I need to send these AT commands to the device:


AT+CMGF=1 follow by a carriage return

As soon as I get this string returned

Ok

I then must send this other AT command:

AT+CMGS="7872435333" follow by a carriage return and then follow by Ctrl Z

As soon as I get this string returned, I’m done.

+CMGS: 242
OK

That’s all. Any help will be highly appreciated.


Thanks
 
You know, I see a LOT of articles out here on forums, talking about the new SerialPort class, and I just feel there are no experts out there on it. There are a TON of us, trying to write programs that:
1) Send a Command
2) Wait for a reply
3) Execute code based on that response.

For example:

success = send_command("AT+CMGF=1")
if (success)
' Something good here
else
' something bad here


This information HAS to be out there somewhere, but I CANNOT find it, and trust me I have looked. I promise you, as soon as we find this information, I will post a tutorial on my wiki site.... let me know please if you have any idea how to accomplish something like this in VB.net 2005.....
 
Last edited by a moderator:
Hello.

I think I have answered such a question already multiple times here on the board, like this: http://www.vbdotnetforums.com/vb-net-general-discussion/28884-serial-com.html and Google spits enough Articles on "VB.NET SerialPort".

Also if you have a look at the Documentation or the Object Browser you'll find everything you need to do that. With some Trial and Error you can 'rise to such an Expert'. No serious, there's a connect method, a read, a write and a disconnect method. What else do you need?

I mean there are tricks, f.e. that read knows a TimeOut-Property, so you won't even have to loop. That the NewLine Property can take care of CR/LF for you.

VB.NET:
        Dim RS232Port As new SerialPort("COM1")
        RS232Port.NewLine = vbNewLine
        RS232Port.ReadTimeout = 1500
        RS232Port.DtrEnable = True
        RS232Port.RtsEnable = True

        Dim response As Object = Nothing

        Try
            RS232Port.Open()

            RS232Port.DiscardInBuffer()
            RS232Port.DiscardOutBuffer()

            RS232Port.Write(theMessage)
            Threading.Thread.Sleep(150)
            response = RS232Port.ReadLine

            RS232Port.DiscardInBuffer()
            RS232Port.DiscardOutBuffer()

            RS232Port.Close()
            RS232Port.Dispose()
        Catch ex as Exception
        End Try

Bobby
 
Back
Top