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!