VB6 for interfacing pic

Discussion in 'Embedded Systems and Microcontrollers' started by arungokul1990, Jan 16, 2013.

  1. arungokul1990

    Thread Starter New Member

    Jan 16, 2013
    am using the below code for transferring data from pic to vb,but it seems it doesnt work,someone pls help me,it seems the error is Invalid port number,am an electronic student working on front end of pic,i want to transfer data that is available on the pic ,help is highly appreciated

    Private Sub Command1_Click() MsgBox ("The port is open " & MSComm1.PortOpen) If (MSComm1.PortOpen = False) Then MSComm1.PortOpen = True End If Command1.Enabled = False Command2.Enabled = True End Sub Private Sub Command2_Click() If (MSComm1.PortOpen = True) Then MSComm1.PortOpen = False End If Command1.Enabled = True Command2.Enabled = False End Sub Private Sub Form_Load() With MSComm1 .CommPort = 1 .RThreshold = 1 .RTSEnable = True .Settings = "9600,N,8,1" .InputLen = 127 .SThreshold = 1 End With End Sub Private Sub Form_Unload(Cancel As Integer) If (MSComm1.PortOpen = True) Then MSComm1.PortOpen = False End If End Sub Private Sub MSComm1_OnComm() Dim Buffer As String Select Case MSComm1.CommEvent Case comEvReceive 'Text1.Text = " " Buffer = MSComm1.Input Text1.Text = Text1.Text & Buffer End Select End Sub
  2. bertus


    Apr 5, 2008

    I moved your thread over here, as it is related to a PIC.
    Your code is VERY hard to read as it is ALL in one line.
    Please use the code tags and line breaks for better readability.

  3. t06afre

    AAC Fanatic!

    May 11, 2009
    Are you sure your PIC send proper data. Before you start VB6 programming. You should verify your setup using a terminal program
    ErnieM likes this.
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    So, find the right one...
    If you are using Windows 7:
    You can find it by right clicking "Computer" -> "Properties" ->"Device Manager" and open the "Ports (COM & LPT)" section. Find the UART bridge that you are using. Odds are that it is not 1.

    Also, as suggested, go use a terminal program to verify that data is, indeed, being transmitted in the manner you expect: "9600,N,8,1". I use TeraTerm, but any terminal program will do this.
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Wow tshuck, did you actually read all that? I go mind blank without any white space or proper punctuation.

    One thing that drives VB6 nuts is port numbers higher then it can handle. MSCOMM was coded to handle some low number of ports, perhaps just 16. It's an artificial limit from the days when COM ports were real hardware and not virtualized USB ports.

    There are hacked version of MSCOMM on the net free to download that have this number corrected: someone went thru the trouble to reverse engineer the assembly listing of the executable to change the max port number.

    Seek and ye shall find
  6. tshuck

    Well-Known Member

    Oct 18, 2012
    I resort to skimming. If the OP hadn't mentioned the word "error", I would have happily closed the tab without another thought.

    I assume English isn't the OP's native language, so I think the question requires a little more finesse. If English is the native tongue and is from the US, well, then it proves the failure of the public school system.. for the 3.11E8th time....