| | |
Error: write send data to comm port
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
#include <stdio.h> // standard input / output functions
#include <string.h> // string function definitions
#include <unistd.h> // UNIX standard function definitions
#include <fcntl.h> // File control definitions
#include <errno.h> // Error number definitions
#include <termios.h> // POSIX terminal control definitionss
#include <time.h> // time calls
#include <conio.h>
#include <iomanip.h>
#include <sys/time.h> //for timeout
#include <sys/select.h>
#include <fstream.h>
int open_port(void)
{
int fd; // file description for the serial port
fd = open("/dev/ser2", O_RDWR | O_APPEND | O_SYNC );
if(fd == -1) // if open is unsucessful
{
printf("\nopen_port: Unable to open /dev/ttyS0. \n");
}
else
{
fcntl(fd, F_SETFL, 0);
printf("port is open.\n");
}
return(fd);
}
int configure_port(int fd) // configure the port
{
struct termios port_settings; // structure to store the port settings in
port_settings.c_cflag = ( CS8 | CREAD | CLOCAL );
port_settings.c_cflag &= ~PARENB; // set no parity, stop bits, data bits
port_settings.c_cflag &= ~CSTOPB;
port_settings.c_cflag &= ~CSIZE;
port_settings.c_cflag |= CS8;
cfsetispeed(&port_settings, B9600); // set baud rates
cfsetospeed(&port_settings, B9600);
tcsetattr(fd, TCSANOW, &port_settings); // apply the settings to the port
return(fd);
} //configure_port
int query_modem(int fd) // query modem with an AT command
{
int m, n;
fd_set rdfs;
struct timeval timeout;
// initialise the timeout structure
timeout.tv_sec = 5; // ten second timeout
timeout.tv_usec = 0;
/
// const char* test="1234";
int success=0;
success=write(fd, test, strlen(test)); //Send data
//n = select(fd + 1, &rdfs, NULL, NULL, &timeout);
n = select(1, &rdfs, NULL, NULL, &timeout);
printf("n before if ------------------> = %d\n", n); //0
if( n==-1)
{
perror("select failed\n");
}
else if (n)
{
printf("\nBytes detected on the port!\n");
}
else
printf("n else------------------> = %d\n", n); //0
printf("\nNo data!\n");
return 0;
}
int main(void)
{
int fd = open_port();
cout<<"\n*********** test ******************"<<endl;
printf("\n________________________________________________________\n");
printf("\n Integrated TVM with Printer (5)\n");
printf("\________________________________________________________\n");
configure_port(fd);
query_modem(fd);
printf("\____________________dah ok______________________\n");
return(0);
} //main
Last edited by msofian3; Nov 10th, 2009 at 4:53 am.
![]() |
Similar Threads
- Send data on a serial port (C)
- how i get serial data from comm port using visual basic 2005 (VB.NET)
- Listen to Serial Comm Port (Visual Basic 4 / 5 / 6)
- Send data on a serial port (C++)
- Sending data to serial port (Visual Basic 4 / 5 / 6)
- About Comm Port (Visual Basic 4 / 5 / 6)
- send data with modem (Java)
Other Threads in the C++ Forum
- Previous Thread: how randomise function works
- Next Thread: How to make a C++ game??
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





