Ejemplo n.º 1
0
ftdiChip::ftdiChip(QObject *parent) :
  QObject(parent),stat(stOpen),timerRead(new QTimer(parent))
{
BufPtrs[0] = Buffer1;
BufPtrs[1] = Buffer2;
BufPtrs[2] = Buffer3;
BufPtrs[3] = Buffer4;
BufPtrs[4] = NULL;
connect(this,SIGNAL(signalStart()),this,SIGNAL(signalStep()),Qt::DirectConnection);
connect(this,SIGNAL(signalStep()),this,SLOT(on_Machine()),Qt::DirectConnection);
connect(timerRead,SIGNAL(timeout()),this,SLOT(on_Machine()),Qt::DirectConnection);
}
Ejemplo n.º 2
0
ControlWidget::ControlWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ControlWidget)
{
    ui->setupUi(this);
    connect(ui->pushButton_add, SIGNAL(clicked()), this, SLOT(addSineWave()));
    connect(ui->pushButton_clear, SIGNAL(clicked()), this, SIGNAL(signalClear()));
    connect(ui->pushButton_step, SIGNAL(clicked()), this, SIGNAL(signalStep()));
    connect(ui->pushButton_control, SIGNAL(clicked()), this, SLOT(pauseResume()));
    connect(ui->pushButton_squareWave, SIGNAL(clicked()), this, SLOT(square()));
    connect(ui->pushButton_sawtooth, SIGNAL(clicked()), this, SLOT(sawtooth()));
}
Ejemplo n.º 3
0
/*Write paskage to TOO*/
void ftdiChip::on_Machine()
{
static QQueue<QByteArray> templistCMD;
static quint16 retAnswer;
static int CurrentValue,ValueMax;
switch(stat)
    {
    case stOpen:
        if(!listCMD.isEmpty()){
            if(Open()==retOk){
                stat=stCounter;
                disconnect(this,SIGNAL(signalStart()),this,SIGNAL(signalStep()));
                setParametersUSB(parameter.retSpeed(),parameter.retDataBit(),parameter.retStopBit(),parameter.retParity());
                timerRead->setInterval(parameter.retTimeDelay());
                templistCMD = listCMD;
                CurrentValue = 0;
                ValueMax = 3*templistCMD.count();
                emit signalProgressRange(0,ValueMax);
                emit signalStep();
                }else {
                emit signalMessageError(tr("<CENTER><b>Not found KIT USN_RS485!</CENTER></b>"));
                emit signalStop();
                }
            }
        listCMD.clear();
        return;
    case stCounter:
        if(!templistCMD.isEmpty()){
            emit signalProgressValue(++CurrentValue,true);
            stat=stWrite;
            }else{
            stat=stClose;
            }
        emit signalStep();
        return;
    case stWrite:
        {
        QByteArray cmd(templistCMD.dequeue());//long Time;
        quint16 result = Bit8Write(cmd,1);
        emit signalSendMessage(false,cmd,Qt::green);
        if(result!=retOk){
            templistCMD.clear();stat=stCounter;emit signalStep();}
        stat=stRead;
        timerRead->start();
        emit signalProgressValue(++CurrentValue,true);
        }
        return;
    case stRead:
        {
        QByteArray resBuff;
        quint16 retRead =Read(resBuff);
        emit signalSendMessage(true,resBuff,Qt::darkBlue);
        retAnswer = CheckingReceivedPacket(resBuff);
        if(retAnswer&ANWR_PROTOCOL::retGet){
          return; // next package
          }
        if((retAnswer&(~(ANWR_PROTOCOL::retOK)))
             &&
           (retRead&(ftdiChip::retErr|ftdiChip::retBusyDevice))){// stop sending
          templistCMD.clear();
          }
        stat=stCounter;
        timerRead->stop();
        emit signalProgressValue(++CurrentValue,true);
        emit signalStep();
        }
        return;
    case stClose:
        Close();
        connect(this,SIGNAL(signalStart()),this,SIGNAL(signalStep()),Qt::DirectConnection);
    default:
        emit signalEnd(true);
        stat = stOpen;
        timerRead->stop();
        emit signalProgressValue(0,false);
        if(retAnswer&(ANWR_PROTOCOL::retOK)) // it is not error
          emit signalStatusOk(tr("Data is written successfully!"));
        if(retAnswer&ANWR_PROTOCOL::retError) // it is error
          emit signalStatusError(tr("Error response!"),false);
        if(retAnswer&ANWR_PROTOCOL::retNoAnsError) // it is error
          emit signalStatusError(tr("Device does not answer!"),false);
        if(retAnswer&ANWR_PROTOCOL::retIncorData)
          emit signalStatusError(tr("Data is incorrect!"),false);
        emit signalStep();
        return;        
  }
}
Ejemplo n.º 4
0
/*Stop send message*/
void ftdiChip::stopMessage()
{
listCMD.clear();
connect(this,SIGNAL(signalStart()),this,SIGNAL(signalStep()),Qt::DirectConnection);
}