My problem with reading from a modem is still there. I can't figure out why it's behaving like it is. It's very weird.
You see, when you write ATZ to the modem, it should write back OK, but what I'm getting is, ATZ again.
Xach told me that it could be something about ECHO from the modem, but I'm reasonably sure that I turned that off (unless all the docs I read about serial communications are wrong, or I really messed up bad.)
I'll post the part where I'm having the most trouble
disclaimer** This part of the code is very commented 'cause I've been trying out a million differnt things to get it working.
gchar* read_from_modem(gint modem_fd, gint chars_to_read) { gchar b_read_from_modem[255]; gchar *p_read_from_modem; gint bytes_read; //gint chars_read = 0; //#define FALSE 0 //#define TRUE 1volatile int STOP=1;
fcntl(modem_fd, F_SETFL, FNDELAY); p_read_from_modem = b_read_from_modem; /* while((bytes_read = read(modem_fd,p_read_from_modem, b_read_from_modem + sizeof(b_read_from_modem) -p_read_from_modem -1 )) > 0) { p_read_from_modem += bytes_read; if(p_read_from_modem[-1] == '\n' || p_read_from_modem[-1] == '\r') break; }
g_print("\n %c \n", p_read_from_modem); */ while (STOP>=1) { /* loop for input */ bytes_read = read(modem_fd,b_read_from_modem,255); /* returns after 5 chars have been input */ //b_read_from_modem[bytes_read]=0; /* so we can printf... */ //printf(":%s:%d\n", b_read_from_modem, bytes_read); //if (b_read_from_modem[0]=='z') STOP=1; STOP = g_strncasecmp(b_read_from_modem,"ATZ",255); //chars_read++; } printf(":%s:%d\n", b_read_from_modem, bytes_read); fcntl(modem_fd, F_SETFL, 0); p_read_from_modem = b_read_from_modem; return(p_read_from_modem); }
oh, and I'll also add the line that tells the modem not to echo stuff back to me.
modem_options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG );
Yes, I did do a tcsetattr(); after that.
Thanks for reading my diary, hope you enjoy my proplems :P