2
我目前正在使用Delphi Prism for Mono開發。所以,軟件可以跨平臺,主要是在Linux操作系統上運行。要開始,我一直在執行和測試運行我的軟件的基本功能 - 串行和網絡通信。LINUX中的串行通信(RS232)
但我似乎無法通過單聲道的串行通信實施。在搜索Internet和Stackoverflow後,似乎沒有支持Linux環境的庫或.NET框架。儘管Stackoverflow中的其他人提出了一些類似的問題,但答案並未真正顯示任何示例。我有點卡住了。
這是我爲Mono串口通信編寫的代碼。在訪問這個網站之後。
{$IFDEF LINUX}
if SerialPort1 = nil then
SerialPort1 := new System.Io.Ports.SerialPort();
SerialPort1.Close;
SerialPort1.BaudRate:=19200;
SerialPort1.DataBits:=8;
SerialPort1.DtrEnable:=true;
SerialPort1.Parity:=System.IO.Ports.Parity.Even;
SerialPort1.PortName:="/dev/ttyS0";
SerialPort1.ParityReplace:=63;
SerialPort1.ReadBufferSize:=4096;
SerialPort1.ReadTimeout:=1000;
SerialPort1.RtsEnable:=true;
SerialPort1.StopBits:=System.IO.Ports.StopBits.One;
SerialPort1.WriteTimeout:=1000;
SerialPort1.Open;
while (true) do
begin
CommByte[0]:=$FF;
CommByte[1]:=$04;
CommByte[2]:=$04;
CommByte[3]:=thechannel;
CommByte[4]:=mcommand;
CommByte[5]:=(CommByte[2] xor CommByte[3] xor CommByte[4]);
SerialPort1.Write(CommByte,0,6);
while SerialPort1.BytesToWrite>0 do;
Thread.Sleep(10);
Application.DoEvents;
end;
{$ENDIF}
但是每次我在Linux下運行這段代碼時,Mono都會在「未實現請求的功能」時產生一個消息框。我不明白爲什麼。這對Mono來說甚至有可能嗎?
我需要訪問Linux上用於RS232通信的串口。
感謝,
請發佈整個堆棧跟蹤,此代碼應該工作。另外,我是否正確理解你在你的UI線程上使用'SerialPort'('Application.DoEvents'建議這樣做)?如果是的話,那麼請不要這樣做,啓動一個單獨的線程來處理RS232通信。 – skolima
看起來像['ParityReplace'支持可能尚未實現](http://www.mono-project.com/HowToSystemIOPorts)。 – sarnold
我也許有點晚:)但你看過這個圖書館嗎? https://github.com/raspberry-sharp/raspberry-sharp-io –