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....
Printable View
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....
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:
Private Sub Form_Load() 'Init CommPort If (MSComm1.PortOpen = False) Then MSComm1.CommPort = 1 MSComm1.Settings = "9600,N,8,1" MSComm1.Handshaking = comNone MSComm1.RThreshold = 1 MSComm1.PortOpen = True End If End Sub Private Sub Form_Unload(Cancel As Integer) MSComm1.PortOpen = False End Sub Private Sub cmdDTR_Click() 'Toggle DTR If (MSComm1.DTREnable = False) Then MSComm1.DTREnable = True Else MSComm1.DTREnable = False End If End Sub Private Sub cmdRTS_Click() 'Toggle RTS If (MSComm1.RTSEnable = False) Then MSComm1.RTSEnable = True Else MSComm1.RTSEnable = False End If End Sub Private Sub MSComm1_OnComm() Select Case MSComm1.CommEvent 'Events Case comEvReceive Case comEvSend Case comEvCTS 'CTS is changed. Check value If (MSComm1.CTSHolding = True) Then chkCTS.Value = 1 Else chkCTS.Value = 0 End If Case comEvDSR 'DSR is changed. Check value If (MSComm1.DSRHolding = True) Then chkDSR.Value = 1 Else chkDSR.Value = 0 End If Case comEvCD 'DCD is changed. Check value If (MSComm1.CDHolding = True) Then chkDCD.Value = 1 Else chkDCD.Value = 0 End If Case comEvRing 'Ring is changed. Can't check value If (chkRing.Value = 1) Then chkRing.Value = 0 Else chkRing.Value = 1 End If Case comEvEOF 'Errors Case comEventBreak Case comEventCDTO Case comEventCTSTO Case comEventDCB Case comEventDSRTO Case comEventFrame Case comEventOverrun Case comEventRxOver Case comEventRxParity Case comEventTxFull Case Else End Select End Sub
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
Im sorry. I can't.
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....
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.
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...