thầy giáo bắt về đọc hiểu trong khi chưa hoc tí gì về cái này , mấy ngaỳ hôm nay ngồi đọc tài liệu visual đau ca mắt mà chưa ra. căn bản m mới học về c thui Nhờ các bác nhé. thanks nhiu!
đoạn code viết để truyền nhận cổng Com :
Option Explicit
Dim ok As Boolean
Dim T As Boolean
'khoi tao com1
Private Sub Command1_Click()
On Error GoTo Thoat
If ok Then Me.MSComm1.PortOpen = False
Me.Command2.Enabled = True
Me.MSComm1.CommPort = 1
Me.MSComm1.Settings = Me.Combo1.Text + ",N,8,1"
Me.MSComm1.InputLen = 0
Me.MSComm1.PortOpen = True
Me.Command1.Enabled = False
Me.Command2.Enabled = True
Me.Text1.Enabled = True
ok = True
If ok Then Me.MSComm2.PortOpen = False
Me.Command2.Enabled = True
Me.MSComm2.CommPort = 2
Me.MSComm2.Settings = Me.Combo1.Text + ",N,8,1"
Me.MSComm2.InputLen = 0
Me.MSComm2.PortOpen = True
Me.Command2.Enabled = False
Me.Command2.Enabled = True
Exit Sub
Thoat:
If Err.Number = 8005 Then
MsgBox "Com1 da su dung!" + Space(15), vbInformation, "Message"
End If
ok = False
End Sub
'khoi tao com 2
Private Sub Command2_Click()
On Error GoTo Thoat
If ok Then Me.MSComm1.PortOpen = False
Me.Command1.Enabled = True
Me.MSComm1.CommPort = 2
Me.MSComm1.Settings = Me.Combo1.Text + ",N,8,1"
Me.MSComm1.InputLen = 0
Me.MSComm1.PortOpen = True
Me.Command2.Enabled = False
Me.Command1.Enabled = True
Me.Text1.Enabled = True
ok = True
Exit Sub
Thoat:
If Err.Number = 8005 Then
MsgBox "Com2 da su dung!" + Space(15), vbInformation, "Message"
End If
ok = False
End Sub
Private Sub Send_Click()
Me.MSComm1.Output = Chr(&HAA&) + "1234567890P"
End Sub
Private Sub Command4_Click()
Unload Form2
End Sub
'
Private Sub Form_Load()
ok = False
T = True
Me.Show
While (T)
If Me.MSComm1.InBufferCount > 0 Then
Me.Text2.Text = Me.Text2.Text + Me.MSComm2.Input
End If
DoEvents
Wend
End Sub
Private Sub Form_Unload(Cancel As Integer)
If ok Then Me.MSComm1.PortOpen = False
T = False
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Me.MSComm1.Output = Chr(KeyAscii)
End Sub
Private Sub Truyen_Click()
End Sub
đoạn code viết để truyền nhận cổng Com :
Option Explicit
Dim ok As Boolean
Dim T As Boolean
'khoi tao com1
Private Sub Command1_Click()
On Error GoTo Thoat
If ok Then Me.MSComm1.PortOpen = False
Me.Command2.Enabled = True
Me.MSComm1.CommPort = 1
Me.MSComm1.Settings = Me.Combo1.Text + ",N,8,1"
Me.MSComm1.InputLen = 0
Me.MSComm1.PortOpen = True
Me.Command1.Enabled = False
Me.Command2.Enabled = True
Me.Text1.Enabled = True
ok = True
If ok Then Me.MSComm2.PortOpen = False
Me.Command2.Enabled = True
Me.MSComm2.CommPort = 2
Me.MSComm2.Settings = Me.Combo1.Text + ",N,8,1"
Me.MSComm2.InputLen = 0
Me.MSComm2.PortOpen = True
Me.Command2.Enabled = False
Me.Command2.Enabled = True
Exit Sub
Thoat:
If Err.Number = 8005 Then
MsgBox "Com1 da su dung!" + Space(15), vbInformation, "Message"
End If
ok = False
End Sub
'khoi tao com 2
Private Sub Command2_Click()
On Error GoTo Thoat
If ok Then Me.MSComm1.PortOpen = False
Me.Command1.Enabled = True
Me.MSComm1.CommPort = 2
Me.MSComm1.Settings = Me.Combo1.Text + ",N,8,1"
Me.MSComm1.InputLen = 0
Me.MSComm1.PortOpen = True
Me.Command2.Enabled = False
Me.Command1.Enabled = True
Me.Text1.Enabled = True
ok = True
Exit Sub
Thoat:
If Err.Number = 8005 Then
MsgBox "Com2 da su dung!" + Space(15), vbInformation, "Message"
End If
ok = False
End Sub
Private Sub Send_Click()
Me.MSComm1.Output = Chr(&HAA&) + "1234567890P"
End Sub
Private Sub Command4_Click()
Unload Form2
End Sub
'
Private Sub Form_Load()
ok = False
T = True
Me.Show
While (T)
If Me.MSComm1.InBufferCount > 0 Then
Me.Text2.Text = Me.Text2.Text + Me.MSComm2.Input
End If
DoEvents
Wend
End Sub
Private Sub Form_Unload(Cancel As Integer)
If ok Then Me.MSComm1.PortOpen = False
T = False
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Me.MSComm1.Output = Chr(KeyAscii)
End Sub
Private Sub Truyen_Click()
End Sub