Segmentation fault
Home › Forums › MultiConnect OCG › Segmentation fault
- This topic has 4 replies, 2 voices, and was last updated 13 years, 3 months ago by JM K.
-
AuthorPosts
-
August 9, 2011 at 5:32 pm #2609JM KParticipant
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
August 10, 2011 at 8:30 pm #3305JM KParticipantHi,
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
August 11, 2011 at 5:16 pm #3306Neil McGuireParticipantI 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.
August 11, 2011 at 5:53 pm #3307JM KParticipantHi 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
August 11, 2011 at 6:11 pm #3308JM KParticipantHi Neil,
Thank you very much. I fixed the problem. The problem was the space before /dev/ttyUSB0. Thanks a lot.
Regards,
JM
-
AuthorPosts
- You must be logged in to reply to this topic.