Click here to Skip to main content
14,241,566 members

C / C++ / MFC

 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch9-Jul-18 8:49
memberOscardelaGrouch9-Jul-18 8:49 
AnswerRe: Using fstream with USB Serial Port Pin
OscardelaGrouch8-Jul-18 10:57
memberOscardelaGrouch8-Jul-18 10:57 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch9-Jul-18 8:52
memberOscardelaGrouch9-Jul-18 8:52 
AnswerRe: Using fstream with USB Serial Port Pin
Jochen Arndt10-Jul-18 3:31
mveJochen Arndt10-Jul-18 3:31 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch10-Jul-18 9:53
memberOscardelaGrouch10-Jul-18 9:53 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch10-Jul-18 18:43
memberOscardelaGrouch10-Jul-18 18:43 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt10-Jul-18 21:09
mveJochen Arndt10-Jul-18 21:09 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch11-Jul-18 17:40
memberOscardelaGrouch11-Jul-18 17:40 
Jochen Arndt wrote:
I did not see any code that initialises the serial port.

There is, I was having trouble with the forum editor, thought maybe my code was too long.
The first part is here ..
/***** Class Declaration ******************************************************/
class ComPort
{
public:
    ComPort();
    ~ComPort();
    void WriteComPortDataMsg(char *data, char num);
    void ReadComPortDataMsg(char *data, char dlimc);
    void ReadComPortDataMsg(char *data);
    void SetDlimiter(char dlimc);
private:
    char dlim;
    struct termios  config;
    int hComPort;
    bool Error;
};

ComPort::ComPort()
{
    dlim = '\n';
    char c;

    Error = false;
    hComPort = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY);
    if (hComPort == -1)
    {
        cout << "failed to open port\n" << endl;
        cout << "Hit <S> to Stop .." << endl;
        cin >> c;
        c = (char)toupper(c);
        if (c == 'S') Error = true;
    }
    
    if(!isatty(hComPort))
    {
        cout << "file descriptor is  not pointing to a TTY device\n" << endl;
        cout << "Hit <S> to Stop .." << endl;
        cin.get(c);
        if ((c == 's' || c == 'S')) Error = true;
    }
    
    if(tcgetattr(hComPort, &config) < 0)
    {
        cout << "configuration of the serial interface not found\n" << endl;
        cout << "Hit <S> to Stop .." << endl;
        cin >> c;
        c = (char)toupper(c);
        if (c == 'S') Error = true;
    }
    
    //
    // Input flags - Turn off input processing
    //
    // convert break to null byte, no CR to NL translation,
    // no NL to CR translation, don't mark parity errors or breaks
    // no input parity check, don't strip high bit off,
    // no XON/XOFF software flow control
    //
    config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON);
    
    // Output flags - Turn off output processing
    //
    // no CR to NL translation, no NL to CR-NL translation,
    // no NL to CR translation, no column 0 CR suppression,
    // no Ctrl-D suppression, no fill characters, no case mapping,
    // no local output processing
    //
    // config.c_oflag &= ~(OCRNL | ONLCR | ONLRET |
    //                     ONOCR | ONOEOT| OFILL | OLCUC | OPOST);
    config.c_oflag = 0;

    //
    // No line processing
    //
    // echo off, echo newline off, canonical mode off, 
    // extended input processing off, signal chars off
    //
    config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);

    //
    // Turn off character processing
    //
    // clear current char size mask, no parity checking,
    // no output processing, force 8 bit input
    //
    config.c_cflag &= ~(CSIZE | PARENB);
    config.c_cflag |= CS8;
    
    if(cfsetispeed(&config, B9600) < 0 || cfsetospeed(&config, B9600) < 0)
    {
        cout << "Baud Rate did not set correctly\n" << endl;
        cout << "Hit <S> to Stop .." << endl;
        cin >> c;
        c = (char)toupper(c);
        if (c == 'S') Error = true;
    }
    
    
    if(tcsetattr(hComPort, TCSAFLUSH, &config) < 0)
    {
        cout << "Configuration set did not work\n" << endl;
        cout << "Hit <S> to Stop .." << endl;
        cin >> c;
        c = (char)toupper(c);
        if (c == 'S') Error = true;
    }
    
    //tcflush(hComPort, TCIOFLUSH);               // clear comport
}

ComPort::~ComPort() { close(hComPort);  }


So, any ideas? Wink | ;)
Thanks for the reply also!!
OdlG
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt11-Jul-18 21:16
mveJochen Arndt11-Jul-18 21:16 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch12-Jul-18 18:42
memberOscardelaGrouch12-Jul-18 18:42 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt12-Jul-18 20:59
mveJochen Arndt12-Jul-18 20:59 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch14-Jul-18 7:51
memberOscardelaGrouch14-Jul-18 7:51 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt14-Jul-18 8:36
mveJochen Arndt14-Jul-18 8:36 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch14-Jul-18 8:38
memberOscardelaGrouch14-Jul-18 8:38 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt14-Jul-18 8:43
mveJochen Arndt14-Jul-18 8:43 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch14-Jul-18 9:40
memberOscardelaGrouch14-Jul-18 9:40 
GeneralRe: Using fstream with USB Serial Port Pin
Jochen Arndt14-Jul-18 12:49
mveJochen Arndt14-Jul-18 12:49 
QuestionWhich do I use ide for learn c ++ Pin
Onur Çil6-Jul-18 2:33
memberOnur Çil6-Jul-18 2:33 
AnswerRe: Which do I use ide for learn c ++ Pin
Richard MacCutchan6-Jul-18 2:54
protectorRichard MacCutchan6-Jul-18 2:54 
AnswerRe: Which do I use ide for learn c ++ Pin
CPallini7-Jul-18 11:06
mveCPallini7-Jul-18 11:06 
GeneralRe: Which do I use ide for learn c ++ Pin
Daniel Pfeffer8-Jul-18 1:49
professionalDaniel Pfeffer8-Jul-18 1:49 
GeneralRe: Which do I use ide for learn c ++ Pin
CPallini8-Jul-18 20:56
mveCPallini8-Jul-18 20:56 
Questionfree pointer to pointer Pin
Diprom3-Jul-18 4:10
memberDiprom3-Jul-18 4:10 
AnswerRe: free pointer to pointer Pin
Richard MacCutchan3-Jul-18 4:23
protectorRichard MacCutchan3-Jul-18 4:23 
AnswerRe: free pointer to pointer Pin
CPallini3-Jul-18 10:25
mveCPallini3-Jul-18 10:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.