Serial Port Communication
Hi,
I am trying to create a connection with port com, and I am using JavaScript.
The goal is to send the HEX sequence and read the HEX back from the port.
I copied from this page https://support.smartbear.com/testcomplete/docs/scripting/working-with/com-ports.html and I modified a bit, here's what I have:
function Test() { var Port, s; Port = dotNET.System_IO_Ports.SerialPort.zctor_4("COM6", 9600); Port.Open(); // Writing data to the port Port.Write("1A030688"); // Waiting for response aqUtils.Delay(1000); // Processing response if (Port.BytesToRead != 0) { s = Port.ReadExisting; Log.Message(s); } else Log.Warning("No data"); Port.Close(); }
It gave me "No Data", I believe it's because I was sending HEX instead of Bytes, but I am not sure how to fix it.
When i tried to remove the 'if' clause, it gave me a success, but it's blank.
It's been a few days but I still don't know how to solve it. I would really appreciate it if anyone could help me with this.
Thank you very much.
Hi,
> The goal is to send the HEX sequence
> Port.Write("1A030688");
The above .Write() call does not write expected hex sequence, but writes the ASCII string (with relevant hex codes), which is not correct as I think.
Try to prefix every hex with \x prefix (like in the article you've referenced) and check if it helps. I.e.:
Port.Write("\x1A");
Port.Write("\x03");
Port.Write("\x06");
Port.Write("\x88");