Assistance Required with VB.net


Closed Thread
Results 1 to 33 of 33

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I moved this thread to the "Off Topic" area.
    As long as this discussion is about interfacing to a MCU I think it is "OK" to discuss VB here.
    Are there limits to the "off topic" topics?

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    I could understand if I was after help with writing a VB application to read a database or something equally obscure, but this is related to sending and receiving data to and from a PIC, or more importantly how to formulate VB code and PBP code so that the two work together.

    Don, what you have mentioned has given me some idea as to what I need. If you have any links to those tutorials it would be appreciated

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tenaja View Post
    Are there limits to the "off topic" topics?
    It has always been my understanding that the "Off Topic" area is for forum "things", electronics questions, and any other "thing" not specific to PB or PBP but in a round about way related to PB or PBP or the forum.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default

    Hi;

    I think i can help, however you need to be more clear about your issue.
    I I'll put here some code,

    VB2008 Net Code;
    First you need to add the serilport class to your project.
    Code:
    Public Class Form1
        Dim WithEvents SerialPort1 As New IO.Ports.SerialPort
    Then, at Form Load, you need to configure and open your SerialPort;
    Code:
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            SerialPort1.PortName = "COM1"
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.BaudRate = 19200
            SerialPort1.DataBits = 8
            SerialPort1.StopBits = 1
            SerialPort1.Open()
            SerialPort1.Write(Chr(13) & "Hugo Oliveira" & Chr(13))
        End Sub
    This handles the recetion from the buffer of the com port, and then i have a If statment to do the actions that need to be perfomed acording with the received data.
    Code:
        Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            Dim recepcao As String
    
            recepcao = SerialPort1.ReadExisting
    
            If recepcao = "%TE" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X - 1, rect.Y)
            ElseIf recepcao = "%TD" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X + 1, rect.Y)
            ElseIf recepcao = "%TC" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X, rect.Y - 1)
            ElseIf recepcao = "%TB" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X, rect.Y + 1)
            ElseIf recepcao = "%TE1" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X - 10, rect.Y)
            ElseIf recepcao = "%TD1" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X + 10, rect.Y)
            ElseIf recepcao = "%TC1" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X, rect.Y - 10)
            ElseIf recepcao = "%TB1" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X, rect.Y + 10)
            ElseIf recepcao = "%TE2" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X - 20, rect.Y)
            ElseIf recepcao = "%TD2" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X + 20, rect.Y)
            ElseIf recepcao = "%TC2" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X, rect.Y - 20)
            ElseIf recepcao = "%TB2" Then
                GetCursorPos(rect)
                SetCursorPos(rect.X, rect.Y + 20)
            End If
        End Sub

    With this piece of code in VB, you must with 100% sure, receive data from Com Port.

    Where is a part of code, from sendinf the data out of the pic, in PBP. I use the Debug command, but you can use Hserout, if you are using te Uart of the PIC, or Serout, Serout2 command.
    Code:
    Main:
    if JX>70 and JX<=100 then
       DEBUG "%TE"
       pause 20
      endif
      
       if JX>0 and JX<=70 then
       DEBUG "%TE1"
       pause 20 
      endif 
      
      if Jx>180 and Jx<210 then
       DEBUG "%TD"
       pause 20
      endif 
      
      if Jx>=210 then
       DEBUG "%TD1"
       pause 20
      endif
    '                             JoyStick Eixo Y
    ' ====================================================================  
      if JY>70 and JY<=100 then
       DEBUG "%TB"
       pause 20 
      endif
      
      if JY>0 and JY<=70 then
       DEBUG "%TB1"
       pause 20 
      endif  
      
      if Jy>180 and Jy<210 then
       DEBUG "%TC" 
       pause 20
      endif
      
      if Jy>=210 then
       DEBUG "%TC1" 
       pause 20
      endif    
    '                             Axis -  Eixo X
    ' ====================================================================
      if Ax<100 then
       DEBUG "%TE2"
       pause 20 
      endif
      
     if Ax>140 then
       DEBUG "%TD2" 
       pause 20
      endif
    '                             Axis -  Eixo Y
    ' ====================================================================  
      if Ay<110 then
       DEBUG "%TB2" 
       pause 20
      endif
      
      if Ay>140 then
       DEBUG "%TC2" 
       pause 20
      endif
    '                             Botões
    ' ====================================================================    
      IF BE = 0 then
       DEBUG "%RL1" 
       pause 80
      endif
    
      IF BD = 0 then
       DEBUG "%RD1" 
       pause 80
      endif    
    goto Main
    Hope it can hep.

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Here are two additions from me:

    Code:
    ComboBox1.Items.AddRange(SerialPort1.GetPortNames())
    This way, you can get the available comports (port list) from your PC hardware directly into a combo box.

    Then,
    Code:
    SerialPort1.PortName = ComboBox1.SelectedItem
    This way, you can select a com port (if there is one).

    Try all of these operations in try/catch so that if a comport is not available, you can prompt a message to the user.
    Also, if there is comport but not selected in combobox, you can also catch it and prompt to the user.


    ----------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default Thanks.

    Guys, thanks for the assistance, I'll have a play when I get home from work

    Much appreciate

  7. #7
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Hi,

    I'm trying to send data from PIC - PC using the program mackrackit pointed to earlier in this thread.

    http://www.rentron.com/receiving_data.htm

    When I compile it I have this error message: Name 'comEvReceive' is not declared.

    Does anyone have an idea of a fix (with as much of an explaination as you can spare please, I'm new to this). I've done lots of Googling with various answer from 'Select Case' to it can't be done in the 2008 VB-Version.

    Code:
     Private Sub MSComm1_OnComm()
    Dim sData As String ' Holds our incoming data
    Dim lHighByte As Long   ' Holds HighByte value
    Dim lLowByte As Long    ' Holds LowByte value
    Dim lWord As Long       ' Holds the Word result
    
    ' If comEvReceive Event then get data and display
    If MSComm1.CommEvent = comEvReceive Then
    
        sData = MSComm1.Input ' Get data (2 bytes)
        lHighByte = Asc(Mid$(sData, 1, 1)) ' get 1st byte
        lLowByte = Asc(Mid$(sData, 2, 1))  ' Get 2nd byte
        
        ' Combine bytes into a word
        lWord = (lHighByte * &H100) Or lLowByte
        
        ' Convert value to a string and display
        lblRCTime.Caption = CStr(lWord)
        
    End If
    End Sub
    I guess I should add I'm using Visual Basic 2008 Express Edition.

    Any help much appreciated.

    Dave
    Last edited by LEDave; - 27th August 2010 at 16:13.

  8. #8
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by LEDave View Post
    Hi,

    I guess I should add I'm using Visual Basic 2008 Express Edition.

    Dave
    Hi,

    The code posted is VB6 and you are using VB2008.
    Try the code in the post 9, of this thread!
    Thanks and Regards;
    Gadelhas

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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