Reputation: 579
I have a .NET 4 Windows service I've written that periodically (usually once a day) communicates with an external device over a serial port. All in all the service works great, but for one customer, every now and then, a call to SerialPort.Open()
throws the following exception:
System.IO.IOException: Insufficient system resources exist to complete the requested service. at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str) at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace) at System.IO.Ports.SerialPort.Open()
Based on the exception, would would think that the server is running low on resources, but that doesn't seem to be the case. The CPU is more or less idle and there's plenty of memory and disk.
There are lots of mentions online of SerialPort.Open()
throwing other IOExceptions and I have implemented Zach Saw's SerialPortFixer, but it appears it fixes a different issue.
Here's an example of what I'm doing (greatly simplified). A couple of instances of this class (using different serial port names) are in memory at all times and then the Run() method is called approximately once a day for each instance.
public class Collector
{
private SerialPort _port;
private string _portName;
public void Run()
{
try
{
// Run Zach Saw's IOException workaround
SerialPortFixer.Execute(_portName);
using (_port = new SerialPort(_portName, 9600, Parity.None, 8, StopBits.One))
{
_port.DataReceived += PortDataReceived;
_port.ErrorReceived += PortErrorReceived;
_port.Handshake = Handshake.None;
_port.DtrEnable = true;
_port.RtsEnable = true;
_port.Open();
// Do the stuff
_port.Close();
}
}
catch (Exception e)
{
// Handle exception
}
}
private void PortDataReceived(object sender, SerialDataReceivedEventArgs e)
{
// Do other stuff
}
private void PortErrorReceived(object sender, SerialErrorReceivedEventArgs e)
{
// Log error
}
}
Any help would be appreciated.
Upvotes: 5
Views: 7524
Reputation: 1
I had this error and my problem was that the NPort Administration found and programmed the serial ports but the IP4 Address of the network card was set to DHCP. I think this happened during a system update.
Recovery from that:
Upvotes: 0
Reputation: 31
I recently had the same problem, the resolution for me was that I was accidentally using a straight-through DB9 cable with a device that required a null modem DB9 cable. Once I swapped to a null modem cable the error disappeared and the device functioned properly.
When I called Moxa, they suggested some other things to try that might lead to this problem:
Upvotes: 0
Reputation: 1
Had the same problem with NPort 5150. Increasing Network timeout (in NPort Administrator) solved my problem.
Upvotes: 0
Reputation: 579
The answer to this question is that the serial port server used by the client was a wi-fi version (Moxa NPort W2150 Plus) and it turns out the exception occurs when the serial port server has wi-fi connectivity problems.
Upvotes: 3