Results 1 to 7 of 7

Thread: controlling rs232 voltage

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Exclamation controlling rs232 voltage

    hi.how to control voltage from rs232 using vb?i m planning on inverting the negative voltage on pin3 to positive.for example,inverting the -10V to +10V when i click the command button.i have no idea on how to do so..thanks a lot....

  2. #2
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: controlling rs232 voltage

    You can use the handshake lines of the comm-ports. These lines are accessible with the MSComm object. On the PC-side the plug layout:

    Pin1: DCD (inp)
    Pin2: RX (not used)
    Pin3: TX (not used)
    Pin4: DTR (out)
    Pin5: GND
    Pin6: DSR (inp)
    Pin7: RTS (out)
    Pin8: CTS (inp)
    Pin9: Ring (inp)

    An example how to control these lines:

    VB Code:
    1. Private Sub Form_Load()
    2.     'Init CommPort
    3.     If (MSComm1.PortOpen = False) Then
    4.         MSComm1.CommPort = 1
    5.         MSComm1.Settings = "9600,N,8,1"
    6.         MSComm1.Handshaking = comNone
    7.         MSComm1.RThreshold = 1
    8.         MSComm1.PortOpen = True
    9.     End If
    10. End Sub
    11.  
    12. Private Sub Form_Unload(Cancel As Integer)
    13.     MSComm1.PortOpen = False
    14. End Sub
    15.  
    16. Private Sub cmdDTR_Click()
    17.     'Toggle DTR
    18.     If (MSComm1.DTREnable = False) Then
    19.         MSComm1.DTREnable = True
    20.     Else
    21.         MSComm1.DTREnable = False
    22.     End If
    23. End Sub
    24.  
    25. Private Sub cmdRTS_Click()
    26.     'Toggle RTS
    27.     If (MSComm1.RTSEnable = False) Then
    28.         MSComm1.RTSEnable = True
    29.     Else
    30.         MSComm1.RTSEnable = False
    31.     End If
    32. End Sub
    33.  
    34. Private Sub MSComm1_OnComm()
    35.     Select Case MSComm1.CommEvent
    36.         'Events
    37.         Case comEvReceive
    38.         Case comEvSend
    39.         Case comEvCTS
    40.             'CTS is changed. Check value
    41.             If (MSComm1.CTSHolding = True) Then
    42.                 chkCTS.Value = 1
    43.             Else
    44.                 chkCTS.Value = 0
    45.             End If
    46.            
    47.         Case comEvDSR
    48.             'DSR is changed. Check value
    49.             If (MSComm1.DSRHolding = True) Then
    50.                 chkDSR.Value = 1
    51.             Else
    52.                 chkDSR.Value = 0
    53.             End If
    54.            
    55.         Case comEvCD
    56.             'DCD is changed. Check value
    57.             If (MSComm1.CDHolding = True) Then
    58.                 chkDCD.Value = 1
    59.             Else
    60.                 chkDCD.Value = 0
    61.             End If
    62.            
    63.         Case comEvRing
    64.             'Ring is changed. Can't check value
    65.             If (chkRing.Value = 1) Then
    66.                 chkRing.Value = 0
    67.             Else
    68.                 chkRing.Value = 1
    69.             End If
    70.            
    71.         Case comEvEOF
    72.        
    73.         'Errors
    74.         Case comEventBreak
    75.         Case comEventCDTO
    76.         Case comEventCTSTO
    77.         Case comEventDCB
    78.         Case comEventDSRTO
    79.         Case comEventFrame
    80.         Case comEventOverrun
    81.         Case comEventRxOver
    82.         Case comEventRxParity
    83.         Case comEventTxFull
    84.         Case Else
    85.     End Select
    86. End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: controlling rs232 voltage

    hi.thanks for the reply.i've try your code and succeed in controlling the voltage.but i hav one more favor to ask.do you know the command to program pic16F84 device?for example,i load a HEX file, and then i want to program the micocontroller.i've try using command:

    MSComm1.output="P"
    Sleep(100)

    i saw this command on a programmer software created in vb6.0.but i've failed to program mine.can you help me...?thanks a lot...p/s:do you know any link that develop pic programmer software in vb?thanks again
    Last edited by freakazoid; Mar 29th, 2006 at 08:38 AM.

  4. #4
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: controlling rs232 voltage

    Im sorry. I can't.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: controlling rs232 voltage

    hi again.it's all airight.just wanna tell you that my hardware is using pin 3,4,5,7,8 on rs232.so, in case you have any idea how to transfer the HEX file from vb to microcontroller,please tell me.i've try searching and searching,but can't find lot.can you verify my assumption.when i send data from pc,the data is send through pin3 on rs232, right?when data is send,the voltage change from -10V(logic 1) to +10V(logic 0).one more thing,do you think i need to use max232 to convert the signal from rs232?the signal will be sent to MCLR on pic16f84 device.thanks....

  6. #6
    Fanatic Member namrekka's Avatar
    Join Date
    Feb 2005
    Location
    Netherlands
    Posts
    639

    Re: controlling rs232 voltage

    Study the data sheet of pic-16F84. Its not an a-synchronous way of communication like RS232 but a synchronous way (with clock and data separate). I know that you can do that with the handshake lines of the comm-port. Use indeed a MAX232 to convert the signals.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: controlling rs232 voltage

    oh..i understand.i have already read the data sheet for programming pic16f84.for my circuit,pin 3 on rs232 is used for MCLR on the pic,pin4&8 used for RB7 and pin 7 used for RB6.do you have any idea how steal +5V from rs232 because my target is that the programmer is fully powered by the serial port.i know i can use voltage regulator but i'm not sure which pin on serial port do i have to use.and i don't really understand about handshaking.can you explain to me a bit..thanks again...

Posting Permissions

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



Click Here to Expand Forum to Full Width