GSM-Forum

GSM-Forum (https://forum.gsmhosting.com/vbb/)
-   GSM Programming & Reverse Engineering (https://forum.gsmhosting.com/vbb/f83/)
-   -   Serial Port in VB .NET 2008 (https://forum.gsmhosting.com/vbb/f83/serial-port-vb-net-2008-a-688748/)

Dave.W 02-25-2009 12:09

Serial Port in VB .NET 2008
 
1 Attachment(s)
Hi,

Since I discovered the free download of Visual Studio .Net Express 2008 over at the microsoft site, I have had a small play bringing some of my VB 6 code over to the new standards.

Attached is a small sample I just wrote to communicate with the Serial Port.

The s/w enumerates all available ports automatically and data entred into the upper text box is transmitted to the port on clicking the Tx button. The data sent is terminated by vbCr character (chr(13)) but this can be modified in code.

Pauses are used to wait for any recieved data to be filled in the buffer, and the Rx data is then added to the RichTextBox. Again these can be modified or replaced by Do..While loops depending on what device you communicate with.

This is not the best way of working with VB.NET, I am reading a lot about threading at the moment. However this very simple code works in my application 100%, and hopefully it can give others a small head start.

Good luck!

Code:

Public Class Form1

    Dim comPorts As Array  'Com ports enumerated into here
    Dim rxBuff As String    'Buffer for receievd data

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'When the form loads
        'Enumerate available Com ports and add to ComboBox1
        comPorts = IO.Ports.SerialPort.GetPortNames()

        For i = 0 To UBound(comPorts)
            ComboBox1.Items.Add(comPorts(i))
        Next

        'Set ComboBox1 text to first available port
        ComboBox1.Text = ComboBox1.Items.Item(0)
        'Set SerialPort1 portname to first available port
        SerialPort1.PortName = ComboBox1.Text

        'Set remaining port attributes
        SerialPort1.BaudRate = 19200
        SerialPort1.Parity = IO.Ports.Parity.None
        SerialPort1.StopBits = IO.Ports.StopBits.One
        SerialPort1.DataBits = 8


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'When Tx button clicked
        'Clear buffer
        rxBuff = ""

        'If port is closed, then open it
        If SerialPort1.IsOpen = False Then SerialPort1.Open()

        'Write this data to port
        SerialPort1.Write(TextBox1.Text & vbCr)

        'Pause for 800ms
        System.Threading.Thread.Sleep(800)

        'If the port is open, then close it
        If SerialPort1.IsOpen = True Then SerialPort1.Close()

        'If the buffer is still empty then no data. End sub
        If rxBuff = "" Then GoTo ends

        'Else display the recieved data in the RichTextBox
        RichTextBox1.Text = rxBuff

ends:
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        'When ComboBox1 selection is changed, we need to update SerialPort1 with the new choise
        'But only if the port is closed!

        If SerialPort1.IsOpen = False Then
            SerialPort1.PortName = ComboBox1.Text
        Else : MsgBox("Operation only valid when port is closed.", MsgBoxStyle.Exclamation, "Error")

        End If

    End Sub

    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        'This sub gets called automatically when the com port recieves some data

        'Pause while all data is read
        System.Threading.Thread.Sleep(300)

        'Move recieved data into the buffer
        rxBuff = (SerialPort1.ReadExisting)

    End Sub

End Class


Dave.W 02-25-2009 12:21

Uses:

This program was intended for communicating with some industrial control application, but is working well with mobile phone over AT command set.

Tested with SE K850i connected on USB data link (PC Suite driver installed), and set to phone mode.

Send AT command "AT"
http://i4.photobucket.com/albums/y105/picogsm/AT-1.png

Send AT service request "AT*"
http://i4.photobucket.com/albums/y105/picogsm/AT-2.png

You can find details of AT command set HERE

Have fun!

vikramb1 03-09-2009 15:56

FBUS command for nokia 1600
 
Sir would u plz tell how to read nokia firmware detail with usb ....coz i am sending FBUS command to phone command sent sucssesfully but didn't get answer from phone would u plz give some help how to communicate with phone with Visual Basic just read phone type and imei.....

Thanks a lot

-luigi- 03-10-2009 13:12

Sending SMS using .NET sOURCE Code!!!
 
Hi. As it was not easy for me to find a source code, I will put the page here for make easy for the people:

http://www.codeproject.com/KB/IP/Sen...using_Net.aspx

if you are using VB8, I recommend u to read this:
https://forum.gsmhosting.com/vbb/f83/serial-port-vb-net-2008-a-688748/

Dave.W 03-10-2009 13:43

Code in both links is the same thing, only the top link has the added AT command for sensind SMS.

Also, you will have problems using that with most manufaturers mobile, as it is working with TEXT mode SMS. Most big manufacturer support only PDU mode.

You can find info how to make PDU text messages at: http://www.embedtronics.com/nokia/fbus.html

I will merge this with the sticky thread - to make it more accessable for others :)

Dave.W 03-10-2009 13:52

Quote:

Originally Posted by vikramb1 (Post 4229404)
Sir would u plz tell how to read nokia firmware detail with usb ....coz i am sending FBUS command to phone command sent sucssesfully but didn't get answer from phone would u plz give some help how to communicate with phone with Visual Basic just read phone type and imei.....

Thanks a lot


The source code posted above is for sending AT commands only, you must modify it to send FBUS commands.

AT command = string data
FBUS = hex data

You can find examples how to send FBUS in visual basic by searching the forum, this can be converted to .NET quite easy :)

vikramb1 03-13-2009 19:10

how to read from port in VB6
 
Sir thanks for reply,

actually i am trying to read phones type and imei through FBUS, sending command with MSCOMM in hex values....but didn't get answer from phone how to read data from port and put in string don't get ....

data written to com port sucessfully seen in sniffer but unable to catch answer....

vikramb1 03-13-2009 19:12

how to read from port in VB6
 
Sir thanks for reply,

actually i am trying to read phones type and imei through FBUS, sending command with MSCOMM in hex values....but didn't get answer from phone how to read data from port and put in string don't get ....

data written to com port sucessfully seen in sniffer but unable to catch answer....
phone is nokia 1600 connected to usb.

cool_guy4ever15 03-27-2009 22:34

hi sir

i've downloaded the attachmet and when i tried to open the program it gives me an error and didn't open.

i wanna to interface Ericsson T290i with AT COmmand i want when the mobile recieve a message it converts it to binary code that microcontroller understand it to turn on/off devices.

i want to know how could i read message from the program i downloaded coz i tried with hyper terminal it gives me error in the reding msg code. so plz i want u to help me

sorry if i ask silly question i havn't worked with visual studio before

i hope u understand me.

Dave.W 03-28-2009 08:40

you must download also the visual studio package from the first link. There is some core files needed to run the exe

vikramb1 03-28-2009 09:54

how to read buffer from comm port
 
Sir when i send command to phone in hex i unable to catch ACK from phone in which event i write code or how i get or read answer from phone plz help

Dave.W 03-29-2009 10:25

1 Attachment(s)
Seems you are using VB6, so why are you posting your question in this thread? You should make a new, or better still make a forum search.

Any way, take the attachment. Its simple com port source code in VB6, very old source. It is already posted in the forum a few times.

JayDi 03-29-2009 14:39

Dave.W, can You explain little more about sending comand via usb and recived answer back procedure?
I'm coding on delphi, and i found very small info about that on forum...
I've seen on this section some code for Delphi by SEMC, but i can't understand how do that...
Thanks... and Sorry, if i post in wrong section...

Dave.W 03-29-2009 21:04

Hi JayDi,

All I know is in the first post really. You must install SEMC Data suite then the mobile becomes like a virtual com and you can access with serial port control.

I suppose there is other levels of communication also.

code-R 03-31-2009 05:24

is available for delphi ???


All times are GMT +1. The time now is 03:29.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
- GSM Hosting Ltd. - 1999-2017 -

Page generated in 0.15714 seconds with 6 queries

SEO by vBSEO