MHS-5200A Serial port communication error - Page 1
Forum section: electronics / testgear

author: trebi
author_rank: Newbie
timestamp: September 14, 2024, 11:56:09 am
content: 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 codeCode:........try{// Serial port setupserialPort = new SerialPort("COM5", 57600, Parity.None, 8, StopBits.One){Handshake = Handshake.RequestToSend,ReadTimeout = 500,WriteTimeout = 500};// Open PortserialPort.Open();// Stopping the device's own program(s6b0)string stopCommand = ":s6b0\r\n";serialPort.Write(stopCommand);// waitingSystem.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");// waitingSystem.Threading.Thread.Sleep(500);// reading answerstring response = serialPort.ReadLine();// We display the content of the responseMessageBox.Show($"Device response: {response}", "Response", MessageBoxButtons.OK, MessageBoxIcon.Information);}catch (TimeoutException).......Thank you in advance for your answers.

author: NE666
author_rank: Frequent Contributor
timestamp: September 14, 2024, 12:07:11 pm
content: 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?

author: Kean
author_rank: Unknown
timestamp: September 14, 2024, 12:16:29 pm
content: I'd suggest first trying no handshake in case of a cable problem.Code:serialPort.Handsake = Handshake.None;Also, if the line endings are always CRLF, you can setCode: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.

author: trebi
author_rank: Newbie
timestamp: September 14, 2024, 08:17:08 pm
content: 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.

author: NE666
author_rank: Frequent Contributor
timestamp: September 15, 2024, 08:04:48 am
content: 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.

author: trebi
author_rank: Newbie
timestamp: September 18, 2024, 02:53:37 pm
content: Thank you for your help, communication via serial port is working.

author: ledtester
author_rank: Super Contributor
timestamp: September 18, 2024, 04:09:48 pm
content: 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.