Question

I need to interface a device via RS232 at 115200 bps. The distance is very short (less than a meter). No hardware or software handshaking. Messages exchanged are also short: 10 - 50 bytes. The frequency of message exchange - max 10 per second.

I used to reliably handle comms in such environment in C/C++ using corresponding Win APIs. However, this time I'd like to do it in .NET/C#.

Some time ago I came across an article dealing with .NET serial port. From what I recall, the author did not recommend using SerialPort class. Instead he opted for unmanaged Win APIs from a managed code. I'm not sure if the article referred to .NET 1.1.

Does anybody know if going managed with SerialPort is a safe bet?

Was it helpful?

Solution

SerialPort works fine. It arguably could have been implemented better, but 10 messages per second of 50 bytes each at 115k is a trivial workload for a modern PC (for comparison bear in mind that PCs are capable of receiving data off a 10Gigabit Ethernet link). Under the bonnet, the OS/driver buffers the data, so whether you read that buffer from C++ or C# won't make much (if any) difference.

SerialPort doesn't work well with USB serial ports.... but that's because USB is notoriously unreliable. Plug in a PCI serial card or connect over ethernet to a Terminal server and SerialPort works fine. Use the USB-to-RS232 converter from a C++ program and the failures return. Draw your own conclusions...

We run systems with 18 serial ports running at various speeds (several at 115k and 10hz, packets of several hundred bytes), and have never had any problems with SerialPort (only with USB-to-RS232 converters!)

Give it a try... it shouldn't take long to prototype...

OTHER TIPS

It's worth noting that the important point here is not whether the code or the computer are ok to work at 115kbps, but rather whether your cables, the serial hardware, the external device, and the environment are ok to work at those speeds.

If you are in an electrically quiet location with good, shielded cable over a short run then you're probably fine. If you are working near high-powered industrial machines that generate a lot of electrical noise and have shoddy cables then you most certainly will not be fine. I have definitely experienced problems in electrically noisy industrial environments with high speed RS-232 communications. In these cases it has been necessary to use high quality cables and to reduce the transfer rate until the communication becomes stable and error-free. If this is a concern, there is nothing to do but test it yourself and see.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top