I for years I have used MSCOMM32.OCX to handle serial port comm in vb6. Is this the "proper" way to handle the serial port in .net or is there another better way?
thanks
kevin
Printable View
I for years I have used MSCOMM32.OCX to handle serial port comm in vb6. Is this the "proper" way to handle the serial port in .net or is there another better way?
thanks
kevin
Check out this thread . I posted a link to the .NET way of doing so :
http://www.vbforums.com/showthread.p...hreadid=305829
thanks Pirate, but I must say that it appears that using the comm port just got a bit more difficult. I have a few questions---this is how you open the comm port. Can I define the behavior of the port during an init segment of code and omit the arguements?VB Code:
m_CommPort.Open(m_ModemPort, 115200, 8, Rs232.DataParity.Parity_None, Rs232.DataStopBit.StopBit_1, 4096)Do I alway need to specify the encoding? or can I set it to default ASCII?VB Code:
m_CommPort.Write(Encoding.ASCII.GetBytes(Me.txtUserCommand.Text & Chr(13)))
what is the purpose of the Thread.Sleep statement?VB Code:
m_CommPort.Write(Encoding.ASCII.GetBytes("AT" & Chr(13))) ' Sleep long enough for the modem to respond and the timer to fire. System.Threading.Thread.Sleep(200) '<=== Application.DoEvents() m_CommPort.Close()
finally--- Is it really that bad to stick with MSCOMM32.OCX?
thanks
kevin
Sorry dude,I've never done something like this before . Just tried to help even with a link .:)
its cool, thanks.....anyone else?
Sunday Morning bump.......
Monday morning :cry: bump....
Hi
Each form as a thread responsible for updating your form GUI, using System.Threading.Thread.Sleep(200) will make that thread sleep for 200ms and you will notice that the GUI stops responding during that time.
Regards
Jorge
thanks Jorge,
that takes care of one question, but I think the rest of them are irrelevant if the last can be answered with a no----Is it so bad using VB6 ocx's such as MSCOMM32.ocx in .net? What are the implications of using VB6 control in .net?
thanks
kevin
Hi
When you add a vb6 control to your .net project it will create a wrapper dll starting with interop.yourcontrolname.dll on your \bin directory, so there disk space wasted and performance hit, Interop is very slow compared to .net .
Regards
Jorge
thanks....I guess I learn the .net way of doing it.
kevin
Ok that's much better . But I just want to add my 2cents . Using interop VB6 with .NET isn't like so bad but it's always not recommended .Simply because the overhead it causes , delay of execution , not 100% handled by the CLR environment and most of all , the data types are quite different .For example , Long in VB6 is Integer in .NET , Any or Variant is Object in .NET .
There was a thread I found that I think was started by Wossname about serial ports in .NET. A links were provided to at least three places that had free downloads of .NET serial port wrapper classes. I studied two of them, and ended up using one of them in my own project (with modifications)
Unfortunately, I haven't been able to find those links again. However, I do have the downloads lying around here somewhere if you'd like them.
Yes please send themQuote:
Originally Posted by Shaggy Hiker
thanks
kevin
Here are 3 files (I hope, I've never actually attached a file to one of these posts before). The two zip files are the free downloads from places probably included in text files in the zips. They are small projects that test a core RS232 wrapper class (a different class in each project, not the same class).
I forget which one I included in the RS232.vb file, and I forget whether or not I made any modifications to the file, but the one I chose was simple to use, and could readily be plugged into my application.
thanks :thumb:
kevin