def __init__(self, port='COM1'):
     "constructeur de la classe, initialise les champs"
     MySerial.__init__(self, port)
     self.serialPort.baudrate = 57600
     self.serialPort.timeout = 2
     self.dataCount = 0
     self.stateDef = {0:"idle", 1:"connected", 2:"discharging", 3:"discharged"}
 def __init__(self, port='COM1'):
     "constructeur de la classe, initialise les champs"
     MySerial.__init__(self, port)
     self.serialPort.baudrate = 57600
     self.serialPort.timeout = 2
     self.dataCount = 0
     self.stateDef = {
         0: "idle",
         1: "connected",
         2: "discharging",
         3: "discharged"
     }
Exemple #3
0
    def __init__(self, interface="0", port="/dev/ttyACM", baud='115200'):

        # Serial
        # por = "/dev/ttyACM"
        # por = "/dev/ttyUSB"
        por = port
        cha = interface
        # port, baudrate, bytesize, parity, stopbits, timeout, xonxoff, rtscts, dsrdtr
        cfg = [cha, baud, '8', 'N', '1', None, False, False, False]
        # fil="init.pkl", par=None, ope=True, deb=False
        obj = MySerial(por=por, par=cfg, deb=0)
        self.mySer = obj  # => self.prot.ser
        if self.mySer.ser:
            print "device present!"
            # Protocol
            # ser=None, sta='', sto=['\r','\n'],hex=False, buf=None, wri=None, cal=None
            prot = MyProtocol(ser=obj, sta='', sto=[
                '',
            ])
            self.prot = prot
            #Parsing
            # myPars = myParser(self.prot)
            # self.prot.calBk1 = myPars
            # cambio la lista di loopback del device
            self.myPars = MyParser()
            self.prot.calBk1 = self.myPars.parser
            # attivo protocollo sul loop principale
            # self.prot.insLoop()

            # check Open
            if self.mySer.ope:
                print "device Ok"
            else:
                print "device not open!"
Exemple #4
0
def myTry01(deb=1):

    # inizializzazione in base al S.O.
    if sys.platform == 'win32':
        # Windows (numerazione parte da 1)
        por = "COM"
        par = ['1', '115200', '8', 'N', '1']
    else:
        # Unix  (numerazione parte da 0)
        #por = "/dev/ttyS"
        #por = "/dev/ttymxc"
        por = "/dev/ttyUSB"
        par = ['0', '115200', '8', 'N', '1']

    # definisco il parser
    def myParser(*args):
        print 'parser:', args
        # mantiene il loop attivo (esce solo per timeOut!)
        return True

    #  istanza di un seriale
    dev = MySerial(por=por, par=par, ope=1, deb=deb)
    if dev.ser:
        print "device Ok"
        self = MyProtocol(ser=dev, sta='*', sto=['\r', '\n'], hex=0, cal=None)
        # attivo il parser
        self.cal = myParser
        return self
    else:
        print "device Ko"
        sys.exit()
Exemple #5
0
    def setupUi(self, mainWidgetArm):
        mainWidgetArm.setObjectName("mainWidgetArm")
        mainWidgetArm.resize(985, 324)
        mainWidgetArm.setMinimumSize(QtCore.QSize(0, 0))
        self.gridLayout_2 = QtWidgets.QGridLayout(mainWidgetArm)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.arm = MyArm(mainWidgetArm)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.arm.sizePolicy().hasHeightForWidth())
        self.arm.setSizePolicy(sizePolicy)
        self.arm.setMinimumSize(QtCore.QSize(0, 30))
        self.arm.setMaximumSize(QtCore.QSize(1400, 600))
        self.arm.setObjectName("arm")
        self.gridLayout_2.addWidget(self.arm, 0, 0, 1, 1)
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.serial = MySerial(mainWidgetArm)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.serial.sizePolicy().hasHeightForWidth())
        self.serial.setSizePolicy(sizePolicy)
        self.serial.setMinimumSize(QtCore.QSize(0, 0))
        self.serial.setObjectName("serial")
        self.gridLayout.addWidget(self.serial, 0, 0, 1, 2)
        spacerItem = QtWidgets.QSpacerItem(48, 20,
                                           QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Minimum)
        self.gridLayout.addItem(spacerItem, 1, 0, 1, 1)
        self.saveButton = QtWidgets.QPushButton(mainWidgetArm)
        self.saveButton.setObjectName("saveButton")
        self.gridLayout.addWidget(self.saveButton, 1, 1, 1, 1)
        self.textBrowser = QtWidgets.QTextBrowser(mainWidgetArm)
        self.textBrowser.setObjectName("textBrowser")
        self.gridLayout.addWidget(self.textBrowser, 2, 0, 1, 2)
        self.gridLayout_2.addLayout(self.gridLayout, 0, 1, 1, 1)

        self.retranslateUi(mainWidgetArm)
        self.serial.sigNewLine.connect(self.arm.slotNewDataArrived)
        self.arm.sigSendCommand['QString'].connect(self.serial.slotSendRequest)
        QtCore.QMetaObject.connectSlotsByName(mainWidgetArm)
Exemple #6
0
# -*- coding: ISO-8859-1 -*-
from mySerial import MySerial

for a in range(12, 13):
    port = 'COM%i' % a
    batMon = MySerial(port)
    if (not (batMon.connect())):
        print('%s : Echec de la connexion' % port)
    else:
        print('%s Connected...' % port)
        if batMon.sendString('Who'):
            #print('Starting the handshake')
            s = batMon.getString()
            print(s)
            if s == 'BatMon':
                print('BatMon detected at %s' % port)
            else:
                print('%s : Connecté, mais pas de réponse' % port)
        else:
            print("%s : Connecté, mais impossible d'écrire sur le port" %
                  port)
        batMon.disconnect()

# bizarre : lors de 1er tests, il restait bloqué dans l'envoi du 'Who', pour COM4
# En ajoutant des strings de debug, cela s'est débloqué en ajoutant celle du 'starting the hadshake'
# mais elle n'apparait pas dans le shell, donc le problème est bien dans le sendString()
# en commentant cette string de debug, cela fonctionne tjs
# La veille, cela fonctionnait avec un sendInt()
Exemple #7
0
    def setupUi(self, mainWidget):
        mainWidget.setObjectName("mainWidget")
        mainWidget.resize(985, 418)
        mainWidget.setMinimumSize(QtCore.QSize(0, 0))
        self.gridLayout_2 = QtWidgets.QGridLayout(mainWidget)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        spacerItem = QtWidgets.QSpacerItem(48, 20,
                                           QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Minimum)
        self.gridLayout.addItem(spacerItem, 2, 2, 1, 1)
        self.textBrowser = QtWidgets.QTextBrowser(mainWidget)
        self.textBrowser.setObjectName("textBrowser")
        self.gridLayout.addWidget(self.textBrowser, 3, 2, 1, 2)
        self.sequence = MySequence(mainWidget)
        self.sequence.setMinimumSize(QtCore.QSize(0, 0))
        self.sequence.setObjectName("sequence")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.sequence)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.gridLayout.addWidget(self.sequence, 2, 0, 2, 1)
        self.saveButton = QtWidgets.QPushButton(mainWidget)
        self.saveButton.setObjectName("saveButton")
        self.gridLayout.addWidget(self.saveButton, 2, 3, 1, 1)
        spacerItem1 = QtWidgets.QSpacerItem(20, 38,
                                            QtWidgets.QSizePolicy.Minimum,
                                            QtWidgets.QSizePolicy.Expanding)
        self.gridLayout.addItem(spacerItem1, 1, 0, 1, 1)
        self.serial = MySerial(mainWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.serial.sizePolicy().hasHeightForWidth())
        self.serial.setSizePolicy(sizePolicy)
        self.serial.setMinimumSize(QtCore.QSize(0, 0))
        self.serial.setObjectName("serial")
        self.gridLayout.addWidget(self.serial, 0, 2, 2, 2)
        spacerItem2 = QtWidgets.QSpacerItem(48, 20,
                                            QtWidgets.QSizePolicy.Preferred,
                                            QtWidgets.QSizePolicy.Minimum)
        self.gridLayout.addItem(spacerItem2, 2, 1, 2, 1)
        spacerItem3 = QtWidgets.QSpacerItem(20, 38,
                                            QtWidgets.QSizePolicy.Minimum,
                                            QtWidgets.QSizePolicy.Expanding)
        self.gridLayout.addItem(spacerItem3, 1, 1, 1, 1)
        self.hand = MyHand(mainWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.hand.sizePolicy().hasHeightForWidth())
        self.hand.setSizePolicy(sizePolicy)
        self.hand.setMinimumSize(QtCore.QSize(0, 30))
        self.hand.setMaximumSize(QtCore.QSize(1400, 600))
        self.hand.setObjectName("hand")
        self.gridLayout.addWidget(self.hand, 0, 0, 1, 2)
        self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)

        self.retranslateUi(mainWidget)
        self.hand.sigSendCommand['QString'].connect(
            self.serial.slotSendRequest)
        self.hand.sigAddFrame.connect(self.sequence.slotAddFrame)
        self.sequence.sigSendCommandFromSequence.connect(
            self.serial.slotSendRequestBin)
        self.saveButton.clicked.connect(self.hand.slotSaveConfiguration)
        self.sequence.sigReadyToSave.connect(mainWidget.slotReadyToSave)
        self.hand.sigReadyToSave.connect(self.sequence.slotSaveConfiguration)
        self.serial.sigNewLine.connect(self.hand.slotNewDataArrived)
        self.serial.sigAngleCommandChanged.connect(
            self.hand.slotAngleCommandChanged)
        self.hand.sigSendLeapMotion.connect(self.serial.slotSendRequestBin)
        QtCore.QMetaObject.connectSlotsByName(mainWidget)
Exemple #8
0
import numpy
from matplotlib import pyplot
from mySerial import MySerial

batMon = MySerial('COM12')
if (not(batMon.connect())):
    print('Echec de la connexion')
else:
    sampleNb = 100                  # Nombre d'échantillons
    batMon.sendInt(sampleNb)
    #data = numpy.zeros((sampleNb,1), dtype='int16')
	data = numpy.zeros(sampleNb)
    for a in range(sampleNb):
        data[a] = batMon.getFloat()
    batMon.disconnect()

    endTime = sampleNb*0.1    #Durée de l'acquisition, en s
    time = numpy.linspace(0,endTime,sampleNb)
    pyplot.plot(time, data)
    pyplot.show()
Exemple #9
0
# -*- coding: ISO-8859-1 -*-
from mySerial import MySerial

for a in range(12,13):
    port = 'COM%i' % a
    batMon = MySerial(port)
    if (not(batMon.connect())):
        print('%s : Echec de la connexion' % port)
    else:
        print('%s Connected...' % port)
        if batMon.sendString('Who'):
            #print('Starting the handshake')
            s = batMon.getString()
            print(s)
            if s == 'BatMon':
                print('BatMon detected at %s' % port)
            else:
                print('%s : Connecté, mais pas de réponse' % port)
        else:
            print("%s : Connecté, mais impossible d'écrire sur le port" % port)
        batMon.disconnect()



# bizarre : lors de 1er tests, il restait bloqué dans l'envoi du 'Who', pour COM4
# En ajoutant des strings de debug, cela s'est débloqué en ajoutant celle du 'starting the hadshake'
# mais elle n'apparait pas dans le shell, donc le problème est bien dans le sendString()
# en commentant cette string de debug, cela fonctionne tjs
# La veille, cela fonctionnait avec un sendInt()