我如何...缩放重量显示 [英] How do I...Scale weight display

查看:67
本文介绍了我如何...缩放重量显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我是从RS232端口发送的数字体重秤。

现在我想在我想要显示的应用程序中获取此信息。

来源没有人这样做吗?

C#语言使用串口

Hi I am a Digital weight scale received from the RS232 port sends.
Now I want to get this information in my application I want to display.
The source does not anyone do this?
C # language using the Serial port

推荐答案

对不起,但我们可以;必须这样做 - 那里所有机器接口都没有标准,即使是通过RS232,如果不知道秤的确切品牌和型号,我们也无法帮助你。



您应该与创建它的人交谈 - 他们应该提供技术支持,并且会比我们更了解他们的产品。如果他们没有,那么找另一个供应商并要求退款!
Sorry, but we can;t necessarily do that - there is no one standard for all machine interfaces, even via RS232, and without knowing the exact make and model of the scale we can't help you very much, if at all.

You should talk to the people who created it - they should provide technical support and will know more about their product than we will. If they don't, then find another supplier and demand your money back!


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;


namespace B1
{
    public partial class Form1 : Form
    {
        private SerialPort _serialPort;         //<-- declares a SerialPort Variable to be used throughout the form
        private const int BaudRate = 9600;

        public Form1()
        {
            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            #region Form Load
            try
            {
                //getRawWeight();
                string[] portNames = SerialPort.GetPortNames();     //<-- Reads all available comPorts
                foreach (var portName in portNames)
                {
                    comboBox1.Items.Add(portName);                  //<-- Adds Ports to combobox
                }
                comboBox1.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            #endregion
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (_serialPort != null && _serialPort.IsOpen)
                _serialPort.Close();
            if (_serialPort != null)
                _serialPort.Dispose();
            //<-- End of Block

            _serialPort = new SerialPort(comboBox1.Text, BaudRate, Parity.None, 8, StopBits.One);       //<-- Creates new SerialPort using the name selected in the combobox
            _serialPort.DataReceived += SerialPortOnDataReceived;       //<-- this event happens everytime when new data is received by the ComPort
            _serialPort.Open();     //<-- make the comport listen
            textBox1.Text = "Listening on " + _serialPort.PortName + "...\r\n";
        }
        private delegate void Closure();
        private void SerialPortOnDataReceived(object sender, SerialDataReceivedEventArgs serialDataReceivedEventArgs)
        {
            if (InvokeRequired)     //<-- Makes sure the function is invoked to work properly in the UI-Thread
                BeginInvoke(new Closure(() => { SerialPortOnDataReceived(sender, serialDataReceivedEventArgs); }));     //<-- Function invokes itself
            else
            {
                while (_serialPort.BytesToRead > 0) //<-- repeats until the In-Buffer is empty
                {
                    string reading = "";
                    reading += string.Format("{0:X2} ", _serialPort.ReadByte());
                    //<-- bytewise adds inbuffer to textbox
                    //string reading = System.Text.Encoding.UTF8.GetString(_serialPort);
                    textBox1.Text = reading.Substring(13);
                    //string reading2 = System.Text.Encoding.UTF8.GetString(reading);
                    //textBox2.Text = reading2.Substring(13);
                }
            }
        }
    }
}


这篇关于我如何...缩放重量显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆