?? frmmodel.frm
字號:
InitFail: MsgBox "初始化出錯!"
CmdInit.Enabled = False
Exit Sub
smscfail: MsgBox "請輸入短消息中心號碼!"
End Sub
Private Sub CmdopenCOM_Click()
Dim buf$, retbuf$, rate%, ratebuf$
'判斷通信端口是否落在1-16之間
If CmbCOM.ListIndex >= 0 And CmbCOM.ListIndex <= 16 Then
MSComm1.CommPort = CmbCOM.ListIndex + 1
Else
MsgBox "指定通信口時發(fā)生錯誤!", vbCritical + vbOKOnly, "系統(tǒng)信息"
Exit Sub
End If
'激活錯誤檢測機制
On Error GoTo comerr
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
CmdOpenCOM.Enabled = False
' CmdStart.Enabled = True
lblmsg.Caption = "可單擊【開始檢測】按鈕,執(zhí)行檢測工作"
buf = Cmb4024.List(Cmb4024.ListIndex)
If Len(buf) = 1 Then
buf = "0" & buf
End If
MSComm1.Output = "#" & buf & Format(0, "00.000") & Chr(13)
retbuf = waitRS(MSComm1, vbCr, 1000)
Pic1.Cls
Pic2.Cls
Pic3.Cls
Pic4.Cls
Pic5.Cls
Pic6.Cls
n1 = 0
n2 = 0
n3 = 0
n4 = 0
n5 = 0
n6 = 0
Timer3.Interval = 200
Frame1.Enabled = True
CmdOpenCOM.Enabled = False
' Cmdsetting.Enabled = True
Frame1.Enabled = False
'Frame2.Enabled = True
CmdStart.Enabled = True
CmdEnd.Enabled = True
Exit Sub
comerr:
MsgBox "打開通信端口時發(fā)生錯誤!請確定通信端口是否存在且正常。", vbCritical + vbOKOnly, "系統(tǒng)信息"
End Sub
Private Sub Cmdsetting_Click()
limit1 = Text1.Text
limit2 = Text2.Text
limit3 = Text3.Text
limit4 = Text4.Text
limit5 = Text5.Text
limit6 = Text6.Text
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Or Text5.Text = "" Or Text6.Text = "" Then
MsgBox "請輸入門限值!"
Else
' CmdStart.Enabled = True
Cmdsetting.Enabled = False
End If
End Sub
Private Sub CmdStart_Click()
Timer1.Enabled = Not Timer1.Enabled
Timer3.Interval = 100
If Timer1.Enabled Then
CmdStart.Caption = "停止檢測"
Else
CmdStart.Caption = "開始檢測"
lblmsg.Caption = "已停止檢測"
End If
End Sub
Private Sub Form_Load()
Dim str As String
Dim i As Integer
MaxPlotNo = 100
n1 = 0
Cmb4017.Clear
For i = 1 To 255
Cmb4017.AddItem CStr(Hex(i))
Cmb4024.AddItem CStr(Hex(i))
Next i
Cmb4017.ListIndex = 0
Cmb4024.ListIndex = 1
CmbCOM.Clear
CmbCOM.AddItem "COM1"
CmbCOM.AddItem "COM2"
CmbCOM.AddItem "COM3"
CmbCOM.AddItem "COM4"
'加一個串口
CmbCOM.ListIndex = 2
port(0) = "1"
port(1) = "2"
port(2) = "3"
port(3) = "4"
port(4) = "5"
For i = 0 To 4
CmbPort.AddItem port(i)
Next i
CmbPort.ListIndex = 0
sendcmb(0) = "+8613880416076"
SendNOCmb.AddItem sendcmb(0)
smsc(0) = "+8613800280500"
smsc(1) = "+8613010811500"
For i = 0 To 1
CmbSMSC.AddItem smsc(i)
Next i
CmbSMSC.ListIndex = 0
' CmdStart.Enabled = False
Pic1.Scale (0, 10)-(MaxPlotNo, -10)
Pic1.DrawWidth = 2
Pic2.Scale (0, 10)-(MaxPlotNo, -10)
Pic2.DrawWidth = 2
Pic3.Scale (0, 10)-(MaxPlotNo, -10)
Pic3.DrawWidth = 2
Pic4.Scale (0, 10)-(MaxPlotNo, -10)
Pic4.DrawWidth = 1
Pic5.Scale (0, 10)-(MaxPlotNo, -10)
Pic5.DrawWidth = 1
Pic6.Scale (0, 10)-(MaxPlotNo, -10)
Pic6.DrawWidth = 1
Pic2.Visible = False
Pic3.Visible = False
Pic4.Visible = False
Pic5.Visible = False
Pic6.Visible = False
'動態(tài)鏈接數據庫
str = App.Path
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & str & "\db1.mdb;Persist Security Info=False"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from 鉆井數據表"
Adodc1.Refresh
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & str & "\db1.mdb;Persist Security Info=False"
Adodc2.CommandType = adCmdText
Adodc2.RecordSource = "select * from 發(fā)送人員表"
Adodc2.Refresh
Adodc3.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & str & "\db1.mdb;Persist Security Info=False"
Adodc3.CommandType = adCmdText
Adodc3.RecordSource = "select * from 人員短信回復表"
Adodc3.Refresh
End Sub
Private Sub Slider1_Click()
Dim buf$, valuestr As Single, pos1%, flag As Boolean
Dim retbuf$
If CmdOpenCOM.Enabled Then
lblmsg.Caption = "尚未打開通信端口"
Exit Sub
End If
buf = Cmb4024.List(Cmb4024.ListIndex)
If Len(buf) = 1 Then
buf = "0" & buf
End If
lblvalue.Caption = Slider1.Value / 10 & "V"
'發(fā)送模擬命令
MSComm1.Output = "#" & buf & "C0+" & Format(Slider1.Value / 10, "00.000") & Chr(13)
lblmsg.Caption = "聯機" & buf & "中......"
retbuf = waitRS(MSComm1, vbCr, 1000)
If retbuf = "" Then
lblmsg.Caption = "輸出電壓失敗"
Exit Sub
End If
MSComm1.Output = "$" & buf & "6C0" & Chr(13)
retbuf = waitRS(MSComm1, vbCr, 1000)
If retbuf = "" Or Len(retbuf) < 9 Then
lblmsg.Caption = "讀回失敗"
Exit Sub
End If
lblreadBack.Caption = Val(Mid(retbuf, 4, 6)) & "V"
End Sub
Private Sub Timer1_Timer()
Dim i1%, s1$, smsc$, sms1$
Dim c1&, c2&, c3&, c4&, c5&, c6&
Dim s2$, s3$, sms2$, sendno$
Dim buf$, sendno1$
Dim pos1%
Dim DAValue As Single, retbuf$
Dim flag As Boolean
Dim flag1 As Boolean, flag2 As Boolean, flag3 As Boolean, flag4 As Boolean, flag5 As Boolean, flag6 As Boolean
Dim i&, X!, Y!
Dim l1&, l2&, l3&, l4&, l5&, l6&
buf = Cmb4017.List(Cmb4017.ListIndex) '取得4017+的地址號碼
If Len(buf) = 1 Then
buf = "0" & buf
End If
MSComm1.Output = "#" & buf & Chr(13) '發(fā)送采集命令,采集所有通道數據
lblmsg.Caption = "聯機" & buf & "中......"
buf = waitRS(MSComm1, vbCr, 1000)
If buf = "" Then
lblmsg.Caption = "取值失敗"
Exit Sub
End If
pos1 = InStr(1, buf, ">")
If pos1 = 0 Then
lblmsg.Caption = "返回值不正確"
Exit Sub
End If
'進行數據分離,并顯示出來
StandpipeTxt.Text = Mid(buf, pos1 + 1, 7)
TorqueTxt.Text = Mid(buf, pos1 + 8, 7)
LevelTxt.Text = Mid(buf, pos1 + 15, 7)
FlowTxt.Text = Mid(buf, pos1 + 22, 7)
LoadTxt.Text = Mid(buf, pos1 + 29, 7)
SpeedTxt.Text = Mid(buf, pos1 + 36, 7)
'畫出所有參數實時曲線圖
flag1 = plot(StandpipeTxt.Text, Pic1, n1, prevalue1)
flag2 = plot(TorqueTxt.Text, Pic2, n2, prevalue2)
flag3 = plot(LevelTxt.Text, Pic3, n3, prevalue3)
flag4 = plot(FlowTxt.Text, Pic4, n4, prevalue4)
flag5 = plot(LoadTxt.Text, Pic5, n5, prevalue5)
flag6 = plot(SpeedTxt.Text, Pic6, n6, prevalue6)
'顯示單個參數實時曲線圖
If OptStandpipe.Value = True Then
Pic2.Visible = False
Pic3.Visible = False
Pic4.Visible = False
Pic5.Visible = False
Pic6.Visible = False
Pic1.Visible = True
ElseIf OptTorque.Value = True Then
Pic1.Visible = False
Pic3.Visible = False
Pic4.Visible = False
Pic5.Visible = False
Pic6.Visible = False
Pic2.Visible = True
ElseIf OptLevel.Value = True Then
Pic1.Visible = False
Pic2.Visible = False
Pic4.Visible = False
Pic5.Visible = False
Pic6.Visible = False
Pic3.Visible = True
ElseIf OptFlow.Value = True Then
Pic1.Visible = False
Pic2.Visible = False
Pic3.Visible = False
Pic5.Visible = False
Pic6.Visible = False
Pic4.Visible = True
ElseIf OptLoad.Value = True Then
Pic1.Visible = False
Pic2.Visible = False
Pic3.Visible = False
Pic4.Visible = False
Pic6.Visible = False
Pic5.Visible = True
ElseIf OptSpeed.Value = True Then
Pic1.Visible = False
Pic2.Visible = False
Pic3.Visible = False
Pic4.Visible = False
Pic5.Visible = False
Pic6.Visible = True
End If
c1 = Val(StandpipeTxt.Text)
c2 = Val(TorqueTxt.Text)
c3 = Val(LevelTxt.Text)
c4 = Val(FlowTxt.Text)
c5 = Val(LoadTxt.Text)
c6 = Val(SpeedTxt.Text)
Timer2.Enabled = True
'簡單判斷是否發(fā)生復雜情況
If c1 > 10 Or c2 > 10 Or c3 > 10 Or c4 > 10 Or c5 > 10 Or c6 > 10 Then
'若發(fā)生復雜情況,把鉆井數據發(fā)送到遠程技術人員手機上
Timer1.Enabled = False
Timer3.Enabled = False
send = StandpipeTxt.Text & ";" & TorqueTxt.Text & ";" & LevelTxt.Text & ";" & FlowTxt.Text & ";" & LoadTxt.Text & ";" & LoadTxt.Text & ";" & SpeedTxt.Text
sendno1 = SendNOCmb.Text
flag = sendSMS(MSComm2, CmbSMSC.Text, sendno1, send)
If Not flag Then
GoTo senderr
Else
Timer3.Enabled = True
timedelay (1000)
End If
End If
Timer1.Enabled = True
Exit Sub
senderr: MsgBox "發(fā)送失敗"
End Sub
Private Sub Timer2_Timer()
'把采集到的鉆井數據存入數據庫
Adodc1.Recordset.AddNew
Adodc1.Recordset("時間") = Now()
Adodc1.Recordset("立管壓力") = StandpipeTxt.Text
Adodc1.Recordset("轉盤扭矩") = TorqueTxt.Text
Adodc1.Recordset("泥漿池液位") = LevelTxt.Text
Adodc1.Recordset("泥漿泵流量") = FlowTxt.Text
Adodc1.Recordset("大鉤負荷") = LoadTxt.Text
Adodc1.Recordset("轉盤轉速") = SpeedTxt.Text
Adodc1.Recordset.Update
End Sub
Private Sub Timer3_Timer() '定時查詢緩沖區(qū),檢查是否收到新的短信息
Dim buf As String
Dim dummyar As String, i1 As String, i2 As Integer, i3 As String
Dim s1 As String, s2 As String, s3 As String
Dim r1 As String, r2 As String, r3 As String
Dim year As String, month As String, day As String, time As String
Dim flag As Boolean
If MSComm2.InBufferCount > 0 Then
buf = buf + MSComm2.Input
If InStr(buf, "+CMTI:") Then
MsgBox "收到新短信!"
Timer3.Interval = 0
Timer1.Enabled = False
MSComm2.InBufferCount = 0
i1 = InStr(buf, ",")
s1 = Mid(buf, i1 + 1, 2)
MSComm2.Output = "AT+CMGR=" + Trim(s1) + vbCr '發(fā)送讀短消息命令
timedelay (200) '延時
buf = waitRS(MSComm2, "OK", 1000)
i2 = InStr(buf, "0891")
s2 = Mid(buf, i2)
i3 = InStr(i2, s2, vbCr)
s3 = Mid(s2, 1, i3 - 1)
readSMS (s3)
year = Mid(rTime, 1, 2)
month = Mid(rTime, 3, 2)
day = Mid(rTime, 5, 2)
r1 = Mid(rTime, 7, 2)
r2 = Mid(rTime, 9, 2)
r3 = Mid(rTime, 11, 2)
time = year & "-" & month & "-" & day & " " & r1 & ":" & r2 & ":" & r3
'把接收到的短消息存入數據庫
Adodc3.Recordset.AddNew
Adodc3.Recordset("手機號碼") = rNo
Adodc3.Recordset("SMSC號碼") = rSMSC
Adodc3.Recordset("時間") = time
Adodc3.Recordset("短信內容") = rSMS
Adodc3.Recordset.Update
If rSMS = "收到" Then
FrameOutput.Enabled = True
ElseIf rSMS = "查詢" Then
send = StandpipeTxt.Text & ";" & TorqueTxt.Text & ";" & LevelTxt.Text & ";" & FlowTxt.Text & ";" & LoadTxt.Text & ";" & LoadTxt.Text & ";" & SpeedTxt.Text
flag = sendSMS(MSComm2, CmbSMSC.Text, rNo, send)
If Not flag Then
GoTo senderr
Else
Timer1.Enabled = True
End If
End If
Timer1.Enabled = True
End If
End If
Timer3.Interval = 100
Exit Sub
senderr: MsgBox "查詢信息失??!"
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -