回复 11楼 yuma
你好:
1,目前窗體可以以設定的秒數進行偵測最新日記,同時也顯示在Text1的上面,如下圖:
2,目前已寫出了十六進制發送給控制模塊的 吸合和斷開,通過驗證能正常控制OK。(目前是使用Command1來啟用的)
2,能實現此功能嗎:a,當Text1裡面每出現一次新的日記出來,就自動進行一次 控制模塊的吸合及斷開。
代碼如下:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim WithEvents Timer1 As Timer '循環 按照 設定秒數 進行觸發
'----通過串口發送十六進制55 01 01 02 00 00 00 59 繼電器吸合---------------------------------------------------------------
Private Sub Command1_Click() '閉合
Dim b(7) As Byte '这里A(0)表示定义的数组是含有下标上限为0的数组.
b(0) = &H55
b(1) = &H1
b(2) = &H1
b(3) = &H2
b(4) = &H0
b(5) = &H0
b(6) = &H0
b(7) = &H59
'a(8) = &H59
'sj(3) = &H3
MSComm1.Output = b
'-----通過串口發送十六進制55 01 01 01 00 00 00 58 繼電器斷開---------------------------------------------------------------
Sleep 2000 '等待2S
Dim c(7) As Byte '这里A(0)表示定义的数组是含有下标上限为0的数组.
c(0) = &H55
c(1) = &H1
c(2) = &H1
c(3) = &H1
c(4) = &H0
c(5) = &H0
c(6) = &H0
c(7) = &H58
'a(8) = &H59
'sj(3) = &H3
MSComm1.Output = c
End Sub
'------------------------------------------------------------------------------------------------------------------------
Private Sub Form_Load()
'---------------窗體載入 RS232設定內容-----------------------------------------
= 1
MSComm1.PortOpen = True
MSComm1.Settings = "9600,n,8,1"
'----------用代码创建一个Timer1控件,不用往窗体拖Timer1控件----------
Set Timer1 = Me.Controls.Add("VB.Timer", "Timer1")
Timer1.Enabled = True
Timer1.Interval = 5000 '5000ms
End Sub
Private Sub Timer1_Timer()
Dim ymd As String '日期变量
Dim FileName As String '文件名变量
Dim Str As String '读取到的数据内容变量
Dim FilePath As String '完整的文件名变量
FilePath = "C:\ew518fe\ES340A\" '日志.LOG的文件夹
ymd = Year(Date) & String(2 - Len(Month(Date)), "0") & Month(Date) & String(2 - Len(Day(Date)), "0") & Day(Date)
FileName = "ODBC" & ymd & ".LOG"
'Print FileName
Cls '清除窗体上一次显示的信息
If Dir(FilePath, vbDirectory + vbHidden) = "" Then
Form1.Print "日志文件目录不存在!"
ElseIf Dir(FilePath & FileName) = "" Then
Form1.Print "今天没有新日志文件!"
Else
Open FilePath & FileName For Input As #1
While Not EOF(1)
Line Input #1, Str
a = a + 1
Wend
'DoEvents
Close #1
If Str <> "" Then
'Form1.Print Str
Text1 = Str
Else
Form1.Print "有日志文件,但日志内容为空!"
End If
End If
End Sub