none
MSComms RRS feed

  • Question

  • IN VS2015 I developed serial communications between the PC and the hardware it is controlling using VB. The PC would send commands which included high ascii characters. Having moved the application to VS2017 the high ascii characters are no longer being sent correctly and causing the hardware to hang.

    I am using Net Framework 4.6.1. I am developing on windows 10 and the application is being tested on a Windows 7 PC. The hardware has been checked and an older version of software works fine.

    Code used to send commands is as follows

    ... various commands to set speed etc. 

    mscomm1.open

     mscomm1.Handshake = Ports.Handshake.RequestToSend
                    mscomm1.Encoding = System.Text.Encoding.GetEncoding(28605)
                    mscomm1.Write(ChrW(portnum) & ChrW(portstr))

    Sending write command with no high ascii values works fine and we can read the results.

    Any suggestions please on how to fix

     

    Wednesday, April 25, 2018 1:15 PM

All replies

  • IN VS2015 I developed serial communications between the PC and the hardware it is controlling using VB. The PC would send commands which included high ascii characters. Having moved the application to VS2017 the high ascii characters are no longer being sent correctly and causing the hardware to hang.

    I am using Net Framework 4.6.1. I am developing on windows 10 and the application is being tested on a Windows 7 PC. The hardware has been checked and an older version of software works fine.

    Code used to send commands is as follows

    ... various commands to set speed etc. 

    mscomm1.open

     mscomm1.Handshake = Ports.Handshake.RequestToSend
                    mscomm1.Encoding = System.Text.Encoding.GetEncoding(28605)
                    mscomm1.Write(ChrW(portnum) & ChrW(portstr))

    Sending write command with no high ascii values works fine and we can read the results.

    Any suggestions please on how to fix

     

    Without knowing specifics, (like what values fail, what is 'high' ascii), I can only guess that the problem is the encoding you are using. One thing I wouldn't do is to open and close the port for each transmission unless it can't be avoided.  Open the port at the start of the app and close it when the app ends.

    Try sending the data this way.

            Dim b() As Byte = mscomm1.Encoding.GetBytes(ChrW(portnum) & ChrW(portstr))
            mscomm1.Write(b, 0, b.Length)
    If the values being sent are less than 256 then don't send them as strings.


    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."

    - from former MSDN User JohnWein

    SerialPort Info

    Multics - An OS ahead of its time.



    • Edited by dbasnett Wednesday, April 25, 2018 4:32 PM
    Wednesday, April 25, 2018 4:26 PM
  • Thank you for your suggestion - I'll give it a try. 

    I do only open the comms at beginning. This worked when using VS2015 and I have changed nothing in moving to VS2017.

    I have read through the update notes and can see no reference to comms, so wonder what has changed.

    Thursday, April 26, 2018 12:03 AM