USB Receiving a Word


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2005
    Posts
    42

    Default USB Receiving a Word

    Help, brain burnout here with Easyhid and words LOL

    I want to send a Word value of decimal 1000
    I am sending from VB two bytes of data 10 00:

    BufferOut(0) = 0
    BufferOut(1) = 10
    BufferOut(2) = 00

    In PBP I am receiving them fine as bytes

    Byte1=usbbuffer(0)
    Byte2=usbbuffer(1)

    Now I want to pop these into a Word Value within PBP code but using

    WordData.HighByte=Byte1
    WordData.LowByte=Byte2

    But it takes the value and stores then as Hex Byte1 gets stored as 0A and Byte 2 gets stored as 00 and hence when I end up with 2560 in Decimal stored and not 1000.

    Now the question is, do I have to convert my Decimal 1000 to hex at the VB end and send or can I convert in my PBP code after receiving?.

    If using Serial data and Receiving using Hserin I just simply
    HSerin [WAIT("$"),DEC4 WordData]
    And would love to do that with USB as well!

    I am probs missing something so obvious here LOL

    Regards

    Sean.

  2. #2
    sinoteq's Avatar
    sinoteq Guest

    Default

    Hi,
    Have you thought about that 1000 DEC is HighByte=3 and LowByte=232 and not 10 00?
    What you get is actually correct if you look at following:

    00001010 00000000=2560 HighByte=10 DEC LowByte=0
    00000011 11101000=1000 HighByte=3 DEC LowByte=232

    My suggestion is to split the word in VB using a different method.

  3. #3
    Join Date
    Aug 2005
    Posts
    42

    Default

    Ah now I see of course.

    So in my VB prog I will take the value say 1000

    Splt it down to 16bits
    0000001111101000

    Split again to high and low 8 bits

    00000011 = 3
    11101000 =232

    Then send dec value of each set of 8 bits.

    Excellent!

    Regards

    Sean.

Similar Threads

  1. Read/Write Problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th February 2010, 01:51
  2. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  3. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  4. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th July 2008, 23:19
  5. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 15:23

Members who have read this thread : 1

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