PC serial port funny


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612

    Default

    Hi,
    I think yoyr problem is in your DEBUG statements in the PIC code. If you use the #modifier the PIC sends the the value of the variable as "text". So if the varaible lower is a word and set to 1234 the pic will send four bytes ie. "1","2","3","4" instead of the two bytes that the wordvariable consists of. That way the number of bytes the PIC sends depends on the actuall value of the variables so the OnComm() event will fire at different places in your "stream" since it's set to fire after every 6 bytes.

    I think that you need to do:
    Code:
    sendlower:
    debug "aa", lower
    PAUSE 100
    And then on the VB-side you look for "aa" and then extract the high and low byte from the stream and put them together with Result = highbyte*256+lowbyte or something like that.

    Did it make any sence?

    /Henrik Olsson.

  2. #2
    Join Date
    Aug 2006
    Posts
    20

    Default

    Thanks Henrik,

    Yes I have tried what you've suggested, but only on the transmission of one variable containing 2 bytes. It worked fine. I will change the code and see if that does the trick. Ithink it might be a little tricky though.


    John.

  3. #3
    Join Date
    Aug 2006
    Posts
    20

    Smile

    Hi all,

    I've been able to get error free comms by sending the variables as high and low bytes (debug "aa", stepcnt.byte1, stepcnt.byte0). The same is not true when I send the variable as

    DEBUG "aa", stepcnt

    My steps taken to covert for display;

    cmdword = Left(displaystr, 2) ' rip out the command 'aa'
    newstring = asc(mid$, 3, 2)) ' put the rest of the word into var
    Lbyte = newstring AND &H255
    Hbyte = (newstring - Lbyte) / &H100
    word = (Hbyte * &H100) OR Lbyte
    Text.text=word

    This seems to work on paper. I've also swapped high and low around as I think the PIC sends the low order byte first?

    Even though I've got the project working well, could someone explain the correct way to strip data using VB.

    Most appreciated

    John

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

    Default

    Could you post your whole codes here (all VB(Vbp,form...) and PBP.Bas)? just pack both in a zip. Save me to re-invent the wheel and work exactly with what you have

    My single brain cell simply can't work with scratch and partial code snip... sorry i'm getting old
    Steve

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

  5. #5
    Join Date
    Aug 2006
    Posts
    20

    Default

    Steve, I've attached the VB program and the PBP prog. Its pretty uglgy but for the best part it works. Its works well with the vb prog when variables are sent as byte1, byte2. Strange this occur when the variable is sent eg HSEROUT ["aa", stepcnt].
    I also changed to the USART as I found using the serial commands I could not catch external inputs.

    Thanks for your time Steve,

    John
    Attached Files Attached Files
    Last edited by nicjo; - 12th January 2007 at 09:35.

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

    Default

    O.K. i'll look at that. So you're using a 16F628 right? for serial comm, i would suggest you to use a crystal. To make sure to don't miss incoming stuff, i always suggest to use a USART interrupt.

    this
    Code:
    ["aa", stepcnt]
    can't work because it will send a WORD ascii character... wich is impossible. So instead, you should work around and use
    Code:
    ["aa", #stepcnt]
    but use VAL on the VB side.

    I'll do a little something here, totally different, so you could use some part of it in your actual code.
    Steve

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

  7. #7
    Join Date
    Aug 2006
    Posts
    20

    Talking

    Thanks, I,m using a Xtal, found that out the hard way, could'nt work out why there were so many errors, after puting xtal in cct, errors disappeared. And yes, I'm using a 628.

    I kind of figured that "aa" stepcnt was a word representation of stepcnt and that on the other end it would need to be split in two to find the original values. I started off with #stepcnt but on the vb side after sending a whole bunch of words, errors started appearing. Never thought of the VAL function though. I just placed the value from the PIC straight into a txt box. Anyway, I hope my code is not to painfull.

    Thanks again

    John

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, 13:47
  2. interfacing to the pc serial port
    By kelangfei in forum General
    Replies: 4
    Last Post: - 7th October 2007, 22:35
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. Replies: 2
    Last Post: - 28th April 2006, 12:10
  5. PC Serial Port Connections
    By BigH in forum Serial
    Replies: 1
    Last Post: - 20th January 2006, 08:24

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