I have a scale that connect to PC through RS232, I send "W" to receive the weight. The scale sends the weight all the time as it's read. How do I catch the weight that is being read?
Can i get any C# sample code?
I have a scale that connect to PC through RS232, I send "W" to receive the weight. The scale sends the weight all the time as it's read. How do I catch the weight that is being read?
Can i get any C# sample code?
You need to use SerialPort component of .NET. The full description and examples are available on MSDN site: http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx
Sending a W? Sounds like the Mettler Toledo scale that FedEx gives businesses. I happen to have some code that reads from such a scale:
// where this.port is an instance of SerialPort, ie
// this.port = new SerialPort(
// portName,
// 1200,
// Parity.None,
// 8,
// StopBits.One);
// this.port.Open();
protected override bool GetWeight(out decimal weightLB, out bool stable)
{
stable = false;
weightLB = 0;
try
{
string data;
this.port.Write("W\r\n");
Thread.Sleep(500);
data = this.port.ReadExisting();
if (data == null || data.Length < 12 || data.Substring(8, 2) != "LB")
{
return false;
}
if (decimal.TryParse(data.Substring(1, 7), out weightLB))
{
stable = (data[11] == '0');
return true;
}
}
catch (TimeoutException)
{
return false;
}
return false;
}
Have a look here
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/a709d698-5099-4e37-9e10-f66ff22cdd1e