VB Binary Serial Help for someone


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005
    Posts
    10

    Smile VB Binary Serial Help for someone

    I have been reading a lot of posts on here absorbing information like a sponge, so I thought that I could give back a little. I wanted to send serial data via hserout. All is well. I'm using a 4 Mhz oscillator with a 16F876A chip. The serial data thing was suprpising for me when sending a word. I wanted to save some bandwidth, so I'm sending binary data. If you specify.
    hserout [MyWord]
    It will only send the LowByte. So you will need to send it as...
    hserout [MyWord.lowbyte, MyWord.highbyte]
    or
    hserout [MyWord.Byte0, MyWord.Byte1]

    First the connect string needs to be a little different in VB. I use this.
    MSComm1.Settings = "19200,n,8,1"
    MSComm1.DTREnable = False
    MSComm1.RThreshold = 1
    MSComm1.InputLen = 0
    MSComm1.InputMode = comInputModeBinary
    MSComm1.CommPort = 4
    MSComm1.PortOpen = True


    Private Sub MSComm1_OnComm()
    Dim ByteArray() As Byte
    Select Case MSComm1.CommEvent
    Case comEvReceive
    ByteArray = MSComm1.Input
    ...

    This is the VB function that I wrote.
    'Convert 2 bytes into a 4 byte vb long
    Private Function MakeWord(LowByte As Byte, HighByte As Byte) As Long
    MakeWord = (HighByte * &H100&) Or LowByte
    End Function

    Now I am new to PIC programming, but am a professional programmer. There may be a register to set or something to send the whole word in one shot. But I noticed that every example that I saw here used DEC MyWord, #MyWord, or something similiar, which kills bandwidth.

    This information would have saved me a couple of days. Enjoy!

    Regards,
    Kurt

  2. #2
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Hi,

    The RS-232C standard describes a communication method where information is sent bit by bit on a physical channel. The information must be broken up in data words. The length of a data word is variable. On PC's a length between 5 and 8 bits can be selected. This length is the netto information length of each word. For proper transfer additional bits are added for synchronisation and error checking purposes.

    To send your 16-bit value over RS232 you will need two data words.

    1 START BIT + 8 DATA BITS + 1 STOP BIT (total 10 bits)
    1 START BIT + 8 DATA BITS + 1 STOP BIT (total 10 bits)

    You will also need to ensure the integrity and correctness of the transmitted data.

    Example of a simple ASCII message-based protocol suitable for use on serial lines:
    http://www.embedded.com/1999/9911/9911feat3.htm


    Best regards,

    Luciano
    Last edited by Luciano; - 15th December 2005 at 16:41.

  3. #3
    Join Date
    Nov 2005
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    I realize that it is 2 bytes. I just didn't expect the compiler to see it as one byte.

    hserout [MyWord]
    will only send the lowbyte

    hserout [#MyWord]
    Will send upto 5 bytes depending on value

    hserout ["Hello"]
    Will send 5 bytes.

    The first line isn't so obvious, and one that I've seen many people try, and fail on this message board. It always results in them sending text instead.

Similar Threads

  1. Send binary file to pic over pc serial port
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 3rd May 2011, 14:47
  2. Serial reading of binary at 75 baud
    By JasonMarsh in forum Serial
    Replies: 5
    Last Post: - 20th February 2008, 17:36
  3. serial connection n vb interface
    By gidah in forum Serial
    Replies: 1
    Last Post: - 18th September 2006, 14:54
  4. VB sending serial data to PIC
    By Tissy in forum Serial
    Replies: 7
    Last Post: - 8th March 2006, 19:31
  5. Serial from 16F877 to VB
    By jrudd in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 21st March 2005, 00:33

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