Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Qt Serialport to CDC Pinguino
31-03-2015, 05:09 AM,
#1
Qt Serialport to CDC Pinguino
hello everyone i have a problem, i can't connect a c++ app to pinguino via CDC, its about getting a led turn on and off depending on the data recived, the thing is, by using the same app i can get it done in arduino, plus if i open the serial port monitor of arduino IDE it works on pinguino and arduino as well.
and by the way there is any serial drivers for the board so i can use the serial class??? i've been searching the web for months with no luck.
here is my code, thanks in advance.
Code:
char dato;  
char receivedbyte;
char buff[64];  
#define led 7
  
void setup(){  
    pinMode(led, OUTPUT);  
    digitalWrite(led,LOW);  
}  
  
void loop() {      
    while((receivedbyte = CDC.read(buff)) == 0);  
        CDC.printf("Caracter Recibido! \r\n");  
    
    if(receivedbyte > 0){  
        dato = buff[0];                        
        if(dato == 49){
            digitalWrite(led,HIGH);  
            CDC.printf("Led Encendido \r\n");  
  
         }else if(dato == 50){  
             digitalWrite(led,LOW);  
             CDC.printf("Led Apagado \r\n");  
         }        
    }  
}
acta non verba
Reply
31-03-2015, 08:57 AM,
#2
RE: Qt Serialport to CDC Pinguino
Would you give more details relating to the board you use : 8 or 32bits, what chip 18fx550, 18f26j50, 18f47j53 etc ... ?
Side PC what system and what  C++ suite (QT ?) ? Give more details please !

Do you know you can also use Python to communicate easily to Pinguino boards via CDC port ?
Bye
André
Reply
31-03-2015, 11:54 AM,
#3
RE: Qt Serialport to CDC Pinguino
I tested your code with IDE x.4 and a 18f4550 pinguino.
I used hyperterminal on my PC windows 7. It is a bit difficult that Hyperterminal recognizes the virtual CDC port but I succeeded : the on/off led control works well and the messages are received on the terminal as well.
If you use Linux use minicom as terminal.
If you want simply a led control a more sophisticated interface than Hyperterminal or Minicom is not necessary !
Bye
André
Reply
31-03-2015, 12:41 PM,
#4
RE: Qt Serialport to CDC Pinguino
Visit this page created by Yeison Cardona, a Colombian Pinguino developper :

https://bitbucket.org/YeisonEng/pynguino-2.0/src

With his tools you can control a Pinguino board from your PC using a virtual CDC port.
Bye
André
Reply
31-03-2015, 10:54 PM,
#5
RE: Qt Serialport to CDC Pinguino
(31-03-2015, 08:57 AM)gtcbreizh Wrote: Would you give more details relating to the board you use : 8 or 32bits, what chip 18fx550, 18f26j50, 18f47j53 etc ... ?
Side PC what system and what  C++ suite (QT ?) ? Give more details please !

Do you know you can also use Python to communicate easily to Pinguino boards via CDC port ?
Bye
André

Hi gtcbreizh, im using a 8 bit board, the 18f2550 one on Windows7 332 bit. Pinguino IDE 11.2015.02.02 and my Qt version is 5.4.0
here is my Qt code:
.pro
Code:
QT       += core gui\
           serialport

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = serialComTest
TEMPLATE = app


SOURCES += main.cpp\
       mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui
main.cpp
Code:
#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[]){
   QApplication a(argc, argv);
   a.setStyle("fusion");
   MainWindow w;
   w.setWindowTitle("Serial Com Test");
   w.show();

   return a.exec();
}
mainwindow.cpp
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSerialPort/QSerialPort>
#include <QMessageBox>

QSerialPort *board; // Apuntador tipo serial
MainWindow::MainWindow(QWidget *parent) :  QMainWindow(parent),
   ui(new Ui::MainWindow){
   ui->setupUi(this);

   // Conexion de las señales de widgets con los slots particulares
   connect(ui->on, SIGNAL(clicked()), this, SLOT(on()));
   connect(ui->off, SIGNAL(clicked()), this, SLOT(off()));
   connect(board, SIGNAL(readyRead()), this, SLOT(readBoard()));
}

MainWindow::~MainWindow(){  
   board->close();
   board->destroyed();
   delete ui;
}

void MainWindow::readBoard(){
   QByteArray  inputByte = board->readAll();
   QString c = inputByte;
   ui->textEdit->setText(c + c);
   board->clear(QSerialPort::AllDirections);
}

void MainWindow::on(){
   /*QByteArray outByte;
   char c = '1';
   outByte.append(c);
   board->write(outByte);*/
   QString c = "1";
   if (board->isWritable()){
       board->write(c.toStdString().c_str());
   } else {
       QMessageBox::warning(this, "Error", "Cant Write on the Board");
   }
}

void MainWindow::off(){
   QByteArray outByte;
   char c = '2';
   outByte.append(c);
   board->write(outByte);
}

void MainWindow::on_on_clicked(){
   on();
}

void MainWindow::on_off_clicked(){
   off();
}

void MainWindow::on_open_com_3_clicked(){
   board = new QSerialPort(this); // Objeto de tipo serial
   // Configuracion para la comunicacion serial segun se requiera
   board->setPortName("/COM3");
   board->open(QIODevice::ReadWrite);
   board->setBaudRate(QSerialPort::Baud9600);
   board->setStopBits(QSerialPort::OneStop);
   board->setParity(QSerialPort::NoParity);
   board->setDataBits(QSerialPort::Data8);
   board->setFlowControl(QSerialPort::NoFlowControl);

   if (board->isOpen()){
       QMessageBox::information(this, "Info", "Port Open" );
   } else {
       QMessageBox::information(this, "Info", "Port Error");
   }
}
mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow{
   Q_OBJECT

public:
   explicit MainWindow(QWidget *parent = 0);
   ~MainWindow();        

public slots:
   void readBoard();
   void on();
   void off();

private slots:
   void on_on_clicked();
   void on_off_clicked();

   void on_open_com_3_clicked();

private:
   Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H
acta non verba
Reply
31-03-2015, 11:05 PM,
#6
RE: Qt Serialport to CDC Pinguino
(31-03-2015, 12:41 PM)gtcbreizh Wrote: Visit this page created by Yeison Cardona, a Colombian Pinguino developper :

https://bitbucket.org/YeisonEng/pynguino-2.0/src

With his tools you can control a Pinguino board from your PC using a virtual CDC port.
Bye
André

its not that simple, just answer me, why it works on arduino but not on pinguino? why does the serial port monitor of arduino IDE works on both arduino and pinguino as well? why does it work on python and ruby but not on a powerfull tool like Qt?
i need to control a 5 degree robotic arm using an interface from Qt, to see the state of every stepper motor and put that in a dial widget, plus i need to be able to control that  from the gui itself. I can't afford another arduino board so i want to use both, but i can't find a way around on pinguino CDC mode.....
why there is no any serial driver for those chips anyways? i what scenario do i need to use the pinguino serial class then?
- sorry for so may questions but i've been searching the web for months and im running out of time and resources...   
acta non verba
Reply
01-04-2015, 11:08 AM,
#7
RE: Qt Serialport to CDC Pinguino
As soon I can I shall try to test via Qt.
I don't know Qt indeed and time is needed to manage with the Qt IDE that is not simple !
Bye
André
Reply
01-04-2015, 06:45 PM, (This post was last modified: 01-04-2015, 06:45 PM by joel.)
#8
RE: Qt Serialport to CDC Pinguino
Hi,
Actually looks like the same problem i had with pinguino CDC and Visual Basic application (W7 64 bits)
All is working fine with hyperterminal, Teraterm, minicom or whatever, but as soon as i wanted to communicate with the pinguino through CDC with a more "elaborated" application (win app), it failed.
Don't know, however, if it is related to the windows CDC driver (virtual com port) or to the PIC side or other thing.
I did not tested application under linux, but it may be interesting to see if it's coming from a "bad" implementation on the PC driver or on the PIC code

Joël
Reply
01-04-2015, 06:56 PM,
#9
RE: Qt Serialport to CDC Pinguino
Hello Joel,
With Python we can communicate between PC and Pinguino boards using a virtual CDC port. See Yeison's pages.
Bye
André
Reply
01-04-2015, 09:24 PM,
#10
RE: Qt Serialport to CDC Pinguino
(01-04-2015, 06:56 PM)gtcbreizh Wrote: Hello Joel,
With Python we can communicate between PC and Pinguino boards using a virtual CDC port. See Yeison's pages.
Bye
André

it's true that python can comunicate between pc and pinguino via CDC, but i would like to try via serial as well, how can i do that? the serial class is on pinguino yes, but i've never seen any particular use of it, when i plug my board using a serial example a COM port does not show up. any ideas? y want to help pinuino comunity by doing this, there's has to be a way!.     
acta non verba
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)