PC serial port funny


Results 1 to 14 of 14

Threaded View

  1. #1
    Join Date
    Aug 2006
    Posts
    20

    Lightbulb PC serial port funny

    Hi all,

    I guess this is a question more about the MSCOMM object within VB6 than PICs however, it may turn out the other way.

    I'm sending serial data to the PC and displaying the data in several text boxes. The connection between the PC and PICF628 begins when the VB6 form opens and the user initiates a request from the PIC. The PIC then sends 5 differnent variables plus a couple of characters at the front so that I could rip out the two command char which indicate which text box to display the data. I'm using the DEBUG @ 300 BPS for communication.

    The funny thing is that when any other data is sent after the initialization the PC comm port seems to have shifted (right) to places. I've attached both the PC code and a snippet from a large PIC file.

    I must mention that some of the VB code I obtained was off Rentron.com, I just added a few things.

    Oh, and one more thing, the days of frustration over the PICF88, was due to a decoupling cap, thanks for everyones advice especially Steve.
    Code:
    
    Private Sub cmdinit_Click()
    Dim out As String
    out = "k"
    MSComm1.Output = out            'command to PIC to begin sending data.
    End Sub
    ----------------------------------------
    Private Sub Form_Load()
    Dim i As Integer
    Dim send_data As String
    Dim InStr As String
        
    MSComm1.CommPort = 2
    ' Fire Rx Event Every Two Bytes
    MSComm1.RThreshold = 6
    
    'If MSComm1.InBufferCount = 6 Then
        ' When Inputting Data, Input 6 Bytes at a time
        MSComm1.InputLen = 6
    'End If
    
    ' 300 Baud, No Parity, 8 Data Bits, 1 Stop Bit
    MSComm1.Settings = "300,N,8,1"
    ' Disable DTR
    MSComm1.DTREnable = False
    
    ' Open the port
    MSComm1.PortOpen = True
    
    End Sub
    ----------------------------------------------------------------
    Public Sub MSComm1_OnComm()
    Dim sData As String
    
    If MSComm1.CommEvent = comEvReceive Then
        sData = sData & MSComm1.Input
        sData = MSComm1.Input ' Get data (2 bytes)
    End If
    
    Call display(sData)
    End Sub
    --------------------------------------------------------------------
    Public Sub display(instring As String)
    Dim cmdword As String         'hold the command word
    Dim word As String        'holds the data
    Dim outstring As String
    
    If Len(instring >= Limit) Then
        outstring = instring
        instring = Right$(instring, Len(instring) - Limit)      'clears the buf
    Call handleinput(outstring)
    
    End If
    End Sub
    ------------------------------------------------------------------------
    Sub handleinput(displaystr As String)
    Dim newstring As String
    
    
    cmdword = Left(displaystr, 2)     ' rip out the command 
    word = Mid$(displaystr, 3, 4)      'rip out the data to be displayed
    
    Select Case cmdword
        Case "OK"
            
        Case "aa"       'lower bound
            lower.Text = word
            
        Case "bb"       'upper bound
            upper.Text = word
            
        Case "cn"       'step count
            stepcnt.Text = word
            
        Case "ab"
            focus1.Text = word
            
    End Select
        
    End Sub
    
    ----------------------------------------------------
    
    PIC code
    
    init:                           '
    sendlower:
    debug "aa", #lower
    PAUSE 100
    
    debug "bb", #upper
    PAUSE 100 
       
    sendstepcnt:       
    debug "cn", #stepcnt
    PAUSE 100
    
    sendf1:
    ADDR_L=1
    ADDR_H=2
    GOSUB readset
    DataA.byte0 = RDDATA_L
    DataA.byte1 = RDDATA_H
    debug "ab", #DataA
    I'm thinking that maybe I need to encapsulate the data in control characters then strip them out at the other end. But after looking at the output of the pic using (MCS Communicator) when the initialistion command is given, I can't see any errors. ?????
    Last edited by Archangel; - 12th June 2011 at 20:44. Reason: code tags

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