GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Mar-2005, 14:22
collinm collinm is offline
New Member
 
Join Date: Mar 2005
Posts: 20
collinm is on a distinguished road

Problem to read on a serial port


hi

i send a command to a led display, the led display is suppose to return me some character

i write a string on a serial port
CPP / C++ / C Code:
void ledDisplayExist()
{
    char msg[]={'\0', '\0', '\0', '\0', '\0', '\1', 'Z', '0', '0', '\2', 'H', 'B', '\4'  };
    int length = sizeof(msg); 
    writeopen(msg, length);
    readopen();
}

int writeopen(char msg[], int size)
{
    printf("write\n");
    int fd1;
    int wr;
    fd1 = open(ledisplay, O_RDWR | O_NOCTTY | O_NDELAY );
    if (fd1 == -1)
    {
        fprintf(stderr, " %s open_port: Unable to open %s\n", strerror(errno), ledisplay);
    }
    else
    {
        fcntl(fd1, F_SETFL, 0);
        
        wr=write(fd1, msg, size);
        if (wr < 0)
            fputs("write() of n bytes failed!\n", stderr);
        close(fd1);
    }
    return (fd1);
} 
after i read on the serial port:
CPP / C++ / C Code:
int readopen()
{
    printf("read\n");
    int fd1;
    int rd;
    char *buff=NULL;
    fd1 = open(ledisplay, O_RDONLY | O_NOCTTY | O_NDELAY );
    if (fd1 == -1)
    {
        fprintf(stderr, "%s open_port: Unable to open %s\n", strerror(errno), ledisplay); 
    }
    else
    {
        fcntl(fd1, F_SETFL, 0);
        printf(" Port 1 has been sucessfully opened and %d is the file descriptor\n",fd1);
        rd=read(fd1, buff, 30);
        printf(" Bytes recieved are %d \n",rd);
        close(fd1);
    }
    return (fd1);
} 
the string returned by the led display is suppose to be something like:

<nul><nul><nul><nul><nul><soh>"000"<stx>"G234.3432 "<etx>"0237<eot>
the lenght of the returned string is under 30 character...

when i run the prog, the prog display

port série utilisé: /dev/ttyS2
connection au led display
write
read
Port 1 has been sucessfully opened and 3 is the file descriptor
i wait a few second and nothing more is display.... i kill the program

any idea why i don't read correctly on the serial port?
Last edited by LuciWiz : 29-Mar-2005 at 14:57. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 29-Mar-2005, 15:27
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,200
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by collinm
hi

i send a command to a led display, the led display is suppose to return me some character

i write a string on a serial port


when i run the prog, the prog display

port série utilisé: /dev/ttyS2
connection au led display
write
read
Port 1 has been sucessfully opened and 3 is the file descriptor
i wait a few second and nothing more is display.... i kill the program

any idea why i don't read correctly on the serial port?

Is the message getting to the LED? (Can you see anything on the LED?)

Are RS232 handshake signals (RTS-CTS) connected on your serial port?

You can confirm operation of the serial port by connecting a loop-back plug:

Disconnect the external device and insert a plug into the port connector with the following connections:

Connect RXD to TXD, connect RTS to CTS. (I think these are the only ones required, but you can look up all of the connections here for other possible connections.)

Then create a program that writes a short message ("Hello") to that port, and see if the program can read the bytes.

Regards,

Dave
  #3  
Old 30-Mar-2005, 02:42
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
7 requests to use code tags and counting -- that's 47% of your posts. I'm sure Lucien is getting tired of fixing up your posts and leaving messages about this. It's not really that hard -- the information is right at the top of the forum.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
Re: Things to Avoid in C/C++ -- gets() , Part 1 WaltP C Programming Language 5 21-Jun-2007 13:13
Problem with string and serial port collinm C Programming Language 13 25-Mar-2005 08:39
An ActiveX Control does not work in VB, what problem would that be? mingcosp MS Visual C++ / MFC Forum 0 19-Jan-2005 11:04
Using getline to read in data krisbot C Programming Language 4 24-Oct-2004 16:57

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:00.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.