Glenn Visca

Hi,

I have an application that intermittently returns a NullReferenceException to the SerialPort1.Isopen() function.

I have worked around the issue for the moment by including a Try/Catch block, but I would like to understand why it happens in the first place.




Re: Visual Basic Express Edition Serial Port ISOPEN() Returning NullReferenceException

Carsten Kanstrup

Seems like you call SerialPort1.IsOpen at a time when SerialPort1 is not declared. Do you close the port and then open it immediately after (no intermediate delay)





Re: Visual Basic Express Edition Serial Port ISOPEN() Returning NullReferenceException

Martin Xie - MSFT

Hi Glenn,

Welcome to MSDN forums!

It's likely to get better responses if you post your code.

Carsten has rich experience in serial communication.

References: Serial COM port communication in Visual Basic .NET

http://www.innovatic.dk/knowledg/SerialCOM/SerialCOM.htm

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=141201&SiteID=1

Regards,

Martin






Re: Visual Basic Express Edition Serial Port ISOPEN() Returning NullReferenceException

Carsten Kanstrup

Martin Xie

In my description (your first link) I have tried to collect all my present knowledge about the serial port together with some background knowledge, which is necessary to use the serial port in a multi threaded environment, like forms and controls, messages, events, delegates, control.Invoke/beginInvoke etc. I have tried to write it in a language, which even beginners should have a chance of understanding, but still keep it technical correct. However, it is extremely difficult to get any good below-the-hood information about .NET and Windows, so there are still some loose ends, which I need to tie up, and there may still be some points, which are not correct. If you should once get a lot of spare time , please read it through and let me know if there are any errors or you have any suggestions or anything else to contribute. All comments are very welcome. You can find my e-mail address on the front page of our homepage.

Best regards,

Innovatic

Carsten Kanstrup





Re: Visual Basic Express Edition Serial Port ISOPEN() Returning NullReferenceException

Martin Xie - MSFT

Hi Carsten,

Your document about Serial COM Port Communication is very beneficial.

I find your E-mail: mail@innovatic.dk on your Innovatic homepage and keep it in mind.

It's a pleasure to keep in touch with you.

Best regards,

Martin