CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2014

    Array on serial port using VBA 6 VB6

    Hello guys,
    I'm working on an existing program written in VBA and I need to make some modifications...

    I have to send a command to a power supply for getting the answer of the actual status.
    There is a specific format. I have modified the sending command routine in this way (using mscomm1):

    Dim buffer (3) as byte

    buffer(0) = &HAA
    buffer(1) = &H1
    buffer(2) ) &H26

    mscomm1.output = buffer

    Here the command works perfectly.
    Then I have to get the answer from the serial port. When I read the serial port using a special com-debug program, I see that the serial port asnwers the following:

    AA 01 26 04 00 00 00 00 2B (which represents the correct answer).

    When I try to use the mscomm1.input command I only see the first AA (170 decimal) character.

    I have used the following code:

    dim stringa () as byte

    stringa = mscomm1.input
    lght_stringa = Ubound(stringa)
    for i = 0 to lght_stringa
    txt = txt & stringa(i)
    next i

    I have tried to change my code in many ways(changing the input mode from char to binary, using .inputlen property, I also tried to execute the .input command more than one time) but it looks that I have not formatted correctly the input. I believe I have to receive the data in the correct format and only then try to read the signle byte...but how to do?
    Any help?
    by the way..actually it works on VBA but if necessary I can switch to VB6...
    thank you very much for any suggestion...

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: Array on serial port using VBA 6 VB6

    See this example in MSDN.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2014

    Re: Array on serial port using VBA 6 VB6

    Quote Originally Posted by VictorN View Post
    See this example in MSDN.
    Hi Victor,
    thank you...
    I have found the reason why it didn't work...it was due to my mscomm1 setting. I didn t set the input mode to binary...so the format of the array was "lost" in the serial buffer...now it works fine! Thank you very much for your support!!!

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.