我正在進行pc(ubuntu)和嵌入式linux(2.6.24)板之間的串行通信。串行通訊本身似乎可以工作(我使用的是從http://serialib.free.fr/html/index.html開始的Serialib),但是每當我的應用程序停止收聽板上調用的/ etc/profile文件時(這種情況不會發生,因爲不使用串口的應用程序) 。串行通信重置/ etc/profile(linux)
要知道,當我在主板上啓動應用程序時,我在PC上打開一個gtkterm以跟隨板子的終端(也使用串口),我認爲這是罪魁禍首/ etc/profile的重置,但我不確定。
我的閱讀應用
#include <stdio.h>
#include "serialib.h"
#include <QCoreApplication>
#include <QSettings>
#include <QProcess>
#include <iostream>
#if defined (_WIN32) || defined(_WIN64)
#define DEVICE_PORT "COM1" // COM1 for windows
#endif
#ifdef __linux__
#define DEVICE_PORT "/dev/ttyS0" // ttyS0 for linux
#endif
int main()
{
serialib LS; // Object of the serialib class
int Ret,res; // Used for return values
char Buffer[128];
// Open serial port
Ret=LS.Open(DEVICE_PORT,115200); // Open serial link at 115200 bauds
if (Ret!=1) { // If an error occured...
printf ("Error while opening port. Permission problem ?\n"); // ... display a message ...
return Ret; // ... quit the application
}
printf ("Serial port opened successfully !\n");
// Read a string from the serial device
Ret=LS.ReadString(Buffer,'\n',128,5000); // Read a maximum of 128 characters with a timeout of 5 seconds
// The final character of the string must be a line feed ('\n')
if (Ret>0) // If a string has been read from, print the string
printf ("String read from serial port : %s",Buffer);
else
printf ("TimeOut reached. No data received !\n"); // If not, print a message.
// Close the connection with the device
LS.Close();
return 0;
}
我送「TEXT \ n」來串聯,而在超時的極限,我有代碼「字符串從串口讀取:TEXT」在終端上出現在gtkterm中複製,然後按「運行etc/profile」。就像我之前說過的,我懷疑我在使用帶有gtkterm的串口的同時,我發送了字符串,但是我必須讓它使用該板,並且我希望您對此問題有意見。
謝謝你的未來答案。
我似乎沒有在該端口上運行的程序,我的inittab如下所示::: sysinit:/ etc/init.d/rcS :: respawn: -/bin/sh tty2 :: askfirst: -/bin/sh tty3 :: askfirst: -/bin/sh tty4 :: askfirst: -/bin/SH ::重啓:/ sbin目錄/初始化 :: ctrlaltdel:/ sbin目錄/重啓 ::關機:/斌/卸除-a -r ::關機:/ sbin目錄/使用swapoff -a – Wowy
@Wowy:是在你的Ubuntu開發盒或目標系統上? –
這個inittab來自目標系統(一個閱讀) – Wowy