2
votes

I have a C#.NET web app that runs in IIS 7 on Server 2008 R2, .NET v4, MVC 3, SQL Server 2012. The app works on a bunch of machines already, but we've just got a new computer and the behaviour on this machine is slightly different.

In particular, when the app opens the System.IO.Ports.SerialPort and writes, no data is actually transmitted on COM1. No exception seems to be thrown either. The app goes on to wait for a response, and times out.

If I close my app, and use Termite (a terminal program) to check that the COM port is working, data comes out the serial port just fine. So the serial port, drivers, etc seem to be ok.

If I have Termite connected to COM1 when my app tries to open the port, I get an Access Denied exception (as I expect). So my application does seem to be trying to access the correct port.

But if there's nothing else using COM1, my application gets no exceptions - but nothing comes out the serial port.

Does anyone have any suggestions about how to debug this situation?

1
It is a bit unusual that a Web app access the low level IO like COM 1 directly particular which is serial, serving concurrent requests. Would you clarify the identity of running the Web app (the identity of running the app pool)? and have you checked the Windows events of the host machine?ZZZ
The hardware is the same ? no special settings are required for this COM? is it real com or virtual com ?ilansch
Thanks AndyH and ilansch. The new machine does have different hardware. The app pool is "ASP.NET v4.0". My application has one thread which obtains data from an instrument and populates a database. Other (web service) threads can retrieve the data and also manage the data acquisition thread.John

1 Answers

2
votes

I had the same problem - C# SerialPort couldn't connect to my serial device but Termite could despite following the device manual.

I compared the SerialPort properties with my Termite settings and found that there's some terminology difference between the two. For example, Termite has an option for "DTR/DTS" (which I needed) while SerialPort doesn't have anything called "DTS". Setting these properties of the SerialPort object worked for me:

DtrEnable = true; 
RtsEnable = true;