Shop OBEX P1 Docs P2 Docs Learn Events
VB6 Serial Communication — Parallax Forums

VB6 Serial Communication

CullenCullen Posts: 3
edited 2013-01-16 23:14 in Propeller 1
Greetings--

I've seen a lot of information regarding Prop to PC serial communication, but I can't seem to find clear answers on what I'm looking for.

I need the Propeller to communicate back and forth with a VB6 app on my PC at runtime. VB will be doing most of the work--the Prop will only be handing input switches, a couple of radio TX/RX here and there, perhaps a GPS signal, outputting to relays, etc. - nothing the Prop can't handle with eight cogs (call it seven if one's tied up with VB). The Prop's code (in Spin) will be pretty simple--it's basically acting as a driver between the PC and the hardware that it needs to interact with. (I haven't written it yet so I have nothing to post.)

How do I wire up the Prop to communicate with the PC this way? I know that I can load programs with the Propstick, but can I communicate with my PC while the Prop is running that way? I'm hoping it's as simple as that. If that's the case, does anyone know how to get VB to communicate with the outside world via USB?

From what I've seen on a few forums, I don't think that VB can use the USB port--it has to use a serial port (or through a USB to serial adapter if the actual serial port isn't on the PC). This (again, I'm theorizing here) is a limitation of VB.

So, if I can't use the Propstick, how do I wire a serial port to the Propeller? Do I need to use a MAX3232? Should I use P31 and P30, or does it matter? If I do use those pins, will it impact the USB serial communication for loading programs?

I found this diagram online but wasn't sure if it fit the my particular application:

http://forums.parallax.com/forums/attach.aspx?a=23135

This is my first post and I'm new to microcontrollers--please let me know if I've left out any important pieces of information.

Thanks!

Comments

  • 4Alex4Alex Posts: 119
    edited 2009-08-25 22:54
    @Cullen: Hello there and welcome. VB6 and propellers is a nicely working combo. I use it regularly in the lab.

    I am in a hurry so I'll be brief. More to come later on.

    1. I use VB6 on a notebook in the lab to monitor stuff through either serial port or USB. Target device is a propeller (of course!).

    2. To use the USB, FTDI supplies a driver, free of charge, that converts the USB port into a virtual serial port, so the USB is seen as a regular serial device.

    3. In VB6, you need to use MSComm object. Setup is critical if you want to make it working properly with the virtual port. I use the object configured as follow:

    DTREnable = false <=== critical! It prevents the propeller from rebooting when port is closed
    EOFEnable = False
    Handshaking = 0 - None
    InBufferSize = 1024
    InputLen = 0
    InputMode = 0 - comInputModeText
    NullDiscard = False
    OutBufferSize = 512
    RThreshold = 0
    RTSEnable = False
    Settings = 115200,n,8,1 <=== lower rate are ok
    SThreshold = 0

    4. depending on how you want to use object, you may have to poll the device, or just wait until some data come your way.

    I really have to go but if you point me toward what you really want to achieve, I may be able to help you with some working VB6 code.

    Cheers,

    Alex

    Post Edited (4Alex) : 8/26/2009 12:16:48 PM GMT
  • 4Alex4Alex Posts: 119
    edited 2009-08-25 23:15
    @Cullen (from my BlackBerry):

    I read again your posting. As far as I know, VB6 is not limited in communicating with a propeller, either serial or usb, and works real sweet.

    If you want to use a serial port, in DB9 configuration, you need 3 wires:
    DB9-pin2(tx/rx), DB9-pin3(rx/tx), and DB9-pin5(gnd). I ignore all the other pins as I don't bother with handshaking. I always use a max232-type of IC, mainly to protect my PC, but I've seen plenty of direct connect through resistors in this forum. If I were you, I'd stick with the max232-type with serial.

    If you are using USB, simply follow the schematics provided by Parallax for the Propeller Plug (or something callled like that). You will need 4 pins: +3v3, Dat+, Dat-, and Gnd. You will need to install the FTDI virtual port driver. It works nice, at least under XP. Our labs are not cleared to use something else at this point (we also use Win2000 but driving the ports are a real pain). I have heard of serial port comms problems with Vista but I don't have any hand-on expertise on that. We hated WinMe, so please don't ask.

    I am still in transit but I'd be more than happy to be of assistance in your project. So many people helped me on this forum, I'd be glad to return the favour whenever I can. Just ask.

    Cheers,

    Alex

    Post Edited (4Alex) : 8/25/2009 11:24:26 PM GMT
  • 4Alex4Alex Posts: 119
    edited 2009-08-25 23:28
    @Cullen (from my BlackBerry):

    Sorry if this comes in bits and pieces.

    On the propeller side, you will need a serialComm spin file. My personal favourite is SerialMirror because I find it very simple to use and extremely versatile when interfacing multiple serial devices comes to play.

    The way you decide to interact between the propeller and the pc is critical. I some applications, I need a cog solely devoted to monitor the polling requests.

    Cheers,

    Alex
  • localrogerlocalroger Posts: 3,451
    edited 2009-08-25 23:58
    As an aside, the mscomm control is only distributed with the VB enterprise edition. Years ago I got tired of messing around with component registration and figured out how to code serial comms straight to the Windows API. If anybody's interested I'll post the code tomorrow when I'm back at work.
  • 4Alex4Alex Posts: 119
    edited 2009-08-26 00:40
    @localroger (from my BlackBerry):

    I use VB6 Pro SP6 (32bits) and MSComm comes standard with it.

    Cheers,

    Alex
  • localrogerlocalroger Posts: 3,451
    edited 2009-08-26 00:52
    @4Alex, I've only seen standard and enterprise. I had a customer who had their VB standard ed installed and I needed to debug their program, which I'd installed via a disk made by the wizard. The #*%@% IDE wouldn't run the MSCOMM control because it was only registered for runtime use, not for development. I have zero patience for that sort of thing and today I have solutions for the serial ports and TCP/IP that don't involve custom controls at all.
  • jazzedjazzed Posts: 11,803
    edited 2009-08-26 00:53
    @localroger, I'd like to see your implementation to compare notes. Can you also post how to do a milli-second timer with Windows API while your at it (VB Timer is easy of course) ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve

    Propeller Tools Post Edited (jazzed) : 8/27/2009 3:26:03 AM GMT
  • CullenCullen Posts: 3
    edited 2009-08-26 01:05
    Thanks for the responses Alex! My notebook doesn't have a serial port but I've used the virtual serial via USB when testing communication with the BS2 a year back, so I know my PC can treat the USB as a virtual serial port. Does that mean I can just hookup my USB port from my notebook (as a virtual serial) to the Propplug to the Prop and get communication between the two at runtime? I know there's a lot more to do with the software, but is this all the hardware connection required? I have a MAX3232 (for 3.3v) if needed, but I won't use it if I don't have to...I'm hoping the Propplug is all it takes.

    Thanks again for the quick responses. These forums are incredibly helpful.
  • SamMishalSamMishal Posts: 468
    edited 2009-08-26 10:06
    localroger said...
    As an aside, the mscomm control is only distributed with the VB enterprise edition. Years ago I got tired of messing around with component registration and figured out how to code serial comms straight to the Windows API. If anybody's interested I'll post the code tomorrow when I'm back at work.
    @LocalRoger,

    does it still work under XP....I had a hell of a time to get VB6 code that did API stuff to still work under XP
    once I ported over to it....does yours work under XP....if yes then PLEASE do post it....

    Thanks


    @Cullen

    Have a look at this document I made for communicating a PC with the propeller. I did it for
    RobotBASIC which provides a VERY EASY way for you to do Serial comms.....but the
    METHODOLOGY and the DETAILS of the way to do it is all there and is still applicable to
    VB6 once you figure out how to do serial comms with VB6.

    There are a few options mentioned in the document that should put you on the right
    path.....all the stuff·aught to·be just as applicable to VB6 as it is for RobotBASIC.

    http://www.robotbasic.org/resources/RobotBASIC_To_PropellerChip_Comms.pdf


    Regards

    Sam
    ·
  • dMajodMajo Posts: 855
    edited 2009-08-26 10:57
    I started using VB3, than VB4, than VB6 Enterprise. VB3 and VB4 was standard releases. Both they have the MSComm object. My first selfmade scada was done using VB3 for the gui and generall management with a c++ (v1.5 IIRC 16-bit) made graphics engine dll to speed up the graph rendering (very very slow when done in basic). Beside Siemens/Telemecanique/AB plc communication it was connected also to spectrometer and deposition thickness controller using serial ports (MSComm).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · Propeller Object Exchange (last Publications / Updates)
  • jmbertoncelli@USAjmbertoncelli@USA Posts: 48
    edited 2009-08-26 12:01
    Hello everybody,

    I am using the latest .NET 3.5 and C# and to be perfectly honest the serial communication object is easy to use and very powerfull.· you can handle both synchronous and asyncronous serial communication you can even use a worker thread and a communication pipe between your GUI and the background worker thread responsible to handle the serial link(s) in real time.· On the prop side my favorite thing is using XBee or even the Bluetooth module from Parallax.· I was very successfull with both of them.· As far as I know VB6 is an obsolete techno and I do not advise anyone to continue to use it.· This url: http://www.learnvisualstudio.net/Members/Default.aspx·is a good way to learn the latest .Net techno, I am using their videos when I need to understand or learn something new.

    have a good day.

    jm.





    ·
  • 4Alex4Alex Posts: 119
    edited 2009-08-26 12:10
    @Cullen: Good morning.

    To answer your question: no, you don't need the MAX3232 in your design if you use the usb implementation, either via the Plug/Clip or a dedicated FTDI IC will work without anything else but the virtual port driver.

    So serial is out. Good. It's even simpler. Wiring diagram of Plug described on Parallax web site and Sam document works well. It's the one I use.

    As for the software, yes, this is where the fun begins. You will have to decide how you want your design to work. Is it going to be a challenge-response scheme between your pc and the propeller (i.e., a command is sent by the pc, the propeller analyse it, and then reply to the pc), a passive slave scheme (i.e. either side are simply waiting for data whenever they come), or a more involving scheme. If you intend to control the propeller, query status of sensors, and trigger switches, you are better with a challenge-response scheme. If its a passive sensor that simply issues periodic data (like a gps), then a passive data collection scheme is all you need. From your initial posting, I would go with a challenge-response approach.

    In that case, you need to first establish some sort of messenging protocol. If you want to take the fixed length method (i.e., the message is always the same length, the simplest of all), then you need to design the payload. Normally you should start with a header byte ("#", for example), then a command byte ("T"), then possibly a function of some sort ("R"), then some bytes for an eventual data set/reply ("0000"), and finally a tail byte (usually a checksum/CRC to ensure your message is valid). In this example, your fixed 8 bytes payload would look like this #TR0000@, meaning Read (R) Thermometer (T). The propeller could reply #TR0125*, meaning Thermometer Reading 12.5deg (you normally avoid decimal point in a reply if a fixed format is expected, in this case a division by 10). I normally reply with the Command+Function because the pc might issue several messages in a row and lenghty processing timing might not return the results in the initial arrival order. This way the pc knows what received data answers which request. If you follow this approach, then it is fairly simple to program both the VB6 and propeller to interact properly. Of course you can design your payload anyway you like. I put a data reply of 4bytes (1 long) because it covers a very large figure that you can still process easily in VB6 and propeller. The fixed lenght is simple to process because you know when a message starts (the header) and how many byte to expect. The location of each byte also convey the meaning of it al (i.e., second byte is the command). Variable lenght payload could be more efficient for wildly different payloads but they are more involving to process (you would need to code at a fixed location how many bytes are expected to be read).

    Let me know if you need more assistance and which approach you are taking.

    @Sam: I found XP to be very stable when VB6 is calling APIs. I use mainly graphical, memory, & internet-related APIs, though. BTW, I've followed some of your previous posts and I take this opportunity to thank you as they were useful to me. Your RobotBasic document is well written. Kudos.

    @dMajo: I also have an interface with an old Perkin-Elmer spectrometer in the lab: works great using MSComm VB6 Pro, but my circuit still uses a PIC16F, not a propeller.

    @LocalRoger: I agree with you that run time only DLL are a pest to deal with. I've never seen a single one coming from Microsoft, though. The only one I had to deal with were commercial (and expensive) DLL/OCX, mainly for graphical use. I also had my share of swearing at an HP DLL... As for the deployment of a program using MSComm, the installation cab generated by the Package & Deployment Wizard never failed me anywhere.

    Cheers,

    Alex

    Post Edited (4Alex) : 8/27/2009 12:51:37 PM GMT
  • Agent420Agent420 Posts: 439
    edited 2009-08-26 12:13
    ^ VB6 may be eol'd, but it's still the programming platform for things like Office 2007 and VBA.· I don't think it's going away any time soon.·

    Personally, I like VB6.·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • 4Alex4Alex Posts: 119
    edited 2009-08-26 12:19
    @Agent420: I agree with you. I use many different languages but I find VB so simple to use. If the tool perform the job simply and efficiently, why change? Afterall, there's widespread evidence that hammers were in use by the Neanderthals, and we still see quite a few of them around today! (the hammers, I mean, errr well.. on a second thought..)

    Cheers,

    Alex
  • localrogerlocalroger Posts: 3,451
    edited 2009-08-26 12:20
    Here's the code I use for serial access in VB4 and VB6.· It's been tested in WIndows NT 4.0, 2000, XP, and Vista consumer editions.· It does not work on Win95 or Win98 at all because those OSes are thread-bound and don't execute the overlapped code.· I have had problems on a couple of occasions with servers; I think some of the server installations do not initialize the DCB structure, so you have to read it before calling builddcb to set the port parameters, but I have this code running on literally hundreds of PC's and it has proven more reliable for me than MSCOMM.

    It's well commented and should be self-explanatory.· I use the normal VB timer to poll the port when necessary; Windows does a good job of buffering and this is almost always fast enough.· It is generally OK to transmit as much data as you want whenever you want as long as txportbusy() is false.· If txportbusy() is true you must wait until it is false signifying that the ongoing transmission is finished.· If you have a process outputting a bunch of data at random times, you can build a timer event that tacks outgoing messages onto a buffer string and blows the buffer out when it's safe.

    You can call the receive function whenever you want.

    I have a couple more versions of this with the names of functions changed for doing multiple ports.· To do the equivalent of a control array you need to create a class, which I've done but the way I did it isn't according to Hoyle and is messy as hell though it works.· (You can't use arrays of the control vars because in VB·dynamic arrays move around in memory, which screws up the pointers.)
  • SamMishalSamMishal Posts: 468
    edited 2009-08-27 03:00
    Hi All,

    The link I gave above to the PDF was to an older version of the PDF....oops
    Please download this newer version and disregard the older one.

    http://www.robotbasic.org/resources/RobotBASIC_To_PropellerChip_Comms.pdf

    it will look very similar but there are few errors in the old version.



    @LocalRoger

    ·· Thanks

    @4Alex

    Thanks for the support.....

    Also you must work for GEICO.....tongue.gif· (re Neanderthal joke)



    Sam
  • FORDFORD Posts: 221
    edited 2009-08-27 08:31
    have used vb6 pro for years, and yes it includes the com object.

    real nice to use.

    and yu can pick up vb6 pro on ebay legitaimately usually for a bargain [noparse]:)[/noparse]



    cheers,

    chris
  • fullspecengfullspeceng Posts: 76
    edited 2009-08-28 00:02
    If all you want to do is simple serial communications, just drag and drop the MSCOM serial object.

    If you want high speed communications, it is more tricky. FTDI ftd2xx drivers are the way to go.

    I have my own packet based asynch library that I'm thinking of releasing as a product. I can do 2mbps sustained transmit/receive using two cogs.
  • CullenCullen Posts: 3
    edited 2009-08-28 00:25
    I think I have it figured out (at least for low speed communication, which is all I need for now Fullspenceng). Basically it really is as simple as initializing a serial object (I used FullDuplexSerial) on 31 and 30 and leaving the Propplug plugged in for communication. I don't where I got convinced that the hardware had to be more complicated than that, and I feel like I searched forever trying to figure out. Either way--it's all working now. I can control relays from a nice looking VBA form on my PC through the Prop--pretty sweet. I feel spoiled now that I can't just launch another cog in VB--I have to either multithread or "DoEvents" like some sort of neanderthal...

    Thanks again to everyone for the responses!
  • Bruce52Bruce52 Posts: 1
    edited 2013-01-16 23:14
    I have been using VS-6.0 Enterprise for several years (still a great platform) and recently found out that the early releases of VS.Net Pro included a program called "vb6controls.reg" that would install the necessary licenses to use the controls from studio 6.0 Pro and Enterprise. VS2002 and VS2003 both had that program (even the time-limited versions packaged with books) because they were so lacking in functionality. VS.Net is no longer handicapped and I'm certain that the newer editions don't have the licensing program anymore. I don't know if the licenses would install on a pc with VB6 Working Model or Standard Edition, but they might. The mscomm control has been working well for me, and this may be a way to get it if you only have one of the lesser versions of VB-6. A search of the internet should turn up the licensing program without having to find an early version of VS-Net, so it wouldn't cost anything to give it a try.
Sign In or Register to comment.