Assistance Required with VB.net


Closed Thread
Results 1 to 33 of 33

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik,

    Success, but..........!

    First of all the success. I changed the PIC code to:

    Code:
    SEROUT2 PORTC.3, 16780, [ z]
    Then changed this line in the VB program:

    Code:
     Me.AddListBoxItem(SerialPort1.ReadExisting)
    To:

    Code:
    Me.AddListBoxItem(SerialPort1.ReadByte)
    And away it went reading and displaying Random Bytes, brilliant

    Now for the but part. I actually want the VB program to read a WORD sent from the PIC (a short in VB?) however for the AddListBoxItem(SerialPort1.Readxxxx there is:

    ReadByte
    ReadChar
    ReadExisting
    ReadLine
    ReadTo

    No ReadShort

    Now I'm thinking somehow it's send a High Byte from the PIC then a Low Byte and join them together in VB, unless there's a 'ReadShort' option.

    Dave
    Last edited by LEDave; - 10th September 2010 at 00:01.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,622


    Did you find this post helpful? Yes | No

    Default

    Hi Dave,

    Nope, a word is two bytes and you have to treat like that.

    The serial port object has a RecevieThreshold property that you can use to fire the Receive event only when so many characters has arrived. If you set it to 2 it will fire every time there's two bytes in the buffer, then you can do something like:
    Code:
    myHighByte = SerialPort1.ReadByte
    myLowByte = SerialPort1.ReadByte
    Then you have to put them back together with something like
    Code:
    Me.AddListBoxItem((myHighByte * 256 + myLowByte).ToString)
    That's ONE way and it'll probably work if "all" your doing is sendning a word over at certain intervals.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik,

    Thanks for that, Ill get on it tonight.

    Good to get the program receiving and displaying Bytes correctly though.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik,

    Quick question:

    The serial port object has a RecevieThreshold property
    In VB6 it does but does it in VB2008?

    Dave

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,622


    Did you find this post helpful? Yes | No

    Default

    Hi,Mine does....but it's called ReceivedBytesThershold, by default it's set to 1.

    I told you my syntax might be off ;-)

    /Henrik.
    Attached Images Attached Images  
    Last edited by HenrikOlsson; - 10th September 2010 at 18:09. Reason: I don't get this new editor....

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


    Did you find this post helpful? Yes | No

    Default

    So does mine and I've set it to two

    How did you copy yours and make it an attachment?

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

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