나는 relaisboard를 Python 바인딩을 사용하는 firmata 프로토콜을 통해 arduino에 연결했습니다. 의사 소통은 문제없이 pyfirmata (https://github.com/tino/pyFirmata)를 사용합니다.Python의 클래스 계층
relaisboard에는 16 개의 릴레이가 있습니다. 3 relais의 모든 그룹은 채널입니다. 모든 채널은 테스트중인 장치 입력 또는 출력에 연결됩니다. 이것은 단지 releboard의 목적에 대한 대략적인 설명을 가지고 있습니다.
아래에서 코드의 골격을 찾을 수 있습니다.
FaultInsertionBoard
가Firmata
에서Arduino
클래스의 래퍼입니다 :#!/usr/bin/env python __version__ = '0.1' # Fault Injection Unit # Power is connected to Fault Bus 1 # Ground is connected to Fault Bus 2 from pyfirmata import Arduino class FaultInsertionBoard(object): def __init__ (self, comPort = 'COM3'): """Initalize the Fault insertion Board Open communication with host via serial port Arguments: comPort -- The serial port used to connect the board to the host. """ self.board = Arduino(comPort) class Channel(object): def __init__ (self, aChannel): """ Create a Channel""" pass def NoFault(): """ Set the channel to the "No fault" condition No Fault condition is: -- DUT channel connected to the testing sistem -- DUT channel disconnected from the Fault bus 1 -- DUT channel disconnected from the Fault bus 2 """ pass def OpenCircuit(): """ Set the channel to the "Open Circuit fault" condition Open Circuit fault condition is: -- DUT channel disconnected from the testing sistem -- DUT channel disconnected from the Fault bus 1 -- DUT channel disconnected from the Fault bus 2 """ pass def ShortToGround(): """ Set the channel to the "Short to Ground fault" condition Open Circuit fault condition is: -- DUT channel disconnected from the testing sistem -- DUT channel disconnected from the Fault bus 1 -- DUT channel connected to the Fault bus 2 """ pass def ShortToPower(): """ Set the channel to the "Short to Ground fault" condition Open Circuit fault condition is: -- DUT channel disconnected from the testing sistem: channel relay is open -- DUT channel connected to the Fault bus 1: Fault Bus 1 relay is closed -- DUT channel disconnected from the Fault bus 2: Fault Bus 1 relay is open """ pass def main(): FaultBoard = FaultInsertionBoard('COM3') VoutSensor = FaultBoard.Channel(0) IOutSensor = FaultBoard.Channel(1) VoutSensor.NoFault() IOutSensor.NoFault() VoutSensor.ShortToGround() IOutSensor.ShortToPower() if __name__ == "__main__": main()
.
Channel(n)
세 릴레NoFault
,
ShortToPower
,
ShortToGround
각 채널의 세 릴레 (이것은 실제 구성을 중요하지 않다)의 다양한 구성이다의
n
번째 그룹을 식별한다.
이제 질문 : 나는 C로 작성된 내장 된 펌웨어에 대해 아주 좋은 경험이 있으며, 파이썬에서는 훨씬 적다. 분명히 위의 코드는 올바르지 않습니다.
누가 위의 기능을 사용하기 위해 클래스 프레임 워크를 제안 할 수 있습니까? 다시 말해, 위에 설명 된대로 relais를 구동하기 위해 Python 코드를 작성하려면 어떻게해야합니까?
PS : 또는 나는 이런 식으로 뭔가 작성할 수
FaultBoard = FaultInsertionBoard('COM3')
FaultBoard.Channel(0).NoFault()
을하지만 덜 우아하고 분명하다 생각합니다.
; 어떻게 도움을 얻을 것으로 기대합니까? –
게시 한 코드가 작동하지 않습니까? –
죄송합니다. 내 잘못입니다. 코드를 넣은 것 같습니다. 위의 편집 된 질문을 참조하십시오. –