Results 1 to 22 of 22

Thread: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    I am having a problem I have always had with MSCOMM32. If I did not have the correct baud rate set for the control on the form it is on, I can not change it programmically. I can set me.mscomm.settings = "19200,n,8,2" all I want but if on the form it is set for "115200,n,8,2", it does not change.

    So, I thought I would give SCOMM32 a try; it is installed.

    When I try to add the activeX control to the toolbox, I get a "Name conflicts with existing module, project, or object library" error. I haven't figure out why yet.


    Even if I have the settings on the form set to "19200,n,8,2" and later perform a "Me.comRS232.Settings = Serialsetup", it will no long communicate. If I do not do that, with the 19200,n,8,2 settings on the form, it communicates just fine.

    Dave
    Last edited by daveyk021; Dec 3rd, 2022 at 01:06 PM.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,526

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    did you delete the MSCOMM32.ocx from your entire project?
    Sam I am (as well as Confused at times).

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Yes, but not from the computer. I remember a few month ago have both MSCOMM and SCOMM32 on the same form under different names just fine, BUT I believe that was in office VBA, not VB6.

    There is no reference to MSCOMM or SCOMM in this project other than on the main form and in the main code. This is a new project.

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,526

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Well, that was just a guess anyway (about using SCOMM). Sorry, can't help with the issue of your baud rate/etc. Am sure others can.

    Sammi
    Sam I am (as well as Confused at times).

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    I recreated the VPN from scratch importing the form and all the modules. That seemed to work. A weird thing, my main form (only form is MAIN) and with the new project, it would not let me run or compile as long as the form name was Main. All my existing projects have a form named Main and work just fine.

    Anyway, I did get SCOMM32x.ocx as a control.

    MSCOMM32, with the exact same settings generates an _OnComm event #2 went data is received. SCOMM32X does not generated and ON_COMM event with the #2. It only seems to generate an event #1, which is a transmit event; so I gave up on SCOMM32X.

    I still can not programmically change the baud rate using the settings. As soon as I change the settings, programmically, the control ceases to work.

    So if the project is going to support 3 or 4 instruments each with their own baud rates, I guess I will need 3 or 4 copies of the control all preset to the baud rate needed and talk to the control based on the instrument being tested. That sucks.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,880

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Just tried it. No problem assigning Settings a different value at run time from the value it was given at design time.

    Are you using VB6 Service Pack 6 or not?

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Quote Originally Posted by dilettante View Post
    Just tried it. No problem assigning Settings a different value at run time from the value it was given at design time.

    Are you using VB6 Service Pack 6 or not?
    VB6.0 (SP6)

    I've had this issue since I started using MCCOMM32.OCX back around 2006 on various computers.

    me.mscomm1.settings = "115200,n,8,2"

    and it never communicates again. If it is set that way on the form, as soon as I address settings programmically, the ocx would never communicate again. Well it might, but doesn't generate an _oncomm event of 2. I receive all data through the _oncomm event.

    Funny this is, today, I could not get SCOMM32x to generate an _oncomm event of 2 not matter what I tried, so I went back to MSCOMM32.

    Now I also have GLOBLMGR.DLL referenced for GPIB/USB communications with test equipment. I doubt that is interfering, but I have never used MSCOMM32 without also referencing GLOMGR.DLL.

    I am tired and heading up right now and will continue this fight tomorrow.

    BTW, currently, I have two instances of MSCOMM32 on the same for and reference each as a control. One is referenced set at 115200 and the other at 19200 baud. Believe it or not, that works fine. But, I have others I want to use this new tool that communicate at 57600, others at 9600 baud. That's two more speeds I need off the top of my head.

    It is not real critical since i figured out a work-around, but it has always stumped me, if I am incorrectly programmically changing the parameter. I was tempted to buy this book: https://www.amazon.com/Visual-Basic-.../dp/1890422282 , but at $120, I doubt it. I have been doing serial communications, with instruments under test, since 2006 and controlling test equipment with the GPIB, and am pretty good at it, except for this one issue.

    I suspect, I am doing something stupid, but it is damn difficult to google FULL examples of how to do it. Sure, it is talked about, and even on microsoft's web site. Changing the setting has never worked for me.

  8. #8
    PowerPoster
    Join Date
    Nov 2017
    Posts
    2,276

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Quote Originally Posted by daveyk021 View Post
    It is not real critical since i figured out a work-around, but it has always stumped me, if I am incorrectly programmically changing the parameter. I was tempted to buy this book: https://www.amazon.com/Visual-Basic-.../dp/1890422282 , but at $120, I doubt it. I have been doing serial communications, with instruments under test, since 2006 and controlling test equipment with the GPIB, and am pretty good at it, except for this one issue.
    The 3rd edition of that book is less than $20, FWIW.

    https://www.amazon.com/Visual-Basic-.../dp/1890422274

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,880

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Are you trying to changes Settings while you have PortOpen = True?

  10. #10
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,151

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Can't say I've ever tried changing the settings while the port is open. I can see where that may fail

    Been using MSComm for many years on the form it is almost always the to the default 9600,n,8,1 then sets the actual via code often getting the settings from a ini file.

    What is this
    "Me.comRS232.Settings = Serialsetup"

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Quote Originally Posted by DataMiser View Post
    Can't say I've ever tried changing the settings while the port is open. I can see where that may fail

    Been using MSComm for many years on the form it is almost always the to the default 9600,n,8,1 then sets the actual via code often getting the settings from a ini file.

    What is this
    Me.comRS232 is the name of the MSCOMM32 control on my form (me). I guess "myMain.commRS232.Settings = serialsetup" would be more correct. Serial Setup is a string variable with the settings.

    Without the control at the correct settings, I can't open the port. So no, the port is not open.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Quote Originally Posted by OptionBase1 View Post
    The 3rd edition of that book is less than $20, FWIW.

    https://www.amazon.com/Visual-Basic-.../dp/1890422274
    Thank you. I ordered it.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Quote Originally Posted by dilettante View Post
    Just tried it. No problem assigning Settings a different value at run time from the value it was given at design time.

    Are you using VB6 Service Pack 6 or not?
    Can you show me how you did it in code?

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Quote Originally Posted by DataMiser View Post
    Can't say I've ever tried changing the settings while the port is open. I can see where that may fail

    Been using MSComm for many years on the form it is almost always the to the default 9600,n,8,1 then sets the actual via code often getting the settings from a ini file.

    What is this
    I use ini files too. Can you show me a code example of changing the settings? I mean it should be straight forward.

    Dave

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    I thought my work-around my issue worked. I would have two MSCOMM32 controls on the same form. I then define a CTL variable and depending on the instrument, select a given control.

    Well, it only works if both controls are configured with the same baud rate. If one control is set to 19200 and the other to 115200, it does transmit data, but apparently at the baud rate of 19200. The instrument hooked to the serial report returns and error message.

    <sigh>

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    So, now I tried only having one comm32 control on the form. I have it preset for 115200 baud. It works fine, I can connect and everything works perfect, BUT if I do this to configure the control:

    MyMain.comRS232_USD15.Settings = "115200,n,8,2"
    MyMain.comRS232_USD15.RThreshold = 1
    MyMain.comRS232_USD15.SThreshold = 1
    MyMain.comRS232_USD15.Handshaking = comRTS

    which is exactly how it is configured on the form, it stops generating the _oncomm event. Why?

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    I may have fixed the issue.

    I had always sent to the port this way: MyCTL.Output = Chr(27) & Remote & vbCrLf

    What I do not understand is why it works perfect until the mscomm control is addressed?

    I changed that line to:
    MyCTL.Output = Chr(27) & Remote & Chr(13)

    Now I can address the mscomm control all I want and change the baud and it works. I had been using vbCrLf since 2006, as I was taught by the German programming engineers at work. No wonder they had a different version of the exact same program for each instrument.

  18. #18
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,151

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Left over line feed in the buffer after sending the VBCRLF ?

    Try vbCR instead

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Quote Originally Posted by DataMiser View Post
    Left over line feed in the buffer after sending the VBCRLF ?

    Try vbCR instead
    Yup, same thing as chr(13).... I would guess unless there are some VB quirks using the pre-defined variables... lol At this point, I would doubt nothing.

    I pulled my hair out for far too long over this one. Up until now, I did not have a multi-instrument software tool, or the need for one. The instruments I test are far enough apart in specs or command functions that it was not a bother. This new software tool, only needs to control 2, maybe 3, commands for a given instrument, so it is easy enough to support many different instrument models.

    In case you're interested, here is the only report output (via Excel) of this software tool.
    Attached Images Attached Images  

  20. #20
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    4,439

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Quote Originally Posted by daveyk021 View Post
    I may have fixed the issue.

    I had always sent to the port this way: MyCTL.Output = Chr(27) & Remote & vbCrLf

    What I do not understand is why it works perfect until the mscomm control is addressed?

    I changed that line to:
    MyCTL.Output = Chr(27) & Remote & Chr(13)

    Now I can address the mscomm control all I want and change the baud and it works. I had been using vbCrLf since 2006, as I was taught by the German programming engineers at work. No wonder they had a different version of the exact same program for each instrument.
    This is not a matter of *choice* or *preference* but all about exact *protocol* your device is implementing.

    When using Chr(27) & Remote & vbCrLf you are spamming the device with extra line feeds (vbLf) so it might ignore these or consider these *prefix* to next command which is incorrect as the commands seem to begin with Chr(27).

    Anyway, my point is that you've been violating device protocol since 2006 and such latent bugs *always* backfire sooner or later when you change the device model or change connectivity from serial port to USB emulator or similar circumstances.

    MSCOMM32 works. The problems are 99.999% of the time in client code.

    cheers,
    </wqw>

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Sep 2022
    Posts
    95

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    "MSCOMM32 works. The problems are 99.999% of the time in client code."

    Absolutely true. I just do not understand why it works perfect unless the code is preceded by changing commport settings before opening the port. Then when it didn't work, I could bring up another program using the same code and it connects and works on the first try.

    I get the LF, but I am not so sure it is the instrument under test. The examples of using mscomm32 probably only show using a chr(13) to send data over the serial port. The LF might be screwing it up.

    BTW, this is under Windows 11. I still had this same issue under Windows 7.

  22. #22
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,151

    Re: MSCOMM32 Issue, VB6 Not allowing SCOMM32 on form

    Quote Originally Posted by daveyk021 View Post
    "MSCOMM32 works. The problems are 99.999% of the time in client code."

    Absolutely true. I just do not understand why it works perfect unless the code is preceded by changing commport settings before opening the port. Then when it didn't work, I could bring up another program using the same code and it connects and works on the first try.

    I get the LF, but I am not so sure it is the instrument under test. The examples of using mscomm32 probably only show using a chr(13) to send data over the serial port. The LF might be screwing it up.

    BTW, this is under Windows 11. I still had this same issue under Windows 7.
    Well what can(will) happen when you send an extra character like that is it can cause everything after the first transmission to not work in your case you say you need chr(27) Data CHR(13) but you were sending CHR(27)datachr(13)chr(10) The client reads up through the chr(13) and may leave the chr(10) in the buffer. Then your next request gets seen as chr(10)chr(27) ..... and that may very well throw a wrench into everything but that is not the doing of MSComm it is a protocol error and depending on the client side code it may or may not be able to deal with such a thing.

    Anytime dealing with serial code you should make sure you send exactly what the other end expects to get in the order expected and nothing else. Any extra characters or out of order characters will cause early baldness.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width