⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.vb

📁 广西百色247台电视发射机监控源代码.已经过实践
💻 VB
📖 第 1 页 / 共 5 页
字号:
                        KTDsendOrReceive(trans, 3, "00", False)
                    End If
                End If
                If trans.Saturday(1) Is Nothing Then
                Else
                    If OnOffFlag(trans.Saturday(1)) = True Then
                        KTDsendOrReceive(trans, 4, "00", False)
                    End If
                End If
            Case DayOfWeek.Sunday
                If trans.Sunday(0) Is Nothing Then
                Else
                    If OnOffFlag(trans.Sunday(0)) = True Then
                        KTDsendOrReceive(trans, 3, "00", False)
                    End If
                End If
                If trans.Sunday(1) Is Nothing Then
                Else
                    If OnOffFlag(trans.Sunday(1)) = True Then
                        KTDsendOrReceive(trans, 4, "00", False)
                    End If
                End If
        End Select
    End Sub
    Public Sub KTDsendControlCmd(ByVal trans As TransmitKTD)
        Dim QueryString As String
        Dim ds As DataSet
        Dim i As Integer
        Dim ResNum As Integer
        Dim controlType As Integer
        Dim id As Int64
        Dim cmd As String
        QueryString = "select * from controlCmd where response=0 and hostAffirm=0 and equNum=" & Trim(trans.TransmitID)
        If search.con.State = ConnectionState.Open Then
            search.con.Close()
        End If
        ds = search.query(QueryString)
        If ds.Tables(0).Rows.Count > 0 Then
            ResNum = ds.Tables(0).Rows.Count - 1
            For i = 0 To ResNum
                controlType = ds.Tables(0).Rows(i).Item("cmdType")
                cmd = ds.Tables(0).Rows(i).Item("cmd")
                id = ds.Tables(0).Rows(i).Item("id")
                trans.Id = id
                KTDsendOrReceive(trans, controlType, cmd, True)
            Next
        End If
        ds = Nothing
    End Sub
    Private Function Client_Connect(ByVal RemoteIP As String, ByVal RemotePort As Integer) As Boolean
        Dim ip As String = RemoteIP
        Dim port As Integer = RemotePort
        Dim host_address1 As IPAddress = IPAddress.Parse(ip)  'Dns.Resolve(ip).AddressList(0)
        Dim host1 As New IPEndPoint(host_address1, port)
        '''创建Client端Socket对象
        '''通讯协议家族为IPv4,socket类型为字符串,连接端类型为Tcp
        'Dim i As Integer
        'iLastTime = Environment.TickCount
        'Do
        'If TransKTD Is Nothing Then
        'Else
        '    For i = 0 To TransKTD.Length - 1
        '        If TransKTD(i).TransmitAddr = RemoteIP Then
        '            TransKTD(i).bOpenClose = False
        '            Exit For
        '        End If
        '    Next
        'End If
        If isFirst = False Then
            If c_socket.Connected = True Then
                c_socket.Close()
            End If
        End If
        c_socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        Try
            c_socket.Connect(host1)
            Client_Connect = True
        Catch ex As Exception
            Client_Connect = False
        End Try
        ' If Environment.TickCount - iLastTime > 2 * 1000 Then Exit Do
        ' Loop Until Client_Connect = True
    End Function

    '************************************************************************吉兆发射机

    Public Sub GMEsendRs232Data(ByVal DataBuf() As Byte, ByVal trans As TransmitGME, ByVal CmdType As Integer)  ''''' 按RS232串口发送数据
        Dim i As Integer
        trans.State = 1
        trans.CommStatus = 2
        If DataBuf Is Nothing Then Exit Sub
        MSComm1.Output = DataBuf
        Sleep(10)
        MSComm1.Settings = "19200,n,8,1"
        Select Case CmdType
            Case 6
                Sleep(2000)
            Case 3, 4
                Sleep(2000)
        End Select
        Dim aBytes As Byte() = MSComm1.Input
        Dim iPnt As Int32
        iPnt = aBytes.Length
        If iPnt <= 0 Then
            trans.bOpenClose = False
            Exit Sub
        Else
            trans.State = 0
        End If
        isSendOk = True
        'ReceiveData(aBytes, iPnt)
        'ReceiveData(DataBuf, trans, CmdType)
        SelectView(2, aBytes, trans, CmdType)
        If CmdType = 6 And trans.TransmitType = 1 And iPnt <> 514 Then Exit Sub
        If CmdType = 6 And trans.TransmitType = 2 And iPnt <> 1026 Then Exit Sub
        trans.parse(aBytes, iPnt, CmdType)
        If trans.CommStatus = 1 Then
            trans.State = 0  '''通讯正常
        ElseIf trans.CommStatus = 2 Then
            trans.State = 1 '''通讯异常
        ElseIf trans.CommStatus = 0 Then
            trans.State = 3 '''正常
        ElseIf trans.CommStatus = 3 Then
            trans.State = 4 '''报警
        End If
        ''*******************************报警数据记录
        If CmdType = 6 And trans.State = 3 Then
            SysAlarm(trans)
            For i = 0 To trans.AmpCount - 1
                AmpAlarm(i, trans)
            Next
            If trans.Master.bBackupState = False Then
                RefAlarm(0, trans)
            Else
                RefAlarm(1, trans)
            End If
            SMSalarm(trans.CommStatus, trans)
        End If
        ''*******************************
    End Sub
    Private Sub GMEsendOrReceive(ByVal trans As TransmitGME, ByVal CmdType As Integer, ByVal saveFlag As Boolean)
        Dim databuf(1024) As Byte
        Dim x As Integer
        SendDataBuf = SendData(CmdType, trans.TraType, trans.strTransmitAddr, trans.Port, trans.PortPara, "00", "00", trans.TransmitType)
        '''显示请求数据
        'DataView(lsvmsg, "请求数据:" + strSendData)
        'SendDataLog(SendDataBuf, trans, CmdType)
        SelectView(1, SendDataBuf, trans, CmdType)
        '''发送数据
        Select Case CmdType
            Case 6
                GMEsendRs232Data(SendDataBuf, trans, CmdType)
            Case Else
                isSendOk = False
                Dim iCount As Integer
                iCount = 0
                Do
                    iCount += 1
                    GMEsendRs232Data(SendDataBuf, trans, CmdType)
                    If isSendOk = True Then
                        Exit Do
                    End If
                Loop Until iCount = 3
        End Select
        '''保存修改记录
        TramDatabase(trans.TransmitID, trans.TransmitName, CmdType, trans.State, saveFlag, trans.Id)
    End Sub
    Public Sub GMEsendOpenClose(ByVal trans As TransmitGME)
        Select Case Today.DayOfWeek
            Case DayOfWeek.Monday
                If trans.Monday(0) Is Nothing Then
                Else
                    If OnOffFlag(trans.Monday(0)) = True Then
                        GMEsendOrReceive(trans, 3, False)
                    End If
                End If
                If trans.Monday(1) Is Nothing Then
                Else
                    If OnOffFlag(trans.Monday(1)) = True Then
                        GMEsendOrReceive(trans, 4, False)
                    End If
                End If
            Case DayOfWeek.Tuesday
                If trans.Tuesday(0) Is Nothing Then
                Else
                    If OnOffFlag(trans.Tuesday(0)) = True Then
                        GMEsendOrReceive(trans, 3, False)
                    End If
                End If
                If trans.Tuesday(1) Is Nothing Then
                Else
                    If OnOffFlag(trans.Tuesday(1)) = True Then
                        GMEsendOrReceive(trans, 4, False)
                    End If
                End If
                If trans.Tuesday(2) Is Nothing Then
                Else
                    If OnOffFlag(trans.Tuesday(2)) = True Then
                        GMEsendOrReceive(trans, 3, False)
                    End If
                End If
                If trans.Tuesday(3) Is Nothing Then
                Else
                    If OnOffFlag(trans.Tuesday(3)) = True Then
                        GMEsendOrReceive(trans, 4, False)
                    End If
                End If
            Case DayOfWeek.Wednesday
                If trans.Wednesday(0) Is Nothing Then
                Else
                    If OnOffFlag(trans.Wednesday(0)) = True Then
                        GMEsendOrReceive(trans, 3, False)
                    End If
                End If
                If trans.Wednesday(1) Is Nothing Then
                Else
                    If OnOffFlag(trans.Wednesday(1)) = True Then
                        GMEsendOrReceive(trans, 4, False)
                    End If
                End If
            Case DayOfWeek.Thursday
                If trans.Thursday(0) Is Nothing Then
                Else
                    If OnOffFlag(trans.Thursday(0)) = True Then
                        GMEsendOrReceive(trans, 3, False)
                    End If
                End If
                If trans.Thursday(1) Is Nothing Then
                Else
                    If OnOffFlag(trans.Thursday(1)) = True Then
                        GMEsendOrReceive(trans, 4, False)
                    End If
                End If
            Case DayOfWeek.Friday
                If trans.Friday(0) Is Nothing Then
                Else
                    If OnOffFlag(trans.Friday(0)) = True Then
                        GMEsendOrReceive(trans, 3, False)
                    End If
                End If
                If trans.Friday(1) Is Nothing Then
                Else
                    If OnOffFlag(trans.Friday(1)) = True Then
                        GMEsendOrReceive(trans, 4, False)
                    End If
                End If
            Case DayOfWeek.Saturday
                If trans.Saturday(0) Is Nothing Then
                Else
                    If OnOffFlag(trans.Saturday(0)) = True Then
                        GMEsendOrReceive(trans, 3, False)
                    End If
                End If
                If trans.Saturday(1) Is Nothing Then
                Else
                    If OnOffFlag(trans.Saturday(1)) = True Then
                        GMEsendOrReceive(trans, 4, False)
                    End If
                End If
            Case DayOfWeek.Sunday
                If trans.Sunday(0) Is Nothing Then
                Else
                    If OnOffFlag(trans.Sunday(0)) = True Then
                        GMEsendOrReceive(trans, 3, False)
                    End If
                End If
                If trans.Sunday(1) Is Nothing Then
                Else
                    If OnOffFlag(trans.Sunday(1)) = True Then
                        GMEsendOrReceive(trans, 4, False)
                    End If
                End If
        End Select
    End Sub
    Public Sub GMEsendControlCmd(ByVal trans As TransmitGME)
        Dim QueryString As String
        Dim ds As DataSet
        Dim i As Integer
        Dim ResNum As Integer
        Dim controlType As Integer
        'Try
        QueryString = "select * from controlCmd where response=0 and hostAffirm=0 and equNum=" & Trim(trans.TransmitID)
        If search.con.State = ConnectionState.Open Then
            search.con.Close()
        End If
        ds = search.query(QueryString)
        If ds.Tables(0).Rows.Count > 0 Then
            ResNum = ds.Tables(0).Rows.Count - 1
            For i = 0 To ResNum
                controlType = ds.Tables(0).Rows(i).Item("cmdType")
                trans.Id = ds.Tables(0).Rows(i).Item("id")
                GMEsendOrReceive(trans, controlType, True)
            Next
        End If
        ds = Nothing
    End Sub

    '************************************************************************凯腾发射机
    Public Sub KTsendRs232Data(ByVal DataBuf() As Byte, ByVal trans As TransmitKT, ByVal CmdType As Integer)  ''''' 按RS232串口发送数据

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -