Results 1 to 2 of 2

Thread: VB code for serial port

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    5

    VB code for serial port

    I need help in interfacing mobile with computer through serial port using visual basic. The signal obtained from RS232 will be passed to IC MAX232. I found some code in VB for serial port, but doesnt seem to work.

    The cable used for connection has 9 pins from one side and 4 pins from the other end. I was told that, I have to make some connections internally, by joining some pins, which I will be doing. But, how should the 4 pins from the end be connected??? Can anyone plz send me the Complete information and the proper code in VB for serial port communication, please???

    I have searched a lot on internet and tried with lot of codes, but they dont give proper output. First of all, I want to do a simple test of the cable, by obtaining the requied voltage for MAX232, plz tell me.



    Thanx a lot.......

  2. #2
    New Member chutinhha's Avatar
    Join Date
    Sep 2008
    Posts
    1

    Re: VB code for serial port

    CLASS MAIN:
    Public Delegate Sub rcvDelegate()

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    'REM This is to send the code to get the sensor names
    TextBox6.Text = ""
    requestType = "N"
    Try
    SerialPort1.Write("N" & vbCrLf)
    Catch ex As Exception
    MsgBox(ex.ToString)
    End Try
    System.Threading.Thread.Sleep(1000)
    End Sub

    Public Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
    'REM BufferHold is a global variable that holds the string
    BufferHold += SerialPort1.ReadExisting
    TextBox6.Invoke(New rcvDelegate(AddressOf updateTextBox), New Object() {})
    End Sub

    Private Sub updateTextBox()
    'TextBox6.Text = TextBox6.Text + SerialPort1.ReadExisting()
    TextBox6.Text = BufferHold
    If requestType = "N" Then
    'This is a request for sensor names
    SensorNames = BufferHold
    End If
    If requestType = "R" Then
    'This is a request for sensor values
    SensorValues = BufferHold
    End If
    SN1 = SensorNames.Substring(0, 3)
    Label3.Text = SN1
    SN2 = SensorNames.Substring(5, 3)
    Label4.Text = SN2
    SN3 = SensorNames.Substring(10, 3)
    Label5.Text = SN3
    SN4 = SensorNames.Substring(15, 3)
    Label6.Text = SN4
    SN5 = SensorNames.Substring(20, 3)
    Label7.Text = SN5
    End Sub
    From Viet Nam -Mail:chutinh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width