Could not open port /dev/ttyGSM
damgot opened this issue · 11 comments
Hello,
I try your code for a project where I need to mux my GSM serial line.
When I run cmux, it create 4 tty : ttyGSM1 to 4.
But I can't use them.
With python I do :
import serial
com=serial.Serial('/dev/ttyGSM1',115200)
and I have the following error :
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/site-packages/serial/serialutil.py", line 171, in init
self.open()
File "/usr/lib/python2.7/site-packages/serial/serialposix.py", line 179, in open
raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port /dev/ttyGSM1: [Errno 51] Level 2 halted: '/dev/ttyGSM1'
Do you have any idea ?
Many thanks
Try to reduce or remove sleep()
delay between send_at_command(serial_fd, "CMUX=...")
and ioctl(..., TIOCSETD, ...)
.
Reference: http://www.spinics.net/lists/linux-serial/msg17661.html
Hi, I have run into the same issue as damgot. I also tried konstunn's suggestion which failed (I don't think it would help in my case because my modem must be reset in order to leave cmux mode). I have installed the n_gsm kernel module through modprobe. I run the cmux program and it talks with the modem and places it into cmux mode successfully. The program creates all 4 /dev/ttyGSM*'s. When I run lsmod I can see that n_gsm is now being used by one PID, I run "fuser /dev/ttyMFD1" and I can see the PID of the cmux program, but when I run "fuser /dev/ttyGSM1" there is no PID returned. So it appears cmux is doing everything but failing on the connection to the virtual serial port? Any help with this would be appreciated. Also as a side note, I have tried ldattach.c and run into the same issue where I cannot connect to the /dev/gsmtty1 port.
When I run lsmod I can see that n_gsm is now being used by one PID, I run "fuser /dev/ttyMFD1" and I can see the PID of the cmux program, but when I run "fuser /dev/ttyGSM1" there is no PID returned
That seems to be normal cause I've got everything working in absolutely the same situation, except for that I've got ttyUSB
in place of your ttyMFD
, that's because I use USB-UART bridge.
I have tried ldattach.c and run into the same issue where I cannot connect to the /dev/gsmtty1 port.
I didn't need to try ldattach
. But I also get gsmtty
created after starting cmux
, and gsmtty
have 600 permissions comparing to less strict permissions of ttyGSM
(660, if i'm not mistaken). Check permissions. May be that is the reason why you can't open gsmtty
. I have succeeded to open gsmtty
(with sudo
), send AT
and get OK
in response.
But, honestly speaking, I don't get why gsmtty
is created and what it is created with, but it works. But I prefer using ttyGSM
created with cmux
.
Don't yet have an idea why you also get [Errno 51] Level 2 halted
as @damgot. I got the same message but info referred in my previous comment helped me to solve this.
I have tried reducing the delay as you previously stated and that did not fix the error. When you run "fuser /dev/ttyGSM1" does it return a PID number? Also I am running the program as root so I don't think it is a permissions issue. This is very odd because it appears the program succeeds but I just cannot access the virtual ports.
When you run "fuser /dev/ttyGSM1" does it return a PID number?
No, it does not. And I suppose that's normal.
This is very odd because it appears the program succeeds but I just cannot access the virtual ports.
Yes, it seems to be odd. But I had the same symptom with my problem. - cmux
succeeded but virtual port was not able to be opened. minicom
wrote [Errno 51] Level 2 halted
.
Try to dive into your modem's datasheet and have a look at it's characteristics. And then try to tune the part of the code that contains tcsetattr(serial_fd, TCSANOW, &tio)
, ioctl(serial_fd, GSMIOC_SETCONF, &gsm)
and sprintf(atcommand, "AT+CMUX=0,0,5,%d,10,3,30,10,2\r", MTU)
accordingly. These calls take pretty important parameters as their arguments.
For example, I had another issue of failing pppd pap authentication after I accidentally replaced sprintf(atcommand, "AT+CMUX=0,0,5,%d,10,3,30,10,2\r", MTU)
with sprintf(atcommand, "AT+CMUX=0\r", MTU)
trying to simplify the code. That was my mistake.
Make sure that you catch all errors occured running cmux
. And to open a tty better use minicom
instead of screen
, cause minicom
is more verbose, while screen
keeps silence just printing [screen is terminating]
. Or better yet write a script or a piece of code as a part of cmux
or a separate program that would try to write commands into GSMtty's to test them, i.e. automated test.
same problems...
but i had remove sleep after AT+CMUX, it doesn't work...
I suggest trying to experiment around with the value of that delay. I suppose that even zero value can make sense.
@konstunn i don't know the right number for delay, i can't find this param in SIM7100C's datesheet.
sprintf(atcommand, "AT+CMUX=0,0,5,%d,10,3,30,10,2\r", g_mtu);
if (send_at_command(serial_fd, atcommand) == -1)
errx(EXIT_FAILURE, "Cannot enable modem CMUX");
AND
int send_at_command(int serial_fd, char *command) {
char buf[SIZE_BUF];
int r;
/* write the AT command to the serial line */
if (write(serial_fd, command, strlen(command)) <= 0)
err(EXIT_FAILURE, "Cannot write to %s", g_device);
/* wait a bit to allow the modem to rest */
sleep(1);
I found sleep(1) in send_at_command, so the time between chip got AT+CMUX and when APP set line descripline, at least 1second passed. i don't know is it a problem.
I don't know exactly. Try to alter this one as well and see the result. And let us know, please.
@konstunn
Dear konstunn
i can use it to create ttyGSM and it works fine ,but i dont know how to quit it /.
when the module is reset ,the ttys is still there. i can not create them again
I read the usermanul ,it support disable cmux and remove ttys,but how to do it ?
Pls give me steps to disable cmux and remove ttys , thanks a lot