Chương trình điều khiển trên máy tính

Một phần của tài liệu đồ án trang bị điện máy cắt khí ga oxy (Trang 27 - 35)

Hình 3.2. Giao diện điều khiển. b. Code lệnh điều khiển.

Const LimX = 255 Const LimY = 255 Dim Dung As Boolean Dim x1 As Byte

Dim x2 As Byte Dim y1 As Byte Dim y2 As Byte

Private Sub About_Click() frmAbout.Show

End Sub

Private Sub cmdLen_Click() If y2 <= 255 Then

If MSComm1.PortOpen = False Then

MsgBox "Cong COM chua duoc ket noi", vbInformation, "Thong bao"

Exit Sub Else

y2 = y2 + 1

pic1.Line -(x2, y2), vbBlue

Text1.Text = "x = " + Str(x2) + " , y = " + Str(y2) End If Else Exit Sub End If End Sub

Private Sub cmdPhai_Click() If x2 <= 255 Then

If MSComm1.PortOpen = False Then

MsgBox "Cong COM chua duoc ket noi", vbInformation, "Thong bao"

Exit Sub Else

MSComm1.Output = "*P#" x2 = x2 + 1

pic1.Line -(x2, y2), vbBlue

Text1.Text = "x = " + Str(x2) + " , y = " + Str(y2) End If Else Exit Sub End If End Sub

Private Sub cmdstart_Click() KhacTruc

Private Sub cmdstop_Click() End

End Sub

Private Sub cmdTrai_Click() If x2 > 0 Then

If MSComm1.PortOpen = False Then

MsgBox "Cong COM chua duoc ket noi", vbInformation, "Thong bao"

Exit Sub Else

MSComm1.Output = "*T#" x2 = x2 - 1

pic1.Line -(x2, y2), vbBlue

Text1.Text = "x = " + Str(x2) + " , y = " + Str(y2) End If Else Exit Sub End If End Sub

Private Sub cmdXuong_Click() If y2 > 0 Then

If MSComm1.PortOpen = False Then

MsgBox "Cong COM chua duoc ket noi", vbInformation, "Thong bao"

Exit Sub Else

MSComm1.Output = "*X#" y2 = y2 - 1

Text1.Text = "x = " + Str(x2) + " , y = " + Str(y2) End If Else Exit Sub End If End Sub

Private Sub Command1_Click() pic1.Cls

KhacTruc End Sub

Private Sub Exit_Click() End

End Sub

Private Sub Form_Load() pic1.ScaleMode = 6

pic1.Scale (-10, LimY)-(LimX, -10)

Text1.Text = "x = " + Str(x2) + " , y = " + Str(y2) End Sub

Private Sub help_Click() frmHelp.Show

End Sub

Private Sub Load_Click()

If MSComm1.PortOpen = False Then MSComm1.PortOpen = True

MsgBox "Cong COM da duoc ket noi", vbInformation, "Thong bao"

Else

End If End Sub

Private Sub stcomport_Click() frmSetting.Show

End Sub

Private Sub TinhToan() Dim F As Single

NhapDT

If Dung = False Then Exit Sub

Else

If MSComm1.PortOpen = False Then

MsgBox "Cong COM chua duoc ket noi", vbInformation, "Thong bao"

Exit Sub Else

pic1.Line (x1, y1)-(x2, y2), vbRed

MSComm1.Output = "*" + Chr(65) + Chr(x1) + Chr(y1) + Chr(x2) + Chr(y2) + "#" Text2 = "*" + Chr(65) + Chr(x1) + Chr(y1) + Chr(x2) + Chr(y2) + "#" Text1.Text = "x = " + Str(x2) + " , y = " + Str(y2) End If End If End Sub

Private Sub KhacTruc() Dim i As Integer

pic1.Line (i, 2)-(i, -2) pic1.CurrentY = 0

pic1.CurrentX = pic1.CurrentX - 5 pic1.Print i

Next i

For i = 0 To LimY - 20 Step 10 pic1.Line (-2, i)-(2, i) pic1.CurrentX = 0 pic1.CurrentY = pic1.CurrentY + 3 pic1.Print i Next i 'Ke truc

pic1.Line (-LimX + 10, 0)-(LimX - 10, 0) pic1.Line (0, LimX - 10)-(0, -LimX + 10) 'Ve mui ten

pic1.Line (LimX - 20, 2)-(LimX - 10, 0) pic1.Line -(LimX - 20, -2)

pic1.Line (-2, LimY - 20)-(0, LimY - 10) pic1.Line -(2, LimY - 20) pic1.Line (0, 0)-(0, 0) x2 = 0 y2 = 0 Text1.Text = "x = " + Str(x2) + " , y = " + Str(y2) End Sub

Private Sub toolStart_Click() KhacTruc

TinhToan End Sub

If MSComm1.PortOpen = True Then MSComm1.PortOpen = False

MsgBox "Cong COM da duoc ngat ket noi", vbInformation, "Thong bao"

Else

MsgBox "Cong COM da duoc ngat ket noi", vbInformation, "Thong bao"

End If End Sub

Private Sub NhapDT()

x1 = Val(txtdtX1.Text) x2 = Val(txtdtX2.Text) y1 = Val(txtdtY1.Text) y2 = Val(txtdtY2.Text) If x1 < 0 Or x1 > 255 Or x2 < 0 Or x2 > 255 Or y1 < 0 Or y1 > 255 Or y2 < 0 Or y2 > 255 Then

MsgBox "Xin hay nhap toa do nho hon 255", vbInformation, "Chu y"

Dung = False Exit Sub Else Dung = True End If End Sub

Một phần của tài liệu đồ án trang bị điện máy cắt khí ga oxy (Trang 27 - 35)

Tải bản đầy đủ (DOC)

(48 trang)
w