Pic & Vb6 Serial Comm


+ Reply to Thread
Results 1 to 14 of 14

Thread: Pic & Vb6 Serial Comm4907 days old

  1. #1
    Junior Member stefano's Avatar
    Join Date
    Dec 2005
    Posts
    51
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    793.31 MB

    0 Not allowed!

    Default Pic & Vb6 Serial Comm

    Hi, is there someone who can help me?

    This is PIC LIST:

    ----------------------------------------------------------------------
    Device 18F458 ' stabilisco il PIC di utilizzo
    XTAL 40
    @CONFIG_REQ
    @__CONFIG config1h, HSPLL_OSC_1
    @__CONFIG config4l, LVP_OFF_4
    @__CONFIG config2h, WDT_OFF_2 & WDTPS_128_2
    @__CONFIG config2l, BOR_ON_2 & PWRT_ON_2
    ALL_DIGITAL = TRUE
    '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
    ' settaggio LCD
    Declare LCD_ENPIN PORTB.3' determino porta EN LCD per vnr b.2
    Declare LCD_RSPIN PORTB.2' determino porta RS LCD per vnr b.3
    Declare LCD_DTPIN PORTB.4' dertermino porte dati LCD(da b4 a b7)
    Declare LCD_LINES 2 ' comunico le linee LCD

    HSERIAL_RCSTA = %10010000 ' Enable serial port and continuous receive
    HSERIAL_TXSTA = %00100000 ' Enable transmit and asynchronous mode
    HSERIAL_BAUD = 19200 '
    Declare HSERIAL_CLEAR On
    '''''''''''''''''''''''''''''''''''''
    freq = 14576000
    DelayMS 200
    Cls
    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''
    inizio: Print At 1,1,"HSERIAL TEST"
    Print At 2,1,@freq

    If PORTC.1 =0 Then DelayMS 200:GoSub vaisu
    If PORTC.2 =0 Then DelayMS 200:GoSub vaigiu
    GoTo inizio
    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''
    vaisu:
    freq = freq + 10
    HSerOut [Dec freq]
    Return

    vaigiu:
    freq = freq - 10
    HSerOut [Dec freq]

    Return


    End

    THIS IS THE VB6 LIST
    ------------------------------------------------------------------------
    Private Sub Form_Load()
    MSComm1.CommPort = 1 ' Selezioniamo la COM1
    MSComm1.Settings = "19200,n,8,1" ' Le impostazioni della seriale
    MSComm1.RThreshold = 1 ' voglio essere informato della ricezione di ogni singolo carattere
    MSComm1.PortOpen = True ' Apriamo la porta.
    End Sub

    Private Sub MSComm1_OnComm()
    Dim Rx$
    Rx$ = MSComm1.Input ' Leggo il contenuto del buffer di ricezione (e svuoto .Input)
    If Len(Rx$) Then ' Se ho ricevuto qualcosa lo scrivo nella TextBox
    Text1.Text = Text1.Text & Rx$
    End If
    End Sub

    This is my FIRST problem:

    Text1.Text = Text1.Text & Rx $ is always (example) written: 1457601014576000f1457602014576030 etc...
    I would always want writing 14576000 delete 14576010 delete 14576020 from beginning Text1.Text window


    This is my SECOND problem:

    I would want to know whether to select VAR1, VAR2 to be print in vb6 test window, example:

    VAR1 = print on Text1.Text of VB6

    VAR2 = print on Text2.Text of VB6


    Thanks to whom will help me !!!

    Regards.

    Stefano.

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    ta1dr
    Guest ta1dr's Avatar

    0 Not allowed!

    Default

    Private Sub Form_Load()
    MSComm1.CommPort = 1 ' Selezioniamo la COM1
    MSComm1.Settings = "19200,n,8,1" ' Le impostazioni della seriale
    MSComm1.RThreshold = 1 ' voglio essere informato della ricezione di ogni singolo carattere

    MSComm1.PortOpen = True ' Apriamo la porta.
    End Sub

    Private Sub MSComm1_OnComm()
    Dim Rx$
    Mscomm1.inputbuffercount=0
    ' *******************Try this
    do
    doevents
    loop until mscomm1.inputbuffercount = xx '(your text len)
    '*********************************************
    Rx$ = MSComm1.Input ' Leggo il contenuto del buffer di ricezione (e svuoto .Input)
    If Len(Rx$) Then ' Se ho ricevuto qualcosa lo scrivo nella TextBox
    Text1.Text = Rx$
    End If
    End Sub

    and second answer
    I can create simple protochol

    exp: your var1 =123 and var2= 456
    you can sent this "A123B456"
    when receive data vb6 check "A" and read data
    if mid(RX$,1,1)="A" then
    text1.text=mid(RX$,2,3)
    endif
    if mid(RX$,5,1)="B" then
    text2.text=mid(RX$,6,3)
    endif

    ahmet
    TURKEY

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Junior Member stefano's Avatar
    Join Date
    Dec 2005
    Posts
    51
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    793.31 MB

    0 Not allowed!

    Default

    Thank for help.
    My VB6 says (when I send data from PIC): compile error: method or data member not found : .inputbuffercount =

    Stefano.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    ta1dr
    Guest ta1dr's Avatar

    0 Not allowed!

    Default

    sorry
    mscomm1.inbuffercount

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Junior Member stefano's Avatar
    Join Date
    Dec 2005
    Posts
    51
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    793.31 MB

    0 Not allowed!

    Default

    Ok, I have added the value (...loop until mscomm1.inbuffercount =8 )but it doesn't print the value on Text1.Text
    What can be?

    Stefano.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    ta1dr
    Guest ta1dr's Avatar

    0 Not allowed!

    Default

    your text length is 8 is it ok ?
    maybe change MSComm1.RThreshold = 8 try this
    I can try your vb6 code my computer tomrrow because I am going to home
    see you tomorrow
    ahmet

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Junior Member stefano's Avatar
    Join Date
    Dec 2005
    Posts
    51
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    793.31 MB

    0 Not allowed!

    Default

    >Yes :I send the var: freq = 14576000 = 8 char.
    MSComm1.RThreshold = 8 > same result.
    Thanks!
    Stefano.

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Prolific Poster johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,183
    Thumbs Up
    Received: 98
    Given: 1
    Total Downloaded
    2.91 GB

    0 Not allowed!

    Default

    I would go back to your initial attempt as it is much better to handle the data as an event.

    Try this

    Private Sub MSComm1_OnComm()
    If MSComm1.CommEvent = ComEvReceive then
    If MSComm1.InBufferCount > 7 then
    Text1.Text = MSComm1.Input
    endIf
    endIf
    end Sub

    This will trigger each time an MSComm event occurs. Test for the event you are looking for - in this case a 'Receive event'. Check the length of the input buffer and if it is greater than 7 read it into Text1.

    The reason for using > 7 rather than 8 is that if there are any additional characters in the buffer you clear them all out. You should also set the InBufferCount to 0 in your initialisation routine to clear out any unexpected data left in the buffer.

    Hope this helps....
    JohnB

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Junior Member stefano's Avatar
    Join Date
    Dec 2005
    Posts
    51
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    793.31 MB

    0 Not allowed!

    Default Okk

    Hi Johngb, very good this is the perfect result!

    Private Sub Form_Load()
    MSComm1.CommPort = 1 ' Selezioniamo la COM1
    MSComm1.Settings = "19200,n,8,1" ' Le impostazioni della seriale
    MSComm1.RThreshold = 1 ' voglio essere informato della ricezione di ogni singolo carattere
    MSComm1.PortOpen = True ' Apriamo la porta.
    I have also added: MSComm1.InputLen = 8
    End Sub

    Private Sub MSComm1_OnComm()
    If MSComm1.CommEvent = comEvReceive Then
    If MSComm1.InBufferCount > 7 Then
    Text1.Text = MSComm1.Input
    End If
    End If


    End Sub
    __________________________________________________ _________

    Many thanks to ahmet for collaborations!
    __________________________________________________ _________

    Sorry Johngb can you help me for the second problem ?

    I would want to know whether to select VAR1, VAR2 to be print in vb6 test window, example:

    VAR1 = print on Text1.Text of VB6VAR2 = print on Text2.Text of VB6


    Regards.

    Stefano

  18. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Nigel Worsley
    Guest Nigel Worsley's Avatar

    0 Not allowed!

    Default

    There are several ways to do what you want, this is one example.

    PIC code:
    Code:
    vaisu: 
    freq = freq + 10
    HSerOut [Dec freq, "A"]
    Return 
    
    vaigiu: 
    freq = freq - 10
    HSerOut [Dec freq, "B"]
    
    Return
    VB code:

    Code:
    Dim RxBuffer as String
    Dim Temp as String
    
    Private Sub Form_Load()
    As before except MSComm1.InputLen = 1
    
    Private Sub MSComm1_OnComm()
    If MSComm1.CommEvent = comEvReceive Then
     If MSComm1.InBufferCount > 0 Then
      Temp = MSComm1.Input
      If Temp = "A" Then
       Text1.Text = RxBuffer 
       RxBuffer  = ""
      ElseIf Temp = "B" Then
       Text2.Text = RxBuffer 
       RxBuffer = ""
      Else
       RxBuffer = RxBuffer & Temp
      Endif
     End If
    End If
    Doing it this way has the added benefit of not requiring the data to be of a fixed length.

  20. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  21. #11
    Junior Member stefano's Avatar
    Join Date
    Dec 2005
    Posts
    51
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    793.31 MB

    0 Not allowed!

    Default I have tried...

    Thanks Nigel, this is VB6 list:



    Private Sub Form_Load()
    MSComm1.CommPort = 1 ' Selezioniamo la COM1
    MSComm1.Settings = "19200,n,8,1" ' Le impostazioni della seriale
    MSComm1.RThreshold = 1 ' voglio essere informato della ricezione di ogni singolo carattere
    MSComm1.PortOpen = True ' Apriamo la porta.
    MSComm1.InputLen = 1



    End Sub

    Private Sub MSComm1_OnComm()
    Dim RxBuffer As String
    Dim Temp As String

    If MSComm1.CommEvent = comEvReceive Then
    If MSComm1.InBufferCount > 0 Then
    Temp = MSComm1.Input
    If Temp = "A" Then
    Text2.Text = RxBuffer
    RxBuffer = ""
    ElseIf Temp = "B" Then
    Text3.Text = RxBuffer
    RxBuffer = ""
    Else
    RxBuffer = RxBuffer & Temp
    End If
    End If
    End If


    End Sub

    The result is negative, it doesn't print on A on Text2.Text and B onText2.Text

    Is there some other parameter to insert?

    Regards
    Stefano.

  22. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  23. #12
    Junior Member stefano's Avatar
    Join Date
    Dec 2005
    Posts
    51
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    793.31 MB

    0 Not allowed!

    Default First "good" result

    Hi Friends, with this code the solution is ...near...



    VB6 IN
    Private Sub Form_Load()
    MSComm1.CommPort = 1 ' Selezioniamo la COM1
    MSComm1.Settings = "19200,n,8,1" ' Le impostazioni della seriale
    MSComm1.RThreshold = 1 ' voglio essere informato della ricezione di ogni singolo carattere
    MSComm1.PortOpen = True ' Apriamo la porta.
    MSComm1.InputLen = 8



    End Sub

    Private Sub MSComm1_OnComm()
    Dim Rx$
    If Mid(Rx$, 1, 1) = "1" Then
    Text2.Text = Mid(Rx$, 1, 2)
    End If
    If Mid(Rx$, 1, 1) = "2" Then
    Text3.Text = Mid(Rx$, 1, 2)
    End If

    Pic OUT

    ...HSerOut [Dec Var1,1]
    ...HSerOut [Dec VAr2,2]

    End Sub[/LEFT]

    thanks to everybody

    Stefano

  24. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  25. #13
    Prolific Poster johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,183
    Thumbs Up
    Received: 98
    Given: 1
    Total Downloaded
    2.91 GB

    0 Not allowed!

    Default

    First the data you are sending out from the PIC is the wrong way round:
    vaisu:
    freq = freq + 10
    HSerOut ["A", Dec freq] ' TagID "A" , Data for "A"
    Return

    vaigiu:
    freq = freq - 10
    HSerOut ["B", Dec freq] ' TagID "B" , Data for "B"

    Return

    That way the first character you receive will tell you what the following data is.

    In your VB program you should do this:

    ' First you will need 2 additional Variables

    Dim InData As String
    Dim IDTag As String

    Private Sub MSComm1_OnComm()
    If MSComm1.CommEvent = comEvReceive Then
    If MSComm1.InBufferCount > 7 Then
    InData = MSComm1.Input ' Save the input data in InData
    IDTag= Left$(InData, 1) ' Get first character of InData (This is the tag ID of the following data)
    InData = Right$(InData, Len(InData) -1) ' Now remove the Tag and save result in InData
    Text4.Text = "OK" ' I have added an extra Status Text box to report errors.... first we clear it to OK
    Select Case IDTag ' Next we test for the value in IDTag to determine which text box to place the data in.
    Case "A": Text1.Text = InData
    Case "B": Text2.Text = InData
    Case "C": Text3.Text = InData
    Case Else: Text4.Text = 'Error - unrecognised Tag": If we don't recognise the tag we report error in the Status text box
    End Select
    End If
    End If

    Hope this helps
    JohnB

  26. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  27. #14
    Junior Member stefano's Avatar
    Join Date
    Dec 2005
    Posts
    51
    Thumbs Up
    Received: 1
    Given: 1
    Total Downloaded
    793.31 MB

    0 Not allowed!

    Default OK "end of the problems" !!

    I have TESTED and it works well, thanks you have been very nice

    Best regards.

    Stefano

  28. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. [SOLVED !] 16F877 USAR & no standard MSCOMM VB6 speed
    By wirecut in forum Proton Plus Compiler v3
    Replies: 14
    Last Post: 5th December 2009, 00:02
  2. [SOLVED !] serial comm and strings
    By dasloth12 in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 26th November 2007, 21:48
  3. [SOLVED !] Serial comm port reassignment
    By Sparky1039 in forum Proton Plus Compiler v3
    Replies: 7
    Last Post: 19th October 2007, 14:07
  4. Using USB with PDS & VB6
    By Alan in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 4th April 2006, 02:44
  5. [SOLVED !] Serial data between 1 master pic & 8 slave pic
    By Roshan in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 23rd September 2005, 11:21

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts