From: Alex Mang on
So I'm using Compact Framework 2.0 on a WinCE 6.0 R3 embedded device, and I
have the following problem:
When I try opening any COM port on the devices, i get an IOException
(obviously, there is no message on the exception). However, the most
interesting (as in odd) thing is that putting the .Open method alone in a
try/catch, I was able to use the .Write method on the serialPort object AND
connecting a display to the COM port, I could see that:
1. the port was open
2. i can write on the port crrectly

Did anyone ever had such a problem?
The oddest thing is that the exact same application works perfectly on
another image, same devices (indeed, as far as i remember, the other image is
a R2 image!).

Best regards,
Alex
From: Paul G. Tobey [eMVP] paultobey _at_ earthlink _dot_ on
Your explanation doesn't really give much to go on, but my guess is that you
tried to open the port twice. The second time fails, but the port is still
open because you opened it the first time, so reads and writes work fine.

Paul T.

"Alex Mang" wrote:

> So I'm using Compact Framework 2.0 on a WinCE 6.0 R3 embedded device, and I
> have the following problem:
> When I try opening any COM port on the devices, i get an IOException
> (obviously, there is no message on the exception). However, the most
> interesting (as in odd) thing is that putting the .Open method alone in a
> try/catch, I was able to use the .Write method on the serialPort object AND
> connecting a display to the COM port, I could see that:
> 1. the port was open
> 2. i can write on the port crrectly
>
> Did anyone ever had such a problem?
> The oddest thing is that the exact same application works perfectly on
> another image, same devices (indeed, as far as i remember, the other image is
> a R2 image!).
>
> Best regards,
> Alex
From: Alex Mang on
Sorry, but I can only strongly disagree.

If you'd like, I could even share a code snippet of the app, since it's a
test app only.
Anyway, to sum everything up, the code is something like:
1. void Form_Load(object sender, EventArgs e)
2. {
3. serialPort.Open();
4. serialPort.WriteLine("test");
5. serialPort.Close();
6. }

The code above, would raise the IOException. However, if i write the
following code instead, everuthing works fine (which is odd).

1. void Form_Load(object sender, EventArgs e)
2. {
3. try{
4. serialPort.Open();
5. }catch{}
6. serialPort.WriteLine("test");
7. serialPort.Close();
8. }

Again, I repeat from the last thread: the application works perfectly on an
older R2 image (so there is no extra-opening on the port; otherwise, the app
wouldn't work on the second image either). Surely, there are several
differences between the two images I'm nentioning. But my question is wether
I am forgetting a component, or maybe an environment variable?

"Paul G. Tobey [eMVP]" wrote:

> Your explanation doesn't really give much to go on, but my guess is that you
> tried to open the port twice. The second time fails, but the port is still
> open because you opened it the first time, so reads and writes work fine.
>
> Paul T.
>
> "Alex Mang" wrote:
>
> > So I'm using Compact Framework 2.0 on a WinCE 6.0 R3 embedded device, and I
> > have the following problem:
> > When I try opening any COM port on the devices, i get an IOException
> > (obviously, there is no message on the exception). However, the most
> > interesting (as in odd) thing is that putting the .Open method alone in a
> > try/catch, I was able to use the .Write method on the serialPort object AND
> > connecting a display to the COM port, I could see that:
> > 1. the port was open
> > 2. i can write on the port crrectly
> >
> > Did anyone ever had such a problem?
> > The oddest thing is that the exact same application works perfectly on
> > another image, same devices (indeed, as far as i remember, the other image is
> > a R2 image!).
> >
> > Best regards,
> > Alex
From: Paul G. Tobey [eMVP] paultobey _at_ earthlink _dot_ on
No, you're not forgetting an environment variable. The code is a much better
way to show what's going on. We need to see the contents of the exception
that you are, presumably, catching in the second case shown. So, don't just
do:

catch {}

actually catch it and examine it in the debugger. At worst, you should be
able to get an HResult that corresponds to what the exception is trying to
tell you went wrong. That should be a good hint.

It's possible that you've built things wrong in some way, of course, but I
think that it's more-likely to be some improvement in the error checking of
framework or some change in the serial driver behavior causing the problem.
You're doing this with a *very* simple set of serial port parameters? 9600,
n, 8, 1, no handshake, no time-outs?

Paul T.

"Alex Mang" wrote:

> Sorry, but I can only strongly disagree.
>
> If you'd like, I could even share a code snippet of the app, since it's a
> test app only.
> Anyway, to sum everything up, the code is something like:
> 1. void Form_Load(object sender, EventArgs e)
> 2. {
> 3. serialPort.Open();
> 4. serialPort.WriteLine("test");
> 5. serialPort.Close();
> 6. }
>
> The code above, would raise the IOException. However, if i write the
> following code instead, everuthing works fine (which is odd).
>
> 1. void Form_Load(object sender, EventArgs e)
> 2. {
> 3. try{
> 4. serialPort.Open();
> 5. }catch{}
> 6. serialPort.WriteLine("test");
> 7. serialPort.Close();
> 8. }
>
> Again, I repeat from the last thread: the application works perfectly on an
> older R2 image (so there is no extra-opening on the port; otherwise, the app
> wouldn't work on the second image either). Surely, there are several
> differences between the two images I'm nentioning. But my question is wether
> I am forgetting a component, or maybe an environment variable?
>
> "Paul G. Tobey [eMVP]" wrote:
>
> > Your explanation doesn't really give much to go on, but my guess is that you
> > tried to open the port twice. The second time fails, but the port is still
> > open because you opened it the first time, so reads and writes work fine.
> >
> > Paul T.
> >
> > "Alex Mang" wrote:
> >
> > > So I'm using Compact Framework 2.0 on a WinCE 6.0 R3 embedded device, and I
> > > have the following problem:
> > > When I try opening any COM port on the devices, i get an IOException
> > > (obviously, there is no message on the exception). However, the most
> > > interesting (as in odd) thing is that putting the .Open method alone in a
> > > try/catch, I was able to use the .Write method on the serialPort object AND
> > > connecting a display to the COM port, I could see that:
> > > 1. the port was open
> > > 2. i can write on the port crrectly
> > >
> > > Did anyone ever had such a problem?
> > > The oddest thing is that the exact same application works perfectly on
> > > another image, same devices (indeed, as far as i remember, the other image is
> > > a R2 image!).
> > >
> > > Best regards,
> > > Alex
From: Alex Mang on
This is the way I'm initializing the serial port object (actually, calling
the constrctor):
System.IO.Ports.SerialPort _sp = new System.IO.Ports.SerialPort("COM", 9600,
System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);

I did have a Exception class in the catch defined, but as stated previously,
there is very little information on the IOException (almost nothing on the
stacktrace - e.g.: even the message is IOException). I don't recall wether it
had a HResult inf. Once I'll get back home, I'll check it again.

Thanks for your support!

If anyone had a similar problem before, please don't hesitate to let me know!

"Paul G. Tobey [eMVP]" wrote:

> No, you're not forgetting an environment variable. The code is a much better
> way to show what's going on. We need to see the contents of the exception
> that you are, presumably, catching in the second case shown. So, don't just
> do:
>
> catch {}
>
> actually catch it and examine it in the debugger. At worst, you should be
> able to get an HResult that corresponds to what the exception is trying to
> tell you went wrong. That should be a good hint.
>
> It's possible that you've built things wrong in some way, of course, but I
> think that it's more-likely to be some improvement in the error checking of
> framework or some change in the serial driver behavior causing the problem.
> You're doing this with a *very* simple set of serial port parameters? 9600,
> n, 8, 1, no handshake, no time-outs?
>
> Paul T.
>
> "Alex Mang" wrote:
>
> > Sorry, but I can only strongly disagree.
> >
> > If you'd like, I could even share a code snippet of the app, since it's a
> > test app only.
> > Anyway, to sum everything up, the code is something like:
> > 1. void Form_Load(object sender, EventArgs e)
> > 2. {
> > 3. serialPort.Open();
> > 4. serialPort.WriteLine("test");
> > 5. serialPort.Close();
> > 6. }
> >
> > The code above, would raise the IOException. However, if i write the
> > following code instead, everuthing works fine (which is odd).
> >
> > 1. void Form_Load(object sender, EventArgs e)
> > 2. {
> > 3. try{
> > 4. serialPort.Open();
> > 5. }catch{}
> > 6. serialPort.WriteLine("test");
> > 7. serialPort.Close();
> > 8. }
> >
> > Again, I repeat from the last thread: the application works perfectly on an
> > older R2 image (so there is no extra-opening on the port; otherwise, the app
> > wouldn't work on the second image either). Surely, there are several
> > differences between the two images I'm nentioning. But my question is wether
> > I am forgetting a component, or maybe an environment variable?
> >
> > "Paul G. Tobey [eMVP]" wrote:
> >
> > > Your explanation doesn't really give much to go on, but my guess is that you
> > > tried to open the port twice. The second time fails, but the port is still
> > > open because you opened it the first time, so reads and writes work fine.
> > >
> > > Paul T.
> > >
> > > "Alex Mang" wrote:
> > >
> > > > So I'm using Compact Framework 2.0 on a WinCE 6.0 R3 embedded device, and I
> > > > have the following problem:
> > > > When I try opening any COM port on the devices, i get an IOException
> > > > (obviously, there is no message on the exception). However, the most
> > > > interesting (as in odd) thing is that putting the .Open method alone in a
> > > > try/catch, I was able to use the .Write method on the serialPort object AND
> > > > connecting a display to the COM port, I could see that:
> > > > 1. the port was open
> > > > 2. i can write on the port crrectly
> > > >
> > > > Did anyone ever had such a problem?
> > > > The oddest thing is that the exact same application works perfectly on
> > > > another image, same devices (indeed, as far as i remember, the other image is
> > > > a R2 image!).
> > > >
> > > > Best regards,
> > > > Alex