今天在windows下連接ublox接收機接收數據,無論是ucenter,串口調試工具還是rtklib實時定位,都能夠接收數據,但是利用rtklib源碼解算卻不行,錯誤定位在不能打開串口。今晚又在linux下調試,命令行下通過 cat /dev/[port]
可以正常接收數據,但是通過下面的程序仍舊無法打開串口:
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
int main()
{
int solu;
char msg[128];
char dev[128]= "/dev/ttyACM0";
if ((solu=open(dev,O_RDWR|O_NOCTTY|O_NONBLOCK))<0) {
sprintf(msg,"%s open error (%d)",dev,errno);
printf("%s\n",msg);
return 0;
}
else
printf("opened\n;");
return 0;
}
對上述程序在終端編譯執行:
$ gcc main.c -o main
$ ./main
返回錯誤:
/dev/ttyACM0 open error (13)
突然想到通過 cat /dev/[port]
查看端口輸出需要root權限,於是使用root權限運行:
$ sudo ./main
結果:
opened
所以想到windows下是不是也是這個原因,但是從來沒在windows下有過這種情況!好吧這是明天的事了!
在此默默感謝一下毫無保留幫助我的朋友!
2019.04.06
補充:
rtklib在windows下打不開串口的問題,經過測試,如果把串口改成寬字符,就可以打開:
dev = CreateFile(L"COM7", rw, 0, 0, OPEN_EXISTING, 0, NULL);
或者在rtklib工程屬性 -> 配置屬性 -> 常規 -> 字符集 ,改爲使用多字節字符集