Click here to Skip to main content
13,766,421 members

C / C++ / MFC

 
GeneralRe: Object pointer as method argument Pin
_Flaviu8-Jul-18 20:57
member_Flaviu8-Jul-18 20:57 
NewsRe: Object pointer as method argument Pin
Richard MacCutchan9-Jul-18 4:01
protectorRichard MacCutchan9-Jul-18 4:01 
AnswerRe: Object pointer as method argument Pin
CPallini8-Jul-18 21:59
mvpCPallini8-Jul-18 21:59 
GeneralRe: Object pointer as method argument Pin
_Flaviu9-Jul-18 6:45
member_Flaviu9-Jul-18 6:45 
QuestionMFC Static Library Project Pin
Richard Andrew x647-Jul-18 17:04
professionalRichard Andrew x647-Jul-18 17:04 
AnswerRe: MFC Static Library Project Pin
Victor Nijegorodov7-Jul-18 22:48
memberVictor Nijegorodov7-Jul-18 22:48 
GeneralRe: MFC Static Library Project Pin
Richard Andrew x648-Jul-18 4:26
professionalRichard Andrew x648-Jul-18 4:26 
QuestionUsing fstream with USB Serial Port Pin
OscardelaGrouch6-Jul-18 21:53
memberOscardelaGrouch6-Jul-18 21:53 
Hello everyone,
I'm kinda new to writing application programs for a PC, a Linux one at that, so I hope this isn't a stupid question. Wink | ;)
I am rather experienced at writing C programs for Microchip PICs. I need a PC application to interface with a PIC project, it will up load information to the PIC from the PC using a pair of Wixel modules. They are basically a USB to RF or RF to Serial bridge. I have them working (one connected to the PC, one connected to the PIC) using a terminal program. I can send data back and forth just fine.
I am now trying to send and receive data using a C++ application. The sending from the PC to the PIC works just fine also. The problem I am having is getting data from the PIC to the PC Application.

This is the application code ..
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;

/*
 * 
 */
int main(int argc, char** argv)
{
    fstream COMPORT;

    char line[256];
    streamsize lim = 256;
    char c;

    COMPORT.open("/dev/ttyACM0");
    
    while(1)    // only works for first input. run again and missed one reply
    {
        if (COMPORT.is_open())
        {
            cout << "Hit <Enter> to send command, <S> to Stop .." << endl;
            cin.get(c);
            if ((c == 's' || c == 'S')) 
            {
                COMPORT.close();
                return 0;
            }
            COMPORT << "UPLOAD NEW MAP\n";
            COMPORT.getline(line, lim);
            cout << "Line =" << line;
            cout << "Response=" << c;
            cout << endl;
        }
    }
    COMPORT.close();
    return 0;
}


The PIC code, if that helps ..
void APP_Wixel_IO_Test_Tasks(void)
{
    APP_ESUART_Tasks();
    if (CmdReady == 1)
    {
        CmdReady = 0;                               // reset flag
        RXBufCnt = 0;                     // reset RX Buffer count command
        utoa(TXBuf, Cnt, 10);
        strcat(TXBuf, "\n");
        WriteESUARTDataMsg(TXBuf, strlen(RXBuf));   // send command back to ESUART
        Cnt++;                                      // increment cnt
    }
}


Basically all the PIC code does is send back the 'cnt' variable when it gets data from the PC.
The
COMPORT.getline(line, lim);
doesn't work right. The first time I run it, it kinda works, but resending the data back to the PIC gets no response ..

Hit <Enter> to send command, <S> to Stop ..

Response=4
Hit <Enter> to send command, <S> to Stop ..

Response=

Hit <Enter> to send command, <S> to Stop ..

Response=

Hit <Enter> to send command, <S> to Stop ..

Response=

Hit <Enter> to send command, <S> to Stop ..


I've tried everything I can think of. Like I said, data out
COMPORT << "UPLOAD NEW MAP\n";
works fine. Data in does not.
Thanks Wink | ;)
OtG
AnswerRe: Using fstream with USB Serial Port Pin
Richard MacCutchan7-Jul-18 0:25
protectorRichard MacCutchan7-Jul-18 0:25 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch7-Jul-18 7:39
memberOscardelaGrouch7-Jul-18 7:39 
GeneralRe: Using fstream with USB Serial Port Pin
Richard MacCutchan7-Jul-18 7:52
protectorRichard MacCutchan7-Jul-18 7:52 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch7-Jul-18 7:55
memberOscardelaGrouch7-Jul-18 7:55 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch7-Jul-18 9:21
memberOscardelaGrouch7-Jul-18 9:21 
GeneralRe: Using fstream with USB Serial Port Pin
speedbump997-Jul-18 13:59
memberspeedbump997-Jul-18 13:59 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch7-Jul-18 14:18
memberOscardelaGrouch7-Jul-18 14:18 
GeneralRe: Using fstream with USB Serial Port Pin
speedbump997-Jul-18 15:51
memberspeedbump997-Jul-18 15:51 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch7-Jul-18 16:46
memberOscardelaGrouch7-Jul-18 16:46 
GeneralRe: Using fstream with USB Serial Port Pin
speedbump997-Jul-18 17:10
memberspeedbump997-Jul-18 17:10 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch8-Jul-18 9:08
memberOscardelaGrouch8-Jul-18 9:08 
GeneralRe: Using fstream with USB Serial Port Pin
speedbump998-Jul-18 12:55
memberspeedbump998-Jul-18 12:55 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch9-Jul-18 9:49
memberOscardelaGrouch9-Jul-18 9:49 
AnswerRe: Using fstream with USB Serial Port Pin
OscardelaGrouch8-Jul-18 11:57
memberOscardelaGrouch8-Jul-18 11:57 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch9-Jul-18 9:52
memberOscardelaGrouch9-Jul-18 9:52 
AnswerRe: Using fstream with USB Serial Port Pin
Jochen Arndt10-Jul-18 4:31
mvpJochen Arndt10-Jul-18 4:31 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch10-Jul-18 10:53
memberOscardelaGrouch10-Jul-18 10:53 

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.


Advertise | Privacy | Cookies | Terms of Service
Web05-2016 | 2.8.181114.1 | Last Updated 15 Nov 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid