办公室的另一个交通信号灯

您好,我叫Maxim,是一家贸易公司IT部门的一名员工。有一次,我和我的同事们决定我们错过了交通信号灯部门。我们还不明白为什么需要它,但是不可抗拒的“欲望”盛行于我们……


图片


现在,几分钟后,我们已经在互联网上寻找他。要求是:真实,便宜,可以使用的暖灯。很快找到,下令,付款,等待。接收,拆包,拆卸,清洗。放灯泡。一次打开所有。办公室变暖了。


我们想知道在哪里进行调整以及如何进行管理。


在表的表格中找到Ke-USB24R-本质上是一个USB模块,带有四个继电器,可以通过将数据写入虚拟COM端口从计算机进行控制,外加18个IO线和四个10位ADC。厂商网站上的详细信息和说明http://www.kernelchip.ru/Ke-USB24R.php


我通过它连接了一个交通信号灯。事实证明,使用制造商网站上的软件可以分别闪烁灯。


, zabbix, . :


  • — ,
  • — ,
  • — .

PowerShell. :



    • (0 — , 1 — Problem)
  1. — , —
  2. .

xml .


. , . .


traffic_lights.ps1
# 
$trigger_id = $args[0] 
#0 - , 1 - Problem
$trigger_status = $args[1] 
#   . 0 -  , 1 - , 2 - , 3 - , 4 - , 5 - .
$trigger_nsev = $args[2] 

#     
$red = 1
$yellow = 2
$green = 3

#    Key - ID , Value -   
$triggers=@{}

#     
$triggers = Import-Clixml -Path C:\Users\User\Desktop\DB_traffic_lights.xml

#    
if ($trigger_status -eq 1)
    {
        #       
        if (!$triggers.ContainsKey($trigger_id))
            {
                #   
                $triggers.Add($trigger_id,$trigger_nsev)
            }
    }
    #     
    else
    {
        #        
        if ($triggers.ContainsKey($trigger_id))
            {
                #    
                $triggers.Remove($trigger_id)
            }
    }

#     
$triggers | Export-Clixml -Path C:\Users\User\Desktop\DB_traffic_lights.xml

#-   
$red_turn_on = $false
$yellow_turn_on = $false

#  
foreach ($trigger in $triggers)
{
        switch ($trigger.Values)
        {
            #0 -  
            0 {  }

            #1 - 
            1 {  }

            #2 - 
            2 { $yellow_turn_on = $true }

            #3 - 
            3 { $yellow_turn_on = $true }

            #4 - 
            4 { $red_turn_on = $true }

            #5 - 
            5 { $red_turn_on = $true }
        }
}

#[System.IO.Ports.SerialPort]::getportnames()
$port = New-Object System.IO.Ports.SerialPort
$port.PortName = 'COM4'
$port.BaudRate = '9600'
$port.Parity = "None"
$port.Handshake = "None"
$port.DataBits = 8
$port.StopBits = 1
$port.ReadTimeout = 500
$port.WriteTimeout = 500
$port.DtrEnable = $true
$port.RtsEnable = $true

$port.Open()

if ($port.IsOpen -eq $true)
    {
        #     
        if($trigger_status -eq "0")
        {
                #   
                $command = '$KE,REL,' + $red + ',0'+"`r"
                $port.WriteLine($command)
                $command = '$KE,REL,' + $yellow + ',0'+"`r"
                $port.WriteLine($command)         

                #  
                $command = '$KE,REL,' + $green + ',1'+"`r"
                $port.WriteLine($command)
                Start-Sleep -Milliseconds 300

                $command = '$KE,REL,' + $green + ',0'+"`r"
                $port.WriteLine($command)
                Start-Sleep -Milliseconds 300

                $command = '$KE,REL,' + $green + ',1'+"`r"
                $port.WriteLine($command)
                Start-Sleep -Milliseconds 300

                $command = '$KE,REL,' + $green + ',0'+"`r"
                $port.WriteLine($command)
                Start-Sleep -Milliseconds 300
        }

        #   
        if ($red_turn_on)
            {
                $command = '$KE,REL,' + $red + ',1'+"`r"
                $port.WriteLine($command)
            }

        #   
        if ($yellow_turn_on)
            {
                $command = '$KE,REL,' + $yellow + ',1'+"`r"
                $port.WriteLine($command)
            }
    }   

$port.Close()

zabbix- ( -> ), : = , = OK.


image


" ". — zabbix-:


powershell.exe -File C:\Users\User\Desktop\traffic_lights.ps1 {TRIGGER.ID} {TRIGGER.VALUE} {TRIGGER.NSEVERITY}

image


- , , . .



结果是一个有趣且实用的内部元素,引起了人们的极大关注。我们必须回答很多问题,例如我们从哪里获得它,为什么需要它,花费多少等等。将来,我计划使设备成为自主设备,以摆脱使用计算机和USB控制器的麻烦。将其替换为某些以太网中继模块,然后将逻辑转移到zabbix服务器。修改显示器并将其垂直悬挂。


感谢您的关注!

Source: https://habr.com/ru/post/zh-CN399371/


All Articles