You are on page 1of 7

BI GII THI GIA K LKBMT HK2/ 2010-2011

1/ i chng trnh STL sang LAD LDN I0.0 LPS AD<> MD0, 20 LPS AN I0.1 MOVW MW4, MW8 DIV MW2, MD6 LPP AN I0.2 INCW VW4 LRD A I0.4 LPS A = LPP A A S V0.4, 2 LPP A M0.3 AN M0.4 TONR T3, 30

V0.0 V0.1 V0.2 V0.3

3/ Vit chng trnh PLC nhn d liu ni tip dng m ASCII, baudrate 19200. Lnh th nht

k t A sau l su byte, s c PLC ct vo ba nh t VB0, dng lm chu k xung v s lng xung cho lnh pht xung PTO Q0.0. Lnh th hai BC cho M0.0 ON.. Khi nhn c d liu PLC gi tr li thng tin nhn, nu M0.0 chuyn trng thi t OFF sang ON th PLC cho M0.0 OFF v pht xung, pht xung gi ln my tnh k t @

Ngt RCV INT4

Ngt PLS INT1

Ngt pht INT0

4/ Vit chng trnh VB gi v nhn d liu vi PLC nh hnh di

Trong txtPeriod g hai s hex, txtNumber g bn s hex, bm cmdSend gi lnh th nht (cu 3), bm nt cmdRun gi lnh th hai. Khi PLC gi tr li lnh th nht hin th su byte trong hai text dng s nguyn, khi PLC gi tr li lnh th hai cho n shpRun mu xanh, khi PLC gi @ cho n ny mu . Khi my tnh gi lnh, nu sau 0.1s khng nhn c tr li t PLC th bo nhn lblError NOT CONNECTED
Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long Dim datain Dim received Dim timeout Private Sub cmdQuit_Click() MSComm1.PortOpen = False End End Sub Private Sub cmdRun_Click() lblError.Visible = False datain = "" Shape1.FillColor = vbRed MSComm1.Output = "BC" Timer1.Enabled = True received = False End Sub Private Sub cmdSend_Click() lblError.Visible = False datain = "" MSComm1.InBufferCount = 0 Text3.Text = "" Text4.Text = "" datain = "" MSComm1.Output = "A" & Text1.Text & Text2.Text cmdRun.Enabled = True

Timer1.Enabled = True received = False End Sub Private Sub Form_Load() With MSComm1 .CommPort = 3 .Settings = "19200,n,8,1" .RThreshold = 1 .InputLen = 0 .PortOpen = True End With lblError.Visible = False Timer1.Interval = 500 Timer1.Enabled = False Text1.Text = 12 Text2.Text = 3456 cmdRun.Enabled = False received = False datain = "" End Sub

Private Sub MSComm1_OnComm() If MSComm1.InBufferCount > 0 Then received = True datain = datain & MSComm1.Input End If Text5.Text = datain If (Mid(datain, 1, 2) = "BC") Then Shape1.FillColor = vbBlue cmdRun.Enabled = False datain = "" End If If (Mid(datain, 1, 1) = "A") And Len(datain) > 6 Then Text3.Text = Val("&h " & Mid(datain, 2, 2)) Text4.Text = Val("&h" & Mid(datain, 4, 4)) datain = "" End If If Mid(datain, 1, 1) = "@" Then Shape1.FillColor = vbRed cmdRun.Enabled = True Beep 2000, 500 datain = "" End If End Sub Private Sub Timer1_Timer() If Not (received) Then lblError.Visible = True

Beep 1000, 200 timeout = True End If Timer1.Enabled = False End Sub