StReader::StReader(QObject *parent) : AaeReader(), aaeCommand(new AaeCommand(this)), debugSequenceCounter(0) { setBaudrate(115200); }
void MainWindow::serialconnect() { //Hust to be safe - wipe all the user commands emit flushInjectionBuffer(); if(!opened) { //Find the portinfo we need foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { if(info.portName() == ui->serialBox->currentText()) { printerinfo = info; break; } } //Emit signals needed emit setBaudrate(ui->baudbox->currentText().toInt()); emit openPort(printerinfo); //Set the flag right opened=true; //Update UI ui->connectBtn->setText("Disconnect"); ui->sendBtn->setDisabled(false); ui->progressBar->setValue(0); ui->controlBox->setDisabled(false); ui->consoleGroup->setDisabled(false); ui->statusGroup->setDisabled(false); ui->actionPrint_from_SD->setEnabled(true); ui->actionSet_SD_printing_mode->setEnabled(true); if(firmware == Repetier) ui->actionEEPROM_editor->setDisabled(false); }
BootLoader::BootLoader(QObject *parent) : AaeReader(parent) { setBaudrate(BAUD115200); dataReceivedQueue.clear(); blReceiveState = BL_RCV_UNDEF; }
bool Bluetooth::setBaud(uint32_t baud) { // Standardbefehl char command[] = "AT+BAUD4"; char p = '4'; // Gibt die höchste Stelligkeit der Baudrate an. uint32_t h = 1000; // Wähle entsprechende Nummer laut Datenblatt switch (baud) { case 1200: p = '1'; h = 1000; break; case 2400: p = '2'; h = 1000; break; case 4800: p = '3'; h = 1000; break; case 9600: p = '4'; h = 1000; break; case 19200: p = '5'; h = 10000; break; case 38400: p = '6'; h = 10000; break; case 57600: p = '7'; h = 10000; break; case 115200: p = '8'; h = 100000; break; case 230400: p = '9'; h = 100000; break; case 460800: p = 'A'; h = 100000; break; case 921600: p = 'B'; h = 100000; break; case 1382400: p = 'C'; h = 1000000; break; default: return false; } command[7] = p; write(command); /* Überprüfe Rückgabewert, OK<r>, wobei <r> gleich die Baudrate * in Dezimalform sein muss */ if (receiveChar() != 'O') { return false; } if (receiveChar() != 'K') { return false; } while (h > 0) { /* Hole zunächst die erste Ziffer der Baudrate, * dann die jeweils nächste. */ char expected = baud / h; // Überprüfe, ob die Ziffer auch zurück gegeben wurde. if (receiveChar() != expected) { return false; } // Lösche die höchste Ziffer baud -= expected * h; // Gehe eine Dezimalstelle tiefer h /= 10; } // Setze jetzt auch die Baudrate vom USART neu setBaudrate(baud); //USART_setBaudrate(baud); return true; }
//--------------------------------------------------------------------------- // default constructor Serial::Parameters::Parameters() : InOutObject(), parameters_( *::Laser360::Parameters::instance() ) { setBaudrate( parameters_.baudrate ); //baudRate_ = Baud57600; port_ = Com1; characterSize_ = Cs8; parity_ = No; stopBits_ = One; receiveTimeout_ = 50; // 50 ms }
/* * Initialize Uart HAL Peripheral * * Enables clocks, the UART peripheral (but neither TX nor RX) * Sets baudrate and parity. */ static void initialize(uint32_t baudrate, Parity parity = Parity::Disabled) { enable(); // DIRTY HACK: disable and reenable uart to be able to set // baud rate as well as parity USART2->CR1 &= ~USART_CR1_UE; // Uart Disable setBaudrate(baudrate); setParity(parity); USART2->CR1 |= USART_CR1_UE; // Uart Reenable }
int SerialPort::openPort( const QString& port, int baudrate, SerialDataBits dataBits, SerialStopBits stopBits, SerialParity parity) { if (mIsOpen) { closePort(); } mFd = open(port.toLocal8Bit().data(), O_RDWR | O_NOCTTY | O_NDELAY); if (mFd == -1) { qCritical() << "Opening serial port failed."; return -1; } mIsOpen = true; // No-blocking reads fcntl(mFd, F_SETFL, FNDELAY); struct termios options; if (0 != tcgetattr(mFd, &options)) { qCritical() << "Reading serial port options failed."; return -2; } // Enable the receiver and set local mode... options.c_cflag |= CLOCAL | CREAD; // Raw input options.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG); // Disable flow control options.c_cflag &= ~CRTSCTS; options.c_iflag &= ~(IXON|IXOFF|IXANY); // ??? /*set up other port settings*/ options.c_cflag |= CREAD|CLOCAL; options.c_lflag &= (~(ICANON|ECHO|ECHOE|ECHOK|ECHONL|ISIG)); options.c_iflag &= (~(INPCK|IGNPAR|PARMRK|ISTRIP|ICRNL|IXANY)); options.c_oflag &= (~OPOST); options.c_cc[VMIN] = 0; #ifdef _POSIX_VDISABLE // Is a disable character available on this system? // Some systems allow for per-device disable-characters, so get the // proper value for the configured device const long vdisable = ::fpathconf(mFd, _PC_VDISABLE); options.c_cc[VINTR] = vdisable; options.c_cc[VQUIT] = vdisable; options.c_cc[VSTART] = vdisable; options.c_cc[VSTOP] = vdisable; options.c_cc[VSUSP] = vdisable; #endif //_POSIX_VDISABLE //Set the new options for the port... if (0 != tcsetattr(mFd, TCSANOW, &options)) { qCritical() << "Writing serial port options failed."; closePort(); return -3; } if (false == setDataBits(dataBits)) { qCritical() << "Setting data bits failed."; closePort(); return -4; } if (false == setStopBits(stopBits)) { qCritical() << "Setting stopbits failed."; closePort(); return -5; } if (false == setParity(parity)) { qCritical() << "Setting parity faield."; closePort(); return -6; } if (false == setBaudrate(baudrate)) { qCritical() << "Setting baudrate failed."; closePort(); return -7; } mAbort = false; start(LowPriority); return 0; }
Bluetooth::Bluetooth(USART_t* usart, PORT_t* port, uint32_t baud) : USART(usart, port, false) { setBaudrate(baud); }
// コンストラクタ Terminal::Terminal(QWidget *parent) : QMainWindow(parent), m_ds(this){ // 変数初期化 // GUIを作成 m_ui.setupUi(this); // GUI各部の制御クラスを作成 m_console = new TerminalConsole(m_ui.ConsoleInput, m_ui.ConsoleOutput, m_ui.ConsoleClear); m_info = new TerminalInfo(m_ui.StatusBar, m_ui.InfoIconDevice, m_ui.InfoLabelName, m_ui.InfoLabelVersion, m_ui.InfoButtonReboot, m_ui.InfoButtonConnect, m_ui.InfoButtonDisconnect); m_access = new TerminalAccess(m_ui.ProcessorInput, m_ui.ProcessorOpen, m_ui.ProcessorWrite, m_ui.ProcessorRead, m_ui.BitstreamInput, m_ui.BitstreamOpen, m_ui.BitstreamSend, m_ui.BitstreamWrite, m_ui.CoprocessorInput, m_ui.CoprocessorOpen, m_ui.CoprocessorSend, m_ui.CoprocessorWrite); m_controller = new TerminalController(this, m_ui.ControllerShow); m_logger = new TerminalLogger(m_ui.LoggerCheckUse, m_ui.LoggerGraph, m_ui.LoggerButtonAdd, m_ui.LoggerButtonRemove, m_ui.LoggerList, m_ui.LoggerSaveList, m_ui.LoggerLabel, m_ui.LoggerStart, m_ui.LoggerStop, m_ui.LoggerSave); m_pipe = new TerminalPipe(m_ui.PipeTable); m_file = new TerminalFile(m_ui.FileTree, m_ui.FileProgress); // ファイラータブのツールボックスにアイコンを設定 QFileIconProvider icon_provider; m_ui.FilerToolBox->setItemIcon(0, icon_provider.icon(QFileIconProvider::Network)); m_ui.FilerToolBox->setItemIcon(1, icon_provider.icon(QFileIconProvider::Drive)); // 非同期操作用のスレッドを作成 m_thread = new QThread(this); m_async = new TerminalAsync(&m_ds); m_async->moveToThread(m_thread); // シグナルを接続 connect(&m_ds, SIGNAL(enableConsole(bool)), m_console, SLOT(enable(bool))); connect(&m_ds, SIGNAL(enableInfo(bool, bool)), m_info, SLOT(enable(bool, bool))); connect(&m_ds, SIGNAL(enableAccess(char, bool, bool, bool, bool)), m_access, SLOT(enable(char, bool, bool, bool, bool))); connect(&m_ds, SIGNAL(enableFileTree(bool, bool, bool, bool, bool, bool)), m_file, SLOT(enable(bool, bool, bool, bool, bool, bool))); connect(&m_ds, SIGNAL(enableController(bool, bool, bool)), m_controller, SLOT(enable(bool, bool, bool))); connect(&m_ds, SIGNAL(enableLogger(bool, bool, bool)), m_logger, SLOT(enable(bool, bool, bool))); connect(m_async, SIGNAL(showWarningConst(const wchar_t *, const wchar_t *)), this, SLOT(showWarningConst(const wchar_t *, const wchar_t *)), Qt::QueuedConnection); connect(m_async, SIGNAL(sendProgress(int)), m_info, SLOT(setProgress(int)), Qt::QueuedConnection); connect(m_async, SIGNAL(setExclusiveState(bool)), &m_ds, SLOT(setExclusiveState(bool)), Qt::QueuedConnection); connect(m_console, SIGNAL(send(const QString &)), this, SLOT(transmitDebug(const QString &))); connect(m_info, SIGNAL(changeConnection(const std::wstring *, bool, bool)), this, SLOT(changeConnection(const std::wstring *, bool, bool))); connect(m_info, SIGNAL(rebootRequest(const wchar_t *)), &m_ds, SLOT(changeBootMode(const wchar_t *))); connect(m_access, SIGNAL(operation(char, std::wstring *)), m_async, SLOT(onAccessOperation(char, std::wstring *)), Qt::QueuedConnection); //connect(m_controller, SIGNAL(operation(const Controller_t &)), &m_ds, SLOT(setController(const Controller_t &))); connect(m_file, SIGNAL(updateRequest(const std::wstring &)), m_ds.m_dsDir, SLOT(updateRequest(const std::wstring &))); connect(m_file, SIGNAL(moveRequest(const std::wstring &, const std::wstring &)), m_ds.m_dsDir, SLOT(moveRequest(const std::wstring &, const std::wstring &))); connect(m_file, SIGNAL(copyRequest(const std::wstring &, const std::wstring &)), m_ds.m_dsDir, SLOT(copyRequest(const std::wstring &, const std::wstring &))); connect(m_file, SIGNAL(deleteRequest(const std::wstring &)), m_ds.m_dsDir, SLOT(deleteRequest(const std::wstring &))); connect(m_file, SIGNAL(mkdirRequest(const std::wstring &)), m_ds.m_dsDir, SLOT(mkdirRequest(const std::wstring &))); connect(m_file, SIGNAL(transfarToDevice(std::wstring *, std::wstring *)), m_async, SLOT(transfarToDevice(std::wstring *, std::wstring *)), Qt::QueuedConnection); connect(m_file, SIGNAL(transfarFromDevice(std::wstring *, std::wstring *)), m_async, SLOT(transfarFromDevice(std::wstring *, std::wstring *)), Qt::QueuedConnection); connect(m_logger, SIGNAL(sendLoggingList(char *, unsigned int)), m_async, SLOT(setLoggingList(char *, unsigned int)), Qt::QueuedConnection); connect(m_async, SIGNAL(sendLog(unsigned short *, unsigned int)), m_logger, SLOT(receiveLog(unsigned short *, unsigned int)), Qt::QueuedConnection); connect(m_async, SIGNAL(sendLoggingError()), m_logger, SLOT(receiveError()), Qt::QueuedConnection); connect(m_controller, SIGNAL(setControllerState(ControllerState_t *)), m_async, SLOT(setControllerState(ControllerState_t *)), Qt::QueuedConnection); connect(m_async, SIGNAL(requestControllerState()), m_controller, SLOT(requestControllerState()), Qt::QueuedConnection); connect(&m_ds, SIGNAL(setDebugText(QString &)), m_info, SLOT(setDebugText(QString &))); connect(&m_ds, SIGNAL(sendProgress(int)), m_info, SLOT(setProgress(int))); connect(&m_ds, SIGNAL(setLogInfo(const std::wstring &)), m_logger, SLOT(setLogInfo(const std::wstring &))); connect(&m_ds, SIGNAL(changeConnection(const std::wstring *, bool, bool)), this, SLOT(changeConnection(const std::wstring *, bool, bool))); connect(&m_ds, SIGNAL(updateWidgetsInfo()), this, SLOT(updateWidgetsInfo())); connect(m_ds.m_dsPipe, SIGNAL(clearPipe()), m_pipe, SLOT(clearPipe())); connect(m_ds.m_dsPipe, SIGNAL(addPipe(const wchar_t *, int, int, const wchar_t *)), m_pipe, SLOT(addPipe(const wchar_t *, int, int, const wchar_t *))); connect(m_ds.m_dsDir, SIGNAL(initTree(const std::wstring &)), m_file, SLOT(initTree(const std::wstring &))); connect(m_ds.m_dsDir, SIGNAL(addDrive(char, const std::wstring &, bool, unsigned long long)), m_file, SLOT(addDrive(char, const std::wstring &, bool, unsigned long long))); connect(m_ds.m_dsDir, SIGNAL(changeDriveStatus(char, unsigned long long)), m_file, SLOT(changeDriveStatus(char, unsigned long long))); connect(m_ds.m_dsDir, SIGNAL(moveToItem(const std::wstring &)), m_file, SLOT(moveToItem(const std::wstring &))); connect(m_ds.m_dsDir, SIGNAL(addItem(const std::wstring &, unsigned long long, bool, unsigned int)), m_file, SLOT(addItem(const std::wstring &, unsigned long long, bool, unsigned int))); connect(m_ds.m_dsDir, SIGNAL(moveUp()), m_file, SLOT(moveUp())); connect(m_ds.m_dsFile, SIGNAL(changeFile(std::wstring *, unsigned long long)), m_file, SLOT(changeFile(std::wstring *, unsigned long long)), Qt::QueuedConnection); // タイマーを作成 QTimer *interval = new QTimer(this); connect(interval, SIGNAL(timeout()), this, SLOT(onInterval())); connect(interval, SIGNAL(timeout()), m_logger, SLOT(update())); interval->start(PERIOD); // ウィジェットを初期状態に m_console->enable(false); m_info->enable(false, false); m_access->enable('P', false); m_access->enable('B', false); m_access->enable('C', false); m_file->enable(false); m_controller->enable(false); m_logger->enable(false); // 前回の設定の読み込み int maximized = 0; clINI setting; if (setting.Open(g_ApplicationDir.c_str(), L"setting.ini") == true){ // パスの読み込み wchar_t buf[MAX_PATH]; setting.Read(L"Path", L"Processor", buf); m_access->setPath('P', buf); setting.Read(L"Path", L"Bitstream", buf); m_access->setPath('B', buf); setting.Read(L"Path", L"Coprocessor", buf); m_access->setPath('C', buf); // 設定の読み込み int baudrate = m_info->getBaudrate(); setting.Read(L"Setting", L"Baudrate", baudrate); m_info->setBaudrate(baudrate); // ウィンドウ座標・サイズの読み込み int pos_x, pos_y, size_w, size_h; setting.Read(L"Window", L"Maximize", maximized); setting.Read(L"Window", L"PosX", pos_x); setting.Read(L"Window", L"PosY", pos_y); setting.Read(L"Window", L"SizeW", size_w); setting.Read(L"Window", L"SizeH", size_h); pos_x -= 500000; pos_y -= 500000; size_w -= 500000; size_h -= 500000; if ((abs(pos_x) <= 32767) && (abs(pos_y) <= 32767)) this->move(pos_x, pos_y); if ((abs(size_w) <= 32767) && (abs(size_h) <= 32767)) this->resize(size_w, size_h); } // 非同期操作用スレッドを開始 m_thread->start(); // タイマーの精度を高める timeBeginPeriod(1); // ウィンドウを表示 if (maximized == 0){ this->show(); }else{ this->showMaximized(); } }
Uart5(uint32_t baudrate) { setBaudrate(baudrate); }
/** * Set baudrate. * * \param baudrate Desired baud rate (e.g. 115200) * \param interruptPriority * Interrupt vector priority (0=highest to 15=lowest) * \param blocking * The write-function waits until a free slot is available * in the send buffer. */ BufferedFlowUart5(uint32_t baudrate, uint32_t interruptPriority, bool blocking = true) { setBaudrate(baudrate, interruptPriority, blocking); }
bool CApoxObj::open( const char *szFileName, unsigned long flags ) { const char *p; unsigned long busspeed = 125; m_emergencyInfo = 0; char szDrvParams[ MAX_PATH ]; m_initFlag = flags; m_RxMsgState = USB_IDLE; // save parameter string and conbert to upper case strncpy( szDrvParams, szFileName, MAX_PATH ); _strupr( szDrvParams ); // Initiate statistics m_stat.cntReceiveData = 0; m_stat.cntReceiveFrames = 0; m_stat.cntTransmitData = 0; m_stat.cntTransmitFrames = 0; m_stat.cntBusOff = 0; m_stat.cntBusWarnings = 0; m_stat.cntOverruns = 0; // if open we have noting to do if ( m_bRun ) return true; // serial p = strtok( szDrvParams, ";" ); if ( NULL != p ) { strcpy( m_SerialNumber, p ); } // Bus-Speed p = strtok( NULL, ";" ); if ( NULL != p ) { if ( ( NULL != strstr( p, "0x" ) ) || ( NULL != strstr( p, "0X" ) ) ) { sscanf( p + 2, "%x", &busspeed ); } else { busspeed = atol( p ); } } // Handle busspeed uint8_t nSpeed = CAN_BAUD_1000; switch ( busspeed ) { case 125: nSpeed = CAN_BAUD_125; break; case 250: nSpeed = CAN_BAUD_250; break; case 500: nSpeed = CAN_BAUD_500; break; case 1000: nSpeed = CAN_BAUD_1000; break; default: nSpeed = CAN_BAUD_125; break; } FT_STATUS ftStatus; ftStatus = FT_OpenEx( (void *)m_SerialNumber, FT_OPEN_BY_SERIAL_NUMBER, &m_ftHandle ); if ( !FT_SUCCESS( ftStatus ) ) return false; ftStatus = FT_ResetDevice( m_ftHandle ); ftStatus = FT_Purge( m_ftHandle, FT_PURGE_RX | FT_PURGE_TX ); ftStatus = FT_SetTimeouts(m_ftHandle, 378, 128); ftStatus = FT_SetUSBParameters ( m_ftHandle, 2048, 2048 ); ftStatus = FT_SetLatencyTimer( m_ftHandle, 3 ); // Run run run ..... m_bRun = true; #ifdef WIN32 // Start write thread DWORD threadId; if ( NULL == ( m_hTreadTransmit = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) workThreadTransmit, this, 0, &threadId ) ) ) { // Failure close(); return false; } // Start read thread if ( NULL == ( m_hTreadReceive = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) workThreadReceive, this, 0, &threadId ) ) ) { // Failure close(); return false; } // Release the mutex UNLOCK_MUTEX( m_apoxMutex ); UNLOCK_MUTEX( m_receiveMutex ); UNLOCK_MUTEX( m_transmitMutex ); UNLOCK_MUTEX( m_responseMutex ); #else // LINUX pthread_attr_t thread_attr; pthread_attr_init( &thread_attr ); // Create the log write thread. if ( pthread_create( &m_threadId, &thread_attr, workThreadTransmit, this ) ) { syslog( LOG_CRIT, "canallogger: Unable to create apoxdrv write thread."); rv = false; fclose( m_flog ); } // Create the log write thread. if ( pthread_create( &m_threadId, &thread_attr, workThreadReceive, this ) ) { syslog( LOG_CRIT, "canallogger: Unable to create apoxdrv receive thread."); rv = false; fclose( m_flog ); } // We are open m_bOpen = true; // Release the mutex pthread_mutex_unlock( &m_apoxMutex ); #endif // Switch to main mode if in boot mode if ( RUNMODE_BOOT == getAdapterRunMode() ) { setAdapterRunMode( RUNMODE_MAIN ); } // Set baudrate setBaudrate( nSpeed ); // Set initial filter/mask switch( m_initFlag & 0x03 ) { case 0: case 3: m_filtermask.rx_buff1_ext = 0; m_filtermask.rx_buff2_ext = 1; break; case 1: m_filtermask.rx_buff1_ext = 0; m_filtermask.rx_buff2_ext = 0; break; case 2: m_filtermask.rx_buff1_ext = 1; m_filtermask.rx_buff2_ext = 1; break; } m_filtermask.RXM0 = 0; m_filtermask.RXM1 = 0; m_filtermask.RXF0 = 0; m_filtermask.RXF1 = 0; m_filtermask.RXF2 = 0; m_filtermask.RXF3 = 0; m_filtermask.RXF4 = 0; m_filtermask.RXF5 = 0; setAdapterFilterMask( &m_filtermask ); // Set transmission mode short trmode = ( (short)( m_initFlag & 0x0c ) >> 2 ); if ( 0 == trmode ) trmode = TRMODE_NORMAL; setTransmissionMode( trmode ); return true; }