PDA

View Full Version : St 232



jmti
01-17-2007, 10:49 AM
how to create program·by using visual basic 6.0·to send and receive data with rs232·and connected by hardware chip·ST232.

private sub form_load ()

MSComm1.ComPort = 1
MSComm1.DTFEnable = False
MSComm1.Setting = "2400,N,8,1"
MSComm1.OpenPort = True
End sub

i try this code but nothing happen... plse help me.

Franklin
01-17-2007, 10:53 AM
What are you connecting to and how? (show us, please)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen

KatyBri
01-17-2007, 12:52 PM
You have set the MSCOMM controls communications properties, but you have no code to read the communications buffer. There are several ways to do this, here is an example from VB6's help files-

note: The DO .... LOOP code in the example below is where the input buffer contents are being read. You will need to modify this code to suit your needs.

MSComm Control Example

The following simple example shows basic serial communications using a modem:

Private Sub Form_Load () ' Buffer to hold input string Dim Instring As String ' Use COM1. MSComm1.CommPort = 1 ' 9600 baud, no parity, 8 data, and 1 stop bit. MSComm1.Settings = "9600,N,8,1" ' Tell the control to read entire buffer when Input ' is used. MSComm1.InputLen = 0 ' Open the port. MSComm1.PortOpen = True ' Send the attention command to the modem. MSComm1.Output = "ATV1Q0" & Chr$(13) ' Ensure that ' the modem responds with "OK". ' Wait for data to come back to the serial port. Do DoEvents Buffer$ = Buffer$ & MSComm1.Input Loop Until InStr(Buffer$, "OK" & vbCRLF) ' Read the "OK" response data in the serial port. ' Close the serial port. MSComm1.PortOpen = FalseEnd Sub
Note···The MSComm control can use polling or an event-driven method to retrieve data from the port. This simple example uses the polling method. For an example of the event-driven method, see help for the OnComm event.

OnComm Event Example

The following example shows how to handle communications errors and events. You can insert code after each related Case statement, to handle a particular error or event.

Private Sub MSComm_OnComm () Select Case MSComm1.CommEvent ' Handle each event or error by placing ' code below each case statement ' Errors Case comEventBreak ' A Break was received. Case comEventFrame ' Framing Error Case comEventOverrun ' Data Lost. Case comEventRxOver ' Receive buffer overflow. Case comEventRxParity ' Parity Error. Case comEventTxFull ' Transmit buffer full. Case comEventDCB ' Unexpected error retrieving DCB] ' Events Case comEvCD ' Change in the CD line. Case comEvCTS ' Change in the CTS line. Case comEvDSR ' Change in the DSR line. Case comEvRing ' Change in the Ring Indicator. Case comEvReceive ' Received RThreshold # of ' chars. Case comEvSend ' There are SThreshold number of ' characters in the transmit ' buffer. Case comEvEof ' An EOF charater was found in ' the input stream End SelectEnd Sub

Hope this helps.

Chris Savage
01-17-2007, 11:51 PM
Is there a BASIC Stamp in this circuit?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support