Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Thread Closed: Issue successfully resolved

???
06/23/04 15:18
Read: times


 
#73028 - The source code HERE.
Responding to: ???'s previous message
Dim Obuffer(0) As Byte
Dim Ibuffer() As Byte
Dim Oread As Integer
Dim Serialport, BRate As Integer
Dim Setting As String

Private Sub Command2_Click()
Serialport = Val(InputBox("Using COM?", "Select COM port", 2))
MSComm1.PortOpen = 0
MSComm1.CommPort = Serialport
MSComm1.PortOpen = 1
Label4.Caption = "Currently using COM" & Serialport & Chr(13) & "Baud rate = " & BRate
End Sub

Private Sub Command3_Click()
Label4.Visible = 0
For i = 0 To 4
Option1(i).Visible = 1
Next i
Command2.Visible = 0
Command3.Visible = 0
Command4.Visible = 1
End Sub

Private Sub Command4_Click()
If Option1(0).Value Then
Setting = "1.2kbps,n,8,1"
MSComm1.Settings = "1200,n,8,1"
BRate = 1200
ElseIf Option1(1).Value Then
Setting = "2.4kbps,n,8,1"
MSComm1.Settings = "2400,n,8,1"
BRate = 2400
ElseIf Option1(2).Value Then
Setting = "4.8kbps,n,8,1"
MSComm1.Settings = "4800,n,8,1"
BRate = 4800
ElseIf Option1(3).Value Then
Setting = "9.6kbps,n,8,1"
MSComm1.Settings = "9600,n,8,1"
BRate = 9600
ElseIf Option1(4).Value Then
Setting = "19.2kbps,n,8,1"
MSComm1.Settings = "19200,n,8,1"
BRate = 19200
End If

Label4.Caption = "Currently using COM" & Serialport & Chr(13) & "Baud rate = " & BRate

Command2.Visible = 1
Command3.Visible = 1
Command4.Visible = 0

For i = 0 To 4
Option1(i).Visible = 0
Next
Label4.Visible = 1
End Sub

Private Sub Form_Load()
Serialport = 1
BRate = 1200

With MSComm1
.CommPort = Serialport
.Settings = "1200,n,8,1"
.InputMode = comInputModeBinary
.RThreshold = 2
.InputLen = 2
.PortOpen = 1
End With

Form1.Caption = "RS-232 Port Communication Module"

Label1.Caption = ""
Label2.Caption = "Output"
Label3.Caption = "Input"
Label4.Caption = "Currently using COM" & Serialport & Chr(13) & "Baud rate = " & BRate

For i = 0 To 4
Option1(i).Visible = 0
Next
Option1(0).Caption = "1.2kbps"
Option1(1).Caption = "2.4kbps"
Option1(2).Caption = "4.8kbps"
Option1(3).Caption = "9.6kbps"
Option1(4).Caption = "19.2kbps"

Text1.Text = ""
Command2.Caption = "Select COM port"
Command3.Caption = "Select Baud Rate"
Command4.Caption = "Assign Baud Rate"
Command4.Visible = 0

End Sub

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = 0
End Sub

Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvReceive Then
Ibuffer = MSComm1.Input
If Ibuffer(0) = Ibuffer(1) Then Label1.Caption = Ibuffer(0)
End If
End Sub

Private Sub Text1_Change()
Oread = Val(Text1.Text)
If (Oread < 0) Or (Oread > 255) Then Text1.Text = ""
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Oread = Val(Text1.Text)
If (Oread >= 0) And (Oread <= 255) Then
Obuffer(0) = Val(Text1.Text)
MSComm1.Output = Obuffer
MSComm1.Output = Obuffer
Text1.Text = ""
End If
Text1.Text = ""
MSComm1.InBufferCount = 0
End If
End Sub


List of 24 messages in thread
TopicAuthorDate
VB COM2 - Off topic            01/01/70 00:00      
   RE: VB COM2 - Off topic            01/01/70 00:00      
      RE: VB COM2 - Off topic            01/01/70 00:00      
   Bad style - unwarranted restriction            01/01/70 00:00      
      RE: Bad style - unwarranted restriction            01/01/70 00:00      
         RE: Wot, not serial port?!            01/01/70 00:00      
         RE: Bad style - unwarranted restriction            01/01/70 00:00      
            COM13!!            01/01/70 00:00      
               RE: COM13!!            01/01/70 00:00      
                  RE: COM13!!            01/01/70 00:00      
                     RE: COM13!!            01/01/70 00:00      
                        RE: COM13!!            01/01/70 00:00      
      How?            01/01/70 00:00      
         RE: How?            01/01/70 00:00      
         RE: How?            01/01/70 00:00      
            RE: How?            01/01/70 00:00      
      RE: Bad style - unwarranted restriction            01/01/70 00:00      
   RE: VB COM2 - Off topic            01/01/70 00:00      
   The Result            01/01/70 00:00      
      RE: The Result            01/01/70 00:00      
      RE: The Result            01/01/70 00:00      
   RE: VB COM2 - Off topic            01/01/70 00:00      
   The source code HERE.            01/01/70 00:00      
   Or the Whole achieve in Zip file            01/01/70 00:00      

Back to Subject List