VB Help


Closed Thread
Results 1 to 36 of 36

Thread: VB Help

Hybrid View

  1. #1
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    Quote Originally Posted by cncmachineguy View Post
    ....How to setup a timer trigger? Maybe it is in the control toolbox? I will check there next.
    Select the TIMER control from the toolbox and drag it into your project. Click on the control to display its properties. Enable the TIMER and set its interval to whatever you want (in mS) - see below.

    Name:  TEST-6H.jpg
Views: 1851
Size:  27.6 KB

    Then code whatever you want to happen whenever a trigger occurs as in the example below.

    Code:
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            count = Val(Label1.Text) * 100
            count = count + 1
            HScrollBar1.Value = count
            Label1.Text = Format$(count / 100, "#0.00")
            NumericUpDown1.Value = count / 100
    
            count = Val(Label3.Text) * 100
            count = count + 1
            HScrollBar2.Value = count
            Label3.Text = Format$(count / 100, "#0.00")
        End Sub
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    Oh thank you rmteo! I had just found the timer, but didn't get the interval part. That works awesome!!

    Ok, now to convert those 2's complimented numbers to show negative values instead of 65533 and such.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    Hi cncmachineguy;

    To receive data from the serial port you should always use SerialPort Event Trigger like the one i posted.

    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)
            End IF
    End Sub
    Don't use timers to poll the serial port, it is not very efficient!!

    If you want to send data to PIC, like a press of a button, then you can use the timer. just put the code that you have inside the button, inside of the timer, and choose the interval!

    I wrote this post in a little hurry, later i have more time and i came back here!
    Thanks and Regards;
    Gadelhas

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    Thanks gadelhas, point taken. Right now the pic is not allowed to send data unless asked for it. The pic side code is modified from the CDC for dummies thread. This part is working great. Thanks to all of you.

    Now for the next part (this seems like it should be easy, but of course not). The 18 bytes sent from the pic represent 9 words. From here on, I will just refer to 1 word. The rest will be the same action.
    Let's call them data(0) and data(1). To put them together I did this:
    Code:
    detain =(data(0)*256)+data(1))
    this works fine with 1 problem. It is really a signed number, so 65533 should read -2.
    I have tried all sort of ways to get here, but continue to fail. I am sure it has to do with dim as or the way I am putting the word back together, but I am at a loss.

    Anyone know how?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    What do you receive from PIC, and what do you want to do, can you give me a full example, its just because english is not my native language, and perhaps i'm not understand something
    Last edited by gadelhas; - 30th May 2011 at 22:42.
    Thanks and Regards;
    Gadelhas

  6. #6
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    From PIC:
    data(0) and data(1). these 2 bytes are the highbyte and lowbyte of a word. -32768-32767

    I need to see the word like that. for example the word may equal 3, or it may be -3. right now I will see 3 or 65533.

    So how to put the bytes back together and show signed integer?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    I never had any purpose to justify the use of signed<->unsigned conversion myself, but you may have a look at
    http://support.microsoft.com/kb/189323

    It's all about how you interpret/display the numbers... like Floating point in PBP... or show decimal on a LCD
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    I would normally side with you steve, but on this one I am having issues. The numbers bounce around zero, so I get to watch 3,3,4,2,1,65533,65534,4,1,.....

    Seems like it would be better to have the numbers more right
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    Quote Originally Posted by cncmachineguy View Post
    From PIC:
    data(0) and data(1). these 2 bytes are the highbyte and lowbyte of a word. -32768-32767

    I need to see the word like that. for example the word may equal 3, or it may be -3. right now I will see 3 or 65533.

    So how to put the bytes back together and show signed integer?
    IN VB.Net, signed bytes are Sbyte and signed Words are Short

    Exemple;
    Dim data0 as Short=-32500
    Dim data1 as SByte = -65

    But if the PIC is sending the 65533, the PC will see 65533 and not -3. Don't know if can help you.
    Last edited by gadelhas; - 30th May 2011 at 22:51.
    Thanks and Regards;
    Gadelhas

  10. #10
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    Ok, different question. How do I put 2 received bytes back together to make 1 word?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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