Click here to Skip to main content
14,269,309 members

C / C++ / MFC

 
GeneralRe: Using fstream with USB Serial Port Pin
OscardelaGrouch8-Jul-18 8:08
memberOscardelaGrouch8-Jul-18 8:08 
GeneralRe: Using fstream with USB Serial Port Pin
speedbump998-Jul-18 11:55
memberspeedbump998-Jul-18 11:55 
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 
Thanks for the help so far. I have written a small PC App program to try termios out.
I am having two issues.
First is the first time I send data to the PIC, the return response is junk.
Second is the response is out of sync with the sent command, it takes sending the command a second time for the response string to be correct. Would appreciate a second pair of eyes to see what is the problem.

PC app code ..
int main(int argc, char** argv)
{
    ComPort MyComPort;
    char TXBuf[255];
    char RXBuf[255];
    char c;
    
    while(1)
    {
        cout << "(U)load New Map, (N)ext Map, (Q)uit .." << endl;
        cin >> c;
        c = (char)toupper(c);
        if (c == 'Q') return 0;
        if (c == 'U')
        {
            strcpy(TXBuf, "UPLOAD NEW MAP\n");
            MyComPort.WriteComPortDataMsg(TXBuf, strlen(TXBuf));
            MyComPort.ReadComPortDataMsg(RXBuf);
            cout << "RXBuf = " << RXBuf << endl;
        }
        else if (c == 'N')
        {
            strcpy(TXBuf, "NEXT MAP\n");
            MyComPort.WriteComPortDataMsg(TXBuf, strlen(TXBuf));
            MyComPort.ReadComPortDataMsg(RXBuf);
            cout << "RXBuf = " << RXBuf << endl;
        }
        cout << endl;
    }
    return 0;
}

class defs ..

/***** 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;
};

void ComPort::WriteComPortDataMsg(char *data, char num)
{
    for (int cnt = 0; cnt < num; cnt++)
    {
        write(hComPort, &data[cnt], 1);         // write char to Com Port
    }
    tcdrain(hComPort);
}

void ComPort::ReadComPortDataMsg(char *data)
{
    int cnt = 0;
    char c;

    data[0] = 0x00;
    do
    {
        read(hComPort, &c, 1);
        if ((c >= 0x20) && (c <= 0x7E)) data[cnt++] = c;
    } while ((c != dlim) && (cnt < 255));
    data[cnt++] = '\0';
}


responses ..
(U)load New Map, (N)ext Map, (Q)uit ..
u
RXBuf = MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM

(U)load New Map, (N)ext Map, (Q)uit ..
u
RXBuf = Processing: UPLOAD NEW MAP

(U)load New Map, (N)ext Map, (Q)uit ..
u
RXBuf = Processing: UPLOAD NEW MAP

(U)load New Map, (N)ext Map, (Q)uit ..
n
RXBuf = Processing: UPLOAD NEW MAP

(U)load New Map, (N)ext Map, (Q)uit ..
n
RXBuf = Processing: NEXT MAP

(U)load New Map, (N)ext Map, (Q)uit ..
n
RXBuf = Processing: NEXT MAP

(U)load New Map, (N)ext Map, (Q)uit ..
q

RUN FINISHED; exit value 0; real time: 13s; user: 0ms; system: 0ms


As you can see the first command response gets junk in RXBuf. The second time response is correct.
Changing the command to "Next Map" gets incorrect response the first time but OK response the second.
Any ideas would be appreciated.
Thanks
OdlG
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 
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 

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.