Hi,
I want to pass strings to the following port (/dev/ttyUSB1) using Linux, but I can't get a succesful connection. The code I am using is the following:
I would be grateful for any help.Code:#include <stdio.h> #include <iostream> #include <fstream> #include <string> #include <stdlib.h> #include <time.h> using namespace std; #define MODEL_ID "at+gmm" int main (){ string result; ofstream oUSB1; ifstream inUSB1; oUSB1.open ("/dev/ttyUSB1"); inUSB1.open ("/dev/ttyUSB1"); if (oUSB1.is_open() && inUSB1.is_open()){ cout << "Successfully opened communications to Modem" << endl; oUSB1 << MODEL_ID; cout << "Sending command " << MODEL_ID << endl; inUSB1 >> result; oUSB1.close(); inUSB1.close(); cout << "Received the following back: " << result << endl; } else { cout << "Unsuccessful" << endl; } }
The compiler I am using is g++
Regards
Brownie