Ejemplo n.º 1
0
def counting_pru():
    """
    CountingPRU
    """
    logger.debug('Counting PRU')
    if PRUserial485_address() != 21 and not os.path.isfile(PORT):
        persist_info(Type.COUNTING_PRU, 0, COUNTING_PRU)
Ejemplo n.º 2
0
def agilent4uhv():
    """
    AGILENT 4UHV
    """
    logger.debug("AGILENT 4UHV")
    if (GPIO.input(PIN_FTDI_PRU) == FTDI
            and GPIO.input(PIN_RS232_RS485) == RS485
            and PRUserial485_address() == 21 and os.path.exists(PORT)):
        baud = 38400
        ser = Serial(port=PORT, baudrate=baud, timeout=0.6)
        devices = []
        for addr in range(0, 32):
            ser.reset_input_buffer()
            ser.reset_output_buffer()
            pl = ""
            pl += "\x02"
            pl += chr(addr + 128)
            pl += "\x38"
            pl += "\x31"
            pl += "\x30"
            pl += "\x30"
            pl += "\x03"
            ser.write(Agilent4UHV_CRC(pl).encode("latin-1"))
            res = ser.read(15).decode("latin-1")
            if len(res) != 0:
                devices.append(addr)
        ser.close()
        name = "Agilent 4UHV"
        if len(devices):
            persist_info(Type.AGILENT4UHV, name, baud, AGILENT4UHV,
                         "AGILENT4UHV connected {}".format(devices))
Ejemplo n.º 3
0
def no_tty():
    """
    NO /dev/ttyUSB0
    """
    logger.debug('No /dev/ttyUSB0')
    if not os.path.exists(PORT) and PRUserial485_address() == 21:
        persist_info(Type.UNDEFINED, 115200, NOTTY)
Ejemplo n.º 4
0
def agilent4uhv():
    """
    AGILENT 4UHV
    """
    logger.debug('AGILENT 4UHV')
    if GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input(
            PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21:
        baud = 38400
        ser = Serial(port=PORT, baudrate=baud, timeout=.6)
        devices = []
        for addr in range(0, 32):
            ser.reset_input_buffer()
            ser.reset_output_buffer()
            pl = ""
            pl += "\x02"
            pl += chr(addr + 128)
            pl += "\x38"
            pl += "\x31"
            pl += "\x30"
            pl += "\x30"
            pl += "\x03"
            ser.write(Agilent4UHV_CRC(pl))
            res = ser.read(15)
            if len(res) != 0:
                devices.append(addr)
        ser.close()
        if len(devices):
            persist_info(Type.AGILENT4UHV, baud, AGILENT4UHV,
                         'AGILENT4UHV connected {}'.format(devices))
Ejemplo n.º 5
0
def power_supply_pru():
    """
    PRU Power Supply
    """
    logger.debug("PRU Power Supply")
    ps_model_names = {
        0: "Empty",
        1: "FBP",
        2: "FBP_DCLINK",
        3: "FAC_ACDC",
        4: "FAC_DCDC",
        5: "FAC_2S_ACDC",
        6: "FAC_2S_DCDC",
        7: "FAC_2P4S_ACDC",
        8: "FAC_2P4S_DCDC",
        9: "FAP",
        10: "FAP_4P",
        11: "FAC_DCDC_EMA",
        12: "FAP_2P2S_Master",
        13: "FAP_2P2S_Slave",
        31: "UNDEFINED",
    }
    if GPIO.input(PIN_FTDI_PRU) == PRU and GPIO.input(
            PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21:
        os.system("/root/pru-serial485/src/overlay.sh")
        baud = 6
        PRUserial485_open(baud, b"M")
        devices = []
        ps_model = []
        ps_names = []
        for ps_addr in range(1, 25):
            PRUserial485_write(
                BSMPChecksum(chr(ps_addr) +
                             "\x10\x00\x01\x00").encode("latin-1"), 100)
            res = PRUserial485_read()
            if len(res) == 7 and res[1] == 17:
                devices.append(ps_addr)
                ps_model = ps_model_names[res[5] %
                                          32]  # PS model: res[5] (bits 4..0)
                ps_name = getPSnames(ps_addr).replace(" ", "")
                if not ps_name in ps_names:
                    ps_names.append(ps_name)
                    name = "Power Supply"
            time.sleep(0.1)
        # Save info
        persist_info(
            Type.POWER_SUPPLY,
            name,
            6000000,
            PRU_POWER_SUPPLY,
            "PS model {}. Connected: {}. Names: {}".format(
                ps_model, devices, ps_names),
        )
Ejemplo n.º 6
0
def counting_pru():
    """
    CountingPRU
    """
    logger.debug("Counting PRU")
    if PRUserial485_address() != 21 and not os.path.exists(PORT):
        counters = CountingPRU_addr()
        os.system("/root/counting-pru/src/DTO_CountingPRU.sh")
        name = "Counting PRU"
        persist_info(
            Type.COUNTING_PRU,
            name,
            0,
            COUNTING_PRU,
            "Connected: [{}]. Auto Configuration: {}".format(
                counters.addr(), counters.autoConfig_Available()),
        )
Ejemplo n.º 7
0
def power_supply_pru():
    """
    PRU Power Supply
    """
    logger.debug('PRU Power Supply')
    ps_model_names = {
        0: "Empty",
        1: "FBP",
        2: "FBP_DCLINK",
        3: "FAC_ACDC",
        4: "FAC_DCDC",
        5: "FAC_2S_ACDC",
        6: "FAC_2S_DCDC",
        7: "FAC_2P4S_ACDC",
        8: "FAC_2P4S_DCDC",
        9: "FAP",
        10: "FAP_4P",
        11: "FAC_DCDC_EMA",
        12: "FAP_2P2S_Master",
        13: "FAP_2P2S_Slave",
        31: "UNDEFINED"
    }
    if GPIO.input(PIN_FTDI_PRU) == PRU and GPIO.input(
            PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21:
        os.system("/root/pru-serial485/src/overlay.sh")
        baud = 6
        PRUserial485_open(baud, 'M')
        devices = []
        ps_model = []
        for ps_addr in range(1, 32):
            PRUserial485_write(
                [i for i in BSMPChecksum(chr(ps_addr) + "\x10\x00\x01\x00")],
                100)
            res = PRUserial485_read()
            if len(res) == 7 and res[1] == "\x11":
                devices.append(ps_addr)
                ps_model = ps_model_names[ord(res[5]) %
                                          32]  # PS model: res[5] (bits 4..0)
            time.sleep(0.1)

        PRUserial485_close()
        persist_info(Type.POWER_SUPPLY, 6000000, PRU_POWER_SUPPLY,
                     'PS model {}. Connected: {}'.format(ps_model, devices))
Ejemplo n.º 8
0
def mbtemp():
    """
    MBTemp
    """
    logger.debug('MBTemp')
    if GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input(
            PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21:
        baud = 115200
        ser = Serial(PORT, baud, timeout=TIMEOUT)
        devices = []
        for mbt_addr in range(1, 32):
            ser.write(BSMPChecksum(chr(mbt_addr) + "\x10\x00\x01\x00"))
            res = ser.read(10)
            if len(res) == 7 and res[1] == "\x11":
                devices.append(mbt_addr)
        ser.close()
        if len(devices):
            persist_info(Type.MBTEMP, baud, MBTEMP,
                         'MBTemps connected {}'.format(devices))
Ejemplo n.º 9
0
def mks9376b():
    """
    MKS 937B
    """
    logger.debug('MKS 937B')
    if GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input(
            PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21:
        baud = 115200
        ser = Serial(port=PORT, baudrate=baud, timeout=0.05)
        devices = []
        for mks_addr in range(1, 255):
            msgm = '\@{0:03d}'.format(mks_addr) + "PR1?;FF"
            ser.reset_input_buffer()
            ser.reset_output_buffer()
            ser.write(msgm)
            res = ser.read(20)
            if len(res) != 0:
                devices.append(mks_addr)
        ser.close()
        if len(devices):
            persist_info(Type.MKS937B, baud, MKS937B,
                         'MKS937Bs connected {}'.format(devices))
Ejemplo n.º 10
0
def thermo_probe():
    """
    Thermo probes
    """
    logger.debug('Thermo probes')
    if GPIO.input(PIN_FTDI_PRU) == FTDI and GPIO.input(
            PIN_RS232_RS485) == RS485 and PRUserial485_address() == 21:
        baud = 19200
        ser = Serial(port=PORT,
                     baudrate=baud,
                     bytesize=SEVENBITS,
                     parity=PARITY_EVEN,
                     stopbits=STOPBITS_TWO,
                     timeout=TIMEOUT)
        msg = thermoIncluirChecksum("\x07" + "01RM1")
        ser.reset_input_buffer()
        ser.reset_output_buffer()
        ser.write(msg.encode('utf-8'))
        res = ser.read(50)

        if len(res) != 0:
            persist_info(Type.SERIAL_THERMO, baud, SERIAL_THERMO)
Ejemplo n.º 11
0
def mbtemp():
    """
    MBTemp
    """
    logger.info("MBTemp")
    if (GPIO.input(PIN_FTDI_PRU) == FTDI
            and GPIO.input(PIN_RS232_RS485) == RS485
            and PRUserial485_address() == 21 and os.path.exists(PORT)):
        baud = 115200
        ser = Serial(PORT, baud, timeout=TIMEOUT)
        devices = []
        for mbt_addr in range(1, 32):
            ser.write(
                BSMPChecksum(chr(mbt_addr) +
                             "\x10\x00\x01\x00").encode("latin-1"))
            res = ser.read(10).decode("latin-1")
            if len(res) == 7 and res[1] == "\x11":
                devices.append(mbt_addr)
        ser.close()
        name = "MBTemp"
        if len(devices):
            persist_info(Type.MBTEMP, name, baud, MBTEMP,
                         "MBTemps connected {}".format(devices))
Ejemplo n.º 12
0
def mks9376b():
    """
    MKS 937B
    """
    logger.debug("MKS 937B")
    if (GPIO.input(PIN_FTDI_PRU) == FTDI
            and GPIO.input(PIN_RS232_RS485) == RS485
            and PRUserial485_address() == 21 and os.path.exists(PORT)):
        baud = 115200
        ser = Serial(port=PORT, baudrate=baud, timeout=0.05)
        devices = []
        for mks_addr in range(1, 255):
            msgm = "\@{0:03d}".format(mks_addr) + "PR1?;FF"
            ser.reset_input_buffer()
            ser.reset_output_buffer()
            ser.write(msgm.encode("latin-1"))
            res = ser.read(20).decode("latin-1")
            if len(res) != 0:
                devices.append(mks_addr)
        ser.close()
        name = "MKS"
        if len(devices):
            persist_info(Type.MKS937B, name, baud, MKS937B,
                         "MKS937Bs connected {}".format(devices))
Ejemplo n.º 13
0
 def __init__(self):
     self.boardID = PRUserial485_address()
     self.status = False
     self.check()
Ejemplo n.º 14
0
#!/usr/bin/python-sirius
# -*- coding: utf-8 -*-

from PRUserial485 import PRUserial485_address
import Adafruit_BBIO.GPIO as GPIO

import sys
import time

# ----- CONSTANTS
PRIMARY = 1
SECONDARY = 2
SERIALXXCON_ID = 21

#Just for SerialxxCON
if PRUserial485_address() != SERIALXXCON_ID:
    exit(PRIMARY)

# ----- GPIO PINS
inputPin = "P9_12"
outputPin = "P9_14"
GPIO.setup(inputPin, GPIO.IN)
GPIO.setup(outputPin, GPIO.OUT)

if "clean" in sys.argv:
    GPIO.output(outputPin, GPIO.LOW)
    exit(0)

elif "force-primary" in sys.argv:
    GPIO.output(outputPin, GPIO.HIGH)
    exit(0)
Ejemplo n.º 15
0
    logger.info("Ethernet service {}".format(service))
    system("connmanctl config {} --ipv4 dhcp".format(service))


def led():  #Shows the user that the IP has been configured
    for i in range(20):
        GPIO.output("P8_28", GPIO.HIGH)
        sleep(0.05)
        GPIO.output("P8_28", GPIO.LOW)
        sleep(0.05)


if __name__ == '__main__':
    logger.info("Verificando condicao DHCP em Hardware")

    device_addr = PRUserial485_address()

    GPIO.setup("P8_28", GPIO.OUT)  #Led configuration
    GPIO.output("P8_28", GPIO.LOW)

    if device_addr == 0:
        logger.info("Contadora detectada")

        for en_FF in ["P8_43", "P8_44", "P8_45", "P8_46", "P9_29",
                      "P9_31"]:  #Enable Flip-Flops
            sleep(0.05)
            GPIO.setup(en_FF, GPIO.OUT)
            sleep(0.05)
            GPIO.output(en_FF, GPIO.HIGH)

        sleep(
Ejemplo n.º 16
0
    logger.info("Setting IP address to {}".format(new_ip))
    system("connmanctl config {} --ipv4 manual {} 255.255.255.0 {} \
    --nameservers 10.0.0.71 10.0.0.72 ".format(service, new_ip, gateway))


def led(num):
    for i in range(num):
        GPIO.output("P8_28", GPIO.HIGH)
        sleep(1)
        GPIO.output("P8_28", GPIO.LOW)
        sleep(1)


if __name__ == '__main__':

    if PRUserial485_address() != 0:
        sys.exit()

    logger.info("Checking IP Availability for the Counter")

    GPIO.setup("P8_28", GPIO.OUT)  #Led configuration
    GPIO.output("P8_28", GPIO.LOW)

    my_ip = get_ip_address().split('.')

    if not (my_ip[-1] in counters_ip):
        a = ping_ips(my_ip[:-1])
        if len(a) == 1:
            set_ip('.'.join(i for i in my_ip[:-1]) + '.' + a[0],
                   '.'.join(i for i in my_ip[:-1]) + '.1')
            led(int(a[0]) - 150)
Ejemplo n.º 17
0
    # ----------------------------------
    # Led configuration
    # ----------------------------------
    GPIO.setup(LED_PIN, GPIO.OUT)
    GPIO.output(LED_PIN, GPIO.LOW)

    # ----------------------------------
    # AutoConfig Status
    # ----------------------------------
    AUTOCONFIG = AutoConfig().status
    logger.info(AUTOCONFIG)
    # ----------------------------------
    # Apply DHCP config if needed
    # ----------------------------------
    # COUNTINGPRU, SIMAR
    if PRUserial485_address() == COUNTINGPRU_SIMAR_ADDRESS:
        simar = Simar_addr()

        if simar.identified:
            #for pin in ["P9_25", "P9_26"]:
            #    GPIO.setup(pin, GPIO.IN)
            if (GPIO.input("P9_25") == 1 and GPIO.input("P9_26") == 0):
                logger.info(
                    "SIMAR red switches on DHCP position. Configuring DHCP.")
                dhcp()

        if AUTOCONFIG:
            logger.info("AUTOCONFIG enabled. Configuring DHCP.")
            dhcp()
            led()