.NET Serial Port Woes. Converting C# Code to VB - vb.net

I'm having trouble with the SerialPort function intermittently crashing while data logging for several days. It's been a hard problem to debug and I would like to try Zach Saw's fix which he talks about here and provides code for in C#
My question is, to do this, do I need to rewrite the entire use of the Serial Port in my code?
If I use the System.IO.Ports.SerialPort module, is there a way to just do a DLLImport of SetCommState to set fAbortOnError to false, or do I need to abandon the SerialPort module entirely and write everything using the kernel32.dll?

I'm pretty sure in this case you could import his project into your solution, and it should run just fine. Since VB and C# are both CLR languages, they both compile down to the same intermediate language.

Check out this page
http://support.microsoft.com/kb/823179
It's got the proper declarations for SetCommState, with some example code. Zach's fix is to basically open the com port as a file first, call setcommstate, then use the serial io functions in .net. I haven't tried it but his post sounds like you shouldn't have to do much at all to your code.

Having tested about 15 different solutions to the various problems with serial ports in .NET, I settled on using CommStudio. It's been rock solid ever since.
You can get CommStudio Express (their free version) here: http://www.componentsource.com/products/commstudio/downloads.html?rv=42917

Related

UPnP in visual basic: Does is still work?

tl;dr - I'm attempting to open internal and external port 4305 to my local address at 192.168.1.103 through UPnP with Visual Basic code.
I've been searching for the better part of 20 hours looking for a way to open these ports on my router through UPnP code for VB. So far, nothing has enabled me to trigger a port through VB. To keep a long story short, I've attempted about 4.3 different options with varying success. These are:
Microsoft's Interop/COM NATUPnP Library (https://learn.microsoft.com/en-gb/previous-versions/windows/desktop/ics/network-address-translation-traversal-interfaces)
NetworkLight_VB (An old program I hoped I could use for reference, http://www.thijsschreijer.nl/blog/?p=450)
ManagedUPnP Library (This is the .3, I spent little time exploring this lib as it's C#, but still think it's worth mentioning, https://archive.codeplex.com/?p=managedupnp)
UPnPc/MiniUPnPc (http://miniupnp.free.fr/)
Portmapper (https://github.com/kaklakariada/portmapper)
NATUPnP 1.0 Type Library
Having a little prior knowledge with Interop services through excel based programs, this seemed like a pretty good solution, however it didn't get very far as the COM object NATUPNPLib.IStaticPortMappingCollection would always return as nothing. I imagine this would be due to NATUPNPLib.UPnPNAT also returning empty, despite Visual Studio showing it as an initialised COM object. With little info or guidance other than "Your UPnP is probably off" (It wasn't) I decided to see if there was another way, and moved on.
NetworkLight_VB
In an attempt to look for working examples of UPnP triggering through VB I quickly realised that this isn't a very hot topic and has barely been talked about in years, with this program being no exception. Opening the program it seemed to run fine, though I had no indication of it actually working as intended, with my router showing no UPnP activity on the port it was trying to hit. I believe there's still potential here with the library being used, but I'm not sure how to utilise it properly or reference it within my own program.
ManagedUPnP Library
This is the same as with the UPnP library used by the NetworkLight_VB program; not sure how to use it. (Being entirely self taught, my knowledge foundations are shaky at best. The only references I've used successfully are through Visual Studios 'add reference' option like with the NATUPnP Interop service)
UPnPc/MiniUPnPc
This showed a lot of promise as a potential workaround, allowing the use of a stealth CMD window to do the dirty work, but this also failed. The worst part is that I have no idea why. Running it seemed to work without issue, and it echoed a success in triggering UPnP, however my router told me otherwise. Checking the UPnP list showed no open port, and any attempt to communicate between my host and client programs failed.
By this point I was ready to just give up and port forward manually. Surely, if everything I was trying kept failing then there must be something wrong with my setup, computer, something that was misbehaving. But I gave it one more shot.
Portmapper
This nifty little java program worked like a charm. I entered the info, checked my router wizard and, lo and behold, there was the port sitting open and ready. Testing my client and host programs, I confirmed that it was working exactly the way I wanted it to. There was just one problem: getting it into my program. Browsing the author's website I found that it did in fact have a command line interface with examples, though my pitiful (and very tired) attempts to use that CLI didn't work. This shouldn't be too hard to work out though.
What does bother me however is that it needs Java installed on the computer to run, and since this is a peer-to-peer based program, replacing 'asking a user to port forward' with 'asking a user to install Java' is undesirable (Though, if all else fails, then so be it. Pressing install is far easier than navigating a router gateway wizard).
Ideally I would like to have the NATUPnP Interop service or any of the libraries work so that I'm not running code outside of the main program, but I really want this to work so anything that does is probably what I'll use.
Any guides on how to use the libraries, examples of working programs or suggestions on alternative methods is very much appreciated.

Zip Function Within Visual Studio

I've poked around looking for a zip function from with Visual Studio but haven't found anything.
Is there a function? Reason I'm asking, is I'm currently creating a process within my code to call 7zip, but this program isn't installed on all user machines and installing the program is an option, just not an ideal option.
Suggestions?
Try the System.IO.Compression library that comes with C#:
ZipFile Class
I have used dotnetzip.codeplex.com with very good results. There is definitely some coding and qa work to do to ensure it's handling your data correctly. But you're quite right that it's easier to deploy to random client machines than calling out to 7zip.

VB.NET 1.1 Winsock Replacement

I'm trying to update an application from vb6 to vb.net. The orig app used the winsock control. Unfortunately I can't nor do I want to use it in the re-write. Are there any decent public classes with events that wrap the Socket class? I've found a few on google but all were buggy and I think it may be a little over my head to write my own from scratch.
Sockets are built in now: http://msdn.microsoft.com/en-us/library/system.net.sockets(VS.71).aspx
If you are doing web related tasks then you should look at System.Net.WebClient or System.Net.HttpWebRequest.

Zune API ZuneCore.dll

I noticed the other day that the Zune PC Software exposes a type library (ZuneCore.dll). It seems to be related to the WMPLib API in some way but I can't figure out how to use it either from VB6 or C#.
Has anybody tried this and had any luck?
Dave
May be an old question, but this link might help: http://zunelcd.codeplex.com/ If you download the source for this project one of the class libraries is a decent API for communicating with the Zune Software.
i just found out about this -> http://soapitstop.com/blogs/fleamarket/archive/2008/03/03/read-the-zune-collection-in-net-from-zune-s-own-api.aspx but it seems a bit outdated Initialize method now takes some parameters and i dont know what to put there!
Try adding a reference to it from a .NET project in Visual Studio. Perhaps this namespace will appear magically: MicrosoftZuneLibrary

Need to convert C# to VB.NET

I have some C# source code that I got off the Internet and I want it in VB.NET. How would you convert it because I don't know C#.
I found multiple translators after performing a simple search, but this one looks kind of cool. No installation necessary!... though I have never used it.
Another way is compiling it to, dragging the assembly to Reflector and then decompiling it to VB.NET
If I recall correctly, you can have multiple source languages in the same project. They just have to be in different files. You should be able to call the c# class from a vb.net class without any major problems. This may not be the prettiest option, but it might work for your situation.
You can have a VB project in the same solution as a C# project, and use classes from either from the other, but you can't have both VB and C# source files compiled in the same project.