0

I am currently attempting to establish an interface with an LP7510 Weighing Indicator using the RS232 to USB protocol, aiming to retrieve the weight information displayed on the device. According to the user guide, the serial interface of the indicator is capable of receiving "simple ASCII commands" (Page 9). The designated command words and their corresponding functionalities are as follows:

"P" - PRINT: Initiates the printing of the weight.
"R" - REPLY: Requests a reply containing the weight value.

Since this is my first experience with serial port communication, it is plausible that the issue lies within my code implementation. Provided below is an initial code snippet that I have employed for this purpose:

private SerialPort serialPort;

private void BtnOpenConnection_Click(object sender, RoutedEventArgs e)
{
    serialPort = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
    serialPort.DataReceived += SerialPort_DataReceived;
    serialPort.Open();
}

private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    string data = serialPort.ReadLine().ToString();

    textBox1.Text = data;
}

private void BtnSend_Click(object sender, RoutedEventArgs e)
{
    serialPort.Write("R");
}

During the initial testing phase, I encountered a situation where no data was received despite successfully establishing a connection. This prompted me to investigate the cable itself. In an attempt to address the issue, I swapped the RX and TX lines on the printed circuit board of the scale indicator, suspecting that the lines might have been incorrectly positioned. However, this modification did not resolve the problem, and the issue persisted.

To further assess the cable's functionality, I conducted a loop test and performed communication tests using TeraTerm. In this scenario, I was able to transmit commands and receive responses successfully. I still would not rule out the Cable however I am now at some loss.

Another possible fix maybe due to the way I can currently calling serialPort.Write("R"). Would I need to first convert this to a byte?

byte asciiCommand = (byte)'R';
serialPort.Write(new byte[] { asciiCommand }, 0, 1);

Any help or suggestions would be greatly appreciated!

R-Raven
  • 1
  • 1
  • Does the manual say if commands need to be terminated by anything? `\n` maybe? – Fildor Jul 04 '23 at 15:25
  • First you need to ensure that you have the correct cables as identified by the manufacturer. Contact the manufacturer for more information. The following may be of interest: [FTDI cables](https://ftdichip.com/product-category/products/cables/usb-rs232-cable-series/) and [VCP Driver](https://ftdichip.com/drivers/vcp-drivers/). Then you need to configure the COM port settings on the weighing indicator. See _4.6 Second display, printer, computer communication (optional)_ on p. 23. – Tu deschizi eu inchid Jul 04 '23 at 15:31
  • The settings you specified in the weigh indicator, must match the settings you use with [SerialPort Class](https://learn.microsoft.com/en-us/dotnet/api/system.io.ports.serialport?view=dotnet-plat-ext-7.0). While the manual doesn't specify what the default settings are, it's possible that serial port communication is not enabled (ie: C27=0; shut off). – Tu deschizi eu inchid Jul 04 '23 at 15:32
  • If you click my username and in the search box type _serial-port_ after my userid, you'll find some posts for serial port that may be helpful. There are some PowerShell commands at the bottom of this [post](https://stackoverflow.com/a/70614758/10024425) that may provide some useful information. – Tu deschizi eu inchid Jul 04 '23 at 15:37
  • [SerialPort.ReadLine](https://learn.microsoft.com/en-us/dotnet/api/system.io.ports.serialport.readline?view=dotnet-plat-ext-7.0) will only work if the data is terminated with a newline as specified by [SerialPort.NewLine](https://learn.microsoft.com/en-us/dotnet/api/system.io.ports.serialport.newline?view=dotnet-plat-ext-7.0) – Tu deschizi eu inchid Jul 04 '23 at 16:13
  • if teraterm isn't to your liking, use "HTerm". it's more specific in presenting the data. – Christoph Rackwitz Jul 04 '23 at 20:28

1 Answers1

1

Your first step with TeraTerm is the best one. Now you are sure the device, the cable, the convertor etc. works perfectly. Your app is the only point to maintain.

So, please note in TeraTerm when the reply comes back: immediately after R or you need to press Enter? You need to write the port respective symbols. It should help. Otherwise provide your feedback.

In TeraTerm also take a note at the reply. Repeat R command several times and determine if 'new line' presents in the reply. Depending on it you need to use 'serialPort.ReadLine()' or 'serialPort.ReadExisting()' because ReadLine() waits the 'new line' symbol and comes back after it only.

Device's manual tells what CR/LF ends the reply, so 'serialPort.ReadLine()' should work.

rotabor
  • 561
  • 2
  • 10