Segmentation fault

Home Forums MultiConnect OCG Segmentation fault

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2609
    JM K
    Participant

    Hi,

    I am working with an EV2 Radio and cannot utilize the sms-utils package. I am trying to write a small application that accepts a message and sends an sms to a custom phone number also entered by the user.

    I wrote a small C program that would just open the ‘file’, ttyUSB0 and send out an SMS to a phone number using the AT commands. I am however getting a Segmentation fault when I try to open the file ttyUSB0 and write an AT command to it. Here is my program:

    void main()

    {

    FILE *fileptr;

    fileptr = fopen(” /dev/ttyUSB0 ” :,”a”);

    puts(“AT!SSMS=0,xxxxxxxx,0,yyyyyyyyyy”); /* xxxxxxxxx is the phone number and yyyyyyyyy is the message */

    fclose(fileptr);

    }

    I bitbaked it successfully and also copied and installed the package on the CDP Unit. I got a segmentation fault only when I tried running it.

    I would appreciate it, if someone could let me know where my program went wrong. Thank you very much and have a great day.

    Best Regards,

    JM

    #3305
    JM K
    Participant

    Hi,

    I modified my program yet still not able to open the /dev/ttyUSB0 file. Here is a copy of the program:

    # include <stdio.h>

    # incluse <stdlib.h>

    # include <unistd.h>

    # include <getopt.h>

    # include <errno.h>

    # include <sys/types.h>

    # include <sys/stat.h>

    # include <fcntl.h>

    # include <termios.h>

    # include <string.h>

    int main()

    {

    int fileptr;

    fileptr = open (“/dev/ttyUSB0 “, O_RDWR | O_NOCTTY | O_NDELAY);

    fnctl(fileptr, F_SETFL, 0);

    printf(“Port has been successfully opened and the file description is %d “, fileptr);

    close(fileptr);

    return 0

    }

    The output I get when I run this program is:

    Port has been successfully opened and the file description is -1.

    If the file description is -1, the event of opening the file has failed. Is this correct?

    I would very much appreciate it if someone could let me know the error in my program.

    Best Regards,

    JM

    #3306
    Neil McGuire
    Participant

    I personally had issues with the O_NDELAY flag, and once I removed it was able to open the port.

    And yes, if (fileptr == -1) { printf( “Could not open port” }

    It also looks like you have a space after /dev/ttyUSB0 in the open() command. Try removing that.

    #3307
    JM K
    Participant

    Hi Neil,

    thank you very much for your reply. I removed the O_NDELAY flag and also removed the space after /dev/ttyUSB0 in the open command and am still getting the file description as -1. Is it because the port is already open? Is that a possibility? Is there any way to check that? Thanks again.

    Best Regards,

    JM

    #3308
    JM K
    Participant

    Hi Neil,

    Thank you very much. I fixed the problem. The problem was the space before /dev/ttyUSB0. Thanks a lot.

    Regards,

    JM

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.