Hello. I'm doing a project that require a sensor to be connect to my VB application. I've decided to use serial port as it intermediate. so how to write the programming for serial port and how to set it baud rate ? Thanx
Printable View
Hello. I'm doing a project that require a sensor to be connect to my VB application. I've decided to use serial port as it intermediate. so how to write the programming for serial port and how to set it baud rate ? Thanx
Start a Standard EXE Project.
From the Projects Menu, Go to Components.
Check the box for "Microsoft Comm Control 6.0"
Apply and close the Dialog.
You should now have a new Component on the tool palette shown as a phone.
Put this on your form.
You can set the Properties, including the baud rate, from the properties window. There is even a Custom Propeties Dialog for the control.
If you need help on using the control, there is an example in the help files that looks like this:
VB Code:
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 = False End Sub
I hope this will get you started.
StonetheCrows.