Since communication on the serial port is asynchronous, I first understood my project related to communication with the RS 232 device, that I would have to have a background thread constantly reading the port for the received data. Now I'm using IronPython (.NET 4.0), so I have access to the smooth SerialPort class built into .NET. This allows me to write code as follows:
self.port = System.IO.Ports.SerialPort('COM1', 9600, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One)
self.port.Open()
reading = self.port.ReadExisting()
Simple enough. But, as I said, I want to constantly check this port for new data as it arrives. Ideally, I would like the OS to tell me when the data will be waiting. Whaddaya know, my prayers were answered, there is an event DataReceived!
self.port.DataReceived += self.OnDataReceived
def OnDataReceived(self, sender, event):
reading = self.port.ReadExisting()
...
, , !!
DataReceived .
, . BackgroundWorker, port.ReadExisting() . , , (\r\n), , linebuffer. linebuffer, , - , .
, -, . - BackgroundWorker, linebuffer. , linebuffer.
. linebuffer, , ; . , , ? , linebuffer, concurrency.
, / , !