Author Topic: MHS-5200A Serial port communication error  (Read 371 times)

0 Members and 1 Guest are viewing this topic.

Offline trebiTopic starter

  • Newbie
  • Posts: 4
  • Country: hu
MHS-5200A Serial port communication error
« on: September 14, 2024, 11:56:09 am »
Hi guys,
I would like to ask for a little help.
I want to write a simple program in C#. Unfortunately, I get stuck at the beginning. I can't communicate with the device via serial port.
I always get a timeout exception error...
What am I doing wrong?

See my code
   
Code: [Select]
........
            try
            {
                // Serial port setup
                serialPort = new SerialPort("COM5", 57600, Parity.None, 8, StopBits.One)
                {
                    Handshake = Handshake.RequestToSend,
                    ReadTimeout = 500,
                    WriteTimeout = 500
                };

                // Open Port
                serialPort.Open();

                // Stopping the device's own program(s6b0)
                string stopCommand = ":s6b0\r\n";
                serialPort.Write(stopCommand);

                // waiting
                System.Threading.Thread.Sleep(500);

                // Simple inquiry
                //:r1c returns :r1c323(firmware 3.23)
                //:r2c returns :r2c015(last digits of P / N ?)
                //:r0c returns :r0c52A(model #? 5200A?)
                serialPort.Write(":r0c\r\n");

                // waiting
                System.Threading.Thread.Sleep(500);

                // reading answer
                string response = serialPort.ReadLine();

                // We display the content of the response
                MessageBox.Show($"Device response: {response}", "Response", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (TimeoutException)
      .......

Thank you in advance for your answers.
 

Offline NE666

  • Regular Contributor
  • *
  • Posts: 129
  • Country: gb
Re: MHS-5200A Serial port communication error
« Reply #1 on: September 14, 2024, 12:07:11 pm »
I think you're more likely to get an informed answer here, given the subject matter; https://www.eevblog.com/forum/testgear/mhs-5200a-serial-protocol-reverse-engineered/50/

However, if you'd like a guess - are you sure that a) hardware flow control is really being used (instead of software/XonXoff) and b) if so, you're wired up correctly?
 
The following users thanked this post: voltsandjolts, Kean

Online Kean

  • Supporter
  • ****
  • Posts: 2238
  • Country: au
  • Embedded systems & IT consultant
    • Kean Electronics
Re: MHS-5200A Serial port communication error
« Reply #2 on: September 14, 2024, 12:16:29 pm »
I'd suggest first trying no handshake in case of a cable problem.
Code: [Select]
serialPort.Handsake = Handshake.None;
Also, if the line endings are always CRLF, you can set
Code: [Select]
serialPort.Newline = "\r\n";and then use WriteLine() without including the line ending.
ReadLine() will also expect the same line ending which is sometimes a problem.
 

Offline trebiTopic starter

  • Newbie
  • Posts: 4
  • Country: hu
Re: MHS-5200A Serial port communication error
« Reply #3 on: September 14, 2024, 08:17:08 pm »
Thanks for the answer.
I have tried all the suggested options but no change. The cable must be good, it communicates with added software. However, I noticed that the factory software sees it as MHS-5212A.
 

Offline NE666

  • Regular Contributor
  • *
  • Posts: 129
  • Country: gb
Re: MHS-5200A Serial port communication error
« Reply #4 on: September 15, 2024, 08:04:48 am »
If it were me, and I'd not done so already, I'd put my own code aside and verify whether or not I could access the device using a "proven" serial terminal program (e.g. putty) using the same serial settings. Eliminate any possible serial misconfiguration issues first ahead of suspecting a problem with your code or libaries.
 

Offline trebiTopic starter

  • Newbie
  • Posts: 4
  • Country: hu
Re: MHS-5200A Serial port communication error
« Reply #5 on: September 18, 2024, 02:53:37 pm »
Thank you for your help, communication via serial port is working. 8)
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3249
  • Country: us
Re: MHS-5200A Serial port communication error
« Reply #6 on: September 18, 2024, 04:09:48 pm »
Does this Python module work for you?

https://www.eevblog.com/forum/testgear/python-module-to-control-mhs-5200a/

Could be a starting point for figuring out what you C# problem is.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf