Vb Dcc

ModelRailroadForums.com is a free Model Railroad Discussion Forum and photo gallery. We cover all scales and sizes of model railroads. Online since 2002, it's one of the oldest and largest model railroad forums on the web. Whether you're a master model railroader or just getting started, you'll find something of interest here.


Hello. I have been running Digitrax for about three years now, and want to make the experience better. I was wondering if anyone knows how to use Microsoft's VB.NET language to do DCC control on the loconet system. My plan is to get other people involved in an unmonitored enviroment. I set up a small layout at my school for Christmas, and thought if people could actually run a train, that would make their experience better. This way, I can set speed limits and make a graphic enviroment which is easier than a DT400 throtle for the average person. Also, with the aid of some microcontrolers, I could get more than one train running unattended and let the computer do the switching. I want to use VB because it is easy and there is an IDE which creates controls for you, but I am not opposed to other languages. Anyone else have any thoughts? Thanks
 
Have you considered JMRI? It's java based, and quite expandable, that would form a foundation with which to build off of. If you use stationary decoders for your switching, it will control that as well without the need for microcontrollers.
 


This may not be exactly what you are looking for, but I have written a VB6 control program that is the entire system and interface - it uses the serial port which connects directly to a booster. The booster is homebrew as well - uses motor control MOSFET ICs. The program does everything and utilizes a homebrew RF wireless controller or on screen controls for operation.

See this thread, down around post #32. It has actually been updated extensively since those posts.

Is this what you are after or are you looking to connect to an existing DCC system?

Mark
 
Your VB6 project looks more like what I was looking for. I have a Digitrax DCS50 and a DT400 wireless throtle. I wanted to just use my booster since I already have it. If your's is simple (and cheap to build), I am not opposed to the idea of building a new one, though. Instead of you wireless controler, though, check out Microsoft's coding 4 fun site. Someone wrote a dll library to use a Wii controler with VB.NET. Turns out they use Bluetooth to communicate with the base station. I'm not sure it would work any better, but it would be interesting. Sorry, but Java is the one language I really struggle with. Maybe I will try again, though. The point of the microcontrolers is that I already have them. I am on a very low budget here. Plus, I can easily use them as block detectors.
 
I have Visual BASIC 2003 (.NET) and struggled with learning it while still using VB6 on current projects, so I stuck with VB6. None of my stuff gets distributed so I don't have to worry about compatibility with other OSs.

That wireless controller uses a software interface too - it is a PS2 controller that interfaces to one of the LPT ports and works very well. 10 bucks for the controller, maybe 15 bucks for the other parts, free software interface - that works for me! :) Budget is a big thing with me too - the old PIII computer is fast enough and the rest I built.

Mark
 
I have several old machines, including one that runs on ProDOS or DOS 3.3. I thought I might try that two if I ever do a public display. It is an Apple IIe, so I don't think anyone would want to steal it. My big issue is the hardware interface and what messages come back (if any). From playing with Parallax's stamp, I learned to use a serial port in VB.NET. I can also use them with Applesoft (BASIC w/ floating point capabilities). If you could tell me anything about that or if you have a schmatic, that would be very helpful. I found some stuff, but they require some IC's that I thnk might be obsolete, and a PIC microcontroler (not a bad thing, but I am not sure they posted the programs). Digitrax put all their specs for their network at this site. http://www.digitrax.com/ftp/loconetpersonaledition.pdf. If I understand correctly, then two of the six wires can be used for track singal and are sent to all boosters, so all I really need is a buffer to get signals from the computer to the track signal. There is my big problem.


I decided to read Digitrax's stuff again as it has been a while since I read it last. As it turns out, a computer's serial port can talk directly to the network if baud rates are set correctly. Still not sure it will work yet, and any pointers would be great.
 
Last edited by a moderator:
Warning - long post ahead. :)

My DCC coding rig is actually quite simple - I use a 18200 IC booster (go here, click on MiniBooster at the bottom) from the MiniDCC system. It is a motor control IC, and pin 3 is connected directly to the output of the serial port. It actually doesn't matter if it is a fully compliant serial port you are using (ie a mainboard port or a USB dongle port) since it doesn't need TTL conversion. What makes it work so well is that pin is actually the motor direction pin - the IC is set to send full voltage output and when the serial port goes high to low (or low to high) it simply reverses polarity on the IC. This is perfect for DCC as it cleans and squares off the signal automatically. No other circuit could do this as efficently and easily.

As for the signal to the track, this took a lot of reading and understanding of how a DCC data string is put together. The NMRA standards documents helped a lot with this. Essentially a "one" on the rails is a short low/high, and a "zero" is a long low/high. The timing of the "one" is crutial, the "zero" can vary in length greatly. A serial port set to 19200 is close enough to the timing standard so that a 0 and 1 sent together on the serial port is read by the loco as a 1, and two or more 0s and two or more 1s sent together is read as a zero. The trick is configuring the 8 bit serial port (with leading and trailing bits) to send that data - it was a LOT of figuring which resulted in some not really pretty coding!! But it does work.

So that gets the data to the track, but I also wanted to control switches, relays for master power, etc. That is accomplished using 4099 8 bit addressable latches in arrays controlled by the parallel port. This could be considered really old school but it is a setup I came up with a long time ago to do home automation and it works for me. Plus the chips are cheap. This could also be done with I2C controllers to really lower the chip count.

If you want to play with this code you're welcome to do so (as long as you don't plan on selling it of course), but it is in VB6 and has been programmed pretty specific to my rig. The function is in there to create the DCC strings but it is kinda buried and I'm awful at my in-program commenting. :)

Another system you may want to look in to is the TMWDCC guys. I started with their DOS system which worked great, but it uses a PIC chip feeding from the LPT port and Windows doesn't handle the interrupt based coding very well (actually not at all) so it couldn't be adapted to my plan. TMWDCC2 however is their windows version and was the inspiration for my current system. Lars sent me the code to do the conversion but it was in C++ and I couldn't use it, so I started scratch. Bottom line is the DOS version works very well, and if you want one of the programmed PIC chips to play with I'd be happy to mail it to you. (It also utilizes wired remote controls which are easy to build.) But if you want to jump to serial port control (which you'll kinda need to do for Windows), play with the bare bones verion of TMWDCC2 they have posted. In both cases, you'll still need a booster and that 18200 IC works amazingly well.

Whew! Hope that helps...

Mark
 
I have come across TWMDCC before. I was originally going to use it on an old machine that seems incapable of using any OS except DOS, but they said the driver takes over the parallel port and there was the other issue of their hardware. I looked through their source code. The driver calls are what gave me a hard time. I have studied C++, but it was a book more for gaming and graphics than for interfaces. I didn't know the project was still alive. I would look at your source code, but Microsoft got rid of support for VB6 in their new IDE. There is an upgrade engine, but it requires that all the drivers used in the project be on the machine. I assume you had to use MSComm to do serial communication, and the upgrade engine can't handle that. However, the baud rate values are very helpful. Thank you. One of the first places I looked when I started to research this was the NMRA's standards. I was going to try to use my stamp to create the singal by cycling a pin on and off, and feeding it to a booster. However, that fell through. I can not cycle it fast enough. My RCX (legos microcontroler) can, but I would have to write new firmware. Someone wrote firmware for it to do DCC. The problem is there is no way to send messages from the computer and the RCX can not write back. I would have to write my own firmware to change that. I also will have trouble ordering parts. I'm not old enought to have a credit card, so online ordering (of anything) is difficult. I started reading through the Digitrax stuff again, and found something I'd missed the first time. You can connect a serial port to their network and send commands, but it is kind of vague hardware wise. I might see if my dad can order a LMD18200. Would another motor driver work though? I think radioshack has one that I could get from a store. It is a DC motor driver, right?
 


I have come across TWMDCC before. I was originally going to use it on an old machine that seems incapable of using any OS except DOS, but they said the driver takes over the parallel port and there was the other issue of their hardware...

The DOS TMWDCC actually works very well. It requires a pretty slow computer (an old P1 233 was just slow enough in my case :) ) - yes it does lock down a parallel port. It can even run from the floppy. It doesn't read decoders very well though. Not sure of any other issue with the hardware other than the PIC chip really is the only way to do that one - the TTL plan never worked for me.

Their TMWDCC2 windows version is a good way to give you a basic idea how it works with the serial port - it helped me a lot, and also was a good "functional" backup I could use to be sure the booster hardware was working. It is "quick and dirty" because it is very basic (they put a first version up and never updated it), but it does give you an idea on how it works.

...I might see if my dad can order a LMD18200. Would another motor driver work though? I think radioshack has one that I could get from a store. It is a DC motor driver, right?

There are a number of other boosters around which use a motor driver type IC, but I had problems with them for some reason. LM298 comes to mind - on the TMWDCC site they have a number of other booster designs. Most of them had a higher component count though - the 18200 is just so simple to build. :)

I'll give you one piece of advise...the first opportunity you have to program your test engine's decoder, be sure to do the following:


  • Turn off DC (CV #29, I set mine to 2): Without it, and your program locks up for some reason, the engine will see straight DC and go off at full speed. This way it will simply stop.

  • Set your packet timeout to around 5 or 10 (CV #11): If your code transmissions have any pauses, this setting will keep the engine going at the previous setting for the specified timeout. In my program sometimes when opening a new windows the COMM pauses briefly and the engine jerks a bit - this setting takes that problem away.
Mark
 




Affiliate Disclosure: We may receive a commision from some of the links and ads shown on this website (Learn More Here)

Back
Top