如何使用 C# 与数字秤通信
我有一个矩阵 d1000+ 数字秤。我希望它在我的应用程序中使用 c# 的权重,但我不知道如何做到这一点。它通过rs232与我的电脑连接。
我正在使用此代码,但重量显示的格式不正确,例如 1+e00023,请告诉我如何纠正它。
public partial class ManageSale : Form
{
private SerialPort port = new SerialPort(
"COM1", 4800, Parity.None,8, StopBits.One);
public ManageSale()
{
InitializeComponent();
port.DataReceived +=
new SerialDataReceivedEventHandler(port_DataReceived);
port.Open();
port.DtrEnable = true;
port.RtsEnable = true;
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
this.label1.Text = port.ReadExisting();
}
private void ManageSale_Load(object sender, EventArgs e)
{
port.WriteLine("5");
}
}
嗨,大家好,我的问题仍然存在,请帮助我解决这个问题,看看我的代码,我错了,请告诉我如何纠正它。
I have a matrix d1000+ digital scale. I want it's weight in my application using c# but I have no idea how to do this. It is connected with my computer through rs232.
I am using this code but weight is shown incorrect format like 1+e00023 please tell me what can i do to correct it.
public partial class ManageSale : Form
{
private SerialPort port = new SerialPort(
"COM1", 4800, Parity.None,8, StopBits.One);
public ManageSale()
{
InitializeComponent();
port.DataReceived +=
new SerialDataReceivedEventHandler(port_DataReceived);
port.Open();
port.DtrEnable = true;
port.RtsEnable = true;
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
this.label1.Text = port.ReadExisting();
}
private void ManageSale_Load(object sender, EventArgs e)
{
port.WriteLine("5");
}
}
hi evryone my problem is still there plese help me to solve this problem see my code where i am wrong please tell me how to correct it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

联系制造商,索取 API 套件。您可能必须使用 DllImport 语句链接到用 C/C++ 编写的 dll。计算出 C/C++ 之间正确的数据类型可能非常耗时,但也是可行的。
请参阅.Net Framework 中的串行端口 Api。那里有一个例子:
Contact the manufacturer, and ask for the API kit. You'll probably have to link against a dll written in C / C++, using a DllImport statement. Working out the proper data types between C / C++ can be time consuming, but is doable.
See the Serial Port Api in the .Net Framework. There's an example there: