3
Answers

How to contact a button on my serial port device?

Sascha B

Sascha B

15y
2.4k
1
Hello,

I have to read some data out of my measurement device.
But the problem is that I dunno how to send a request that has the same
function as a button on my device.
So how can I check which button on my device sends which code?
It is a Color Measurement devce from Konica Minolta called CL-200.

Or is there an other way to get the data out of the device up to my pc?
(But it has to be controlled by my PC not by button pressing on the device)
Answers (3)
0
Abhishek Singh
NA 5.3k 1.1m 10y
Hi,

<asp:gridview ID="Gridview1" runat="server" AutoGenerateColumns="False" OnRowDataBound="Gridview1_RowDataBound" ShowFooter="True">
        <Columns>
            <asp:BoundField DataField="CustomerID" HeaderText="ID" />
            <asp:TemplateField HeaderText="Name">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("firstname") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("firstname") %>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
            <asp:Label ID="lbl" runat="server" Text="Total Amount" />
         </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Amount">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("amount") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("amount") %>'></asp:Label>
                </ItemTemplate>

                <FooterTemplate>
            <asp:Label ID="lblTotal" runat="server" />
         </FooterTemplate>
            </asp:TemplateField>
        </Columns>
        </asp:gridview>
  

Code:

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace gridViewTest
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        decimal total = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.populateData();
            }
        }

        public void populateData()
        {
            DataTable dt = new DataTable();


            dt.Columns.Add("CustomerID");
            dt.Columns.Add("FirstName");
         
            dt.Columns.Add("Amount");
            dt.Rows.Add("0001", "Abhishek", 10000);
            dt.Rows.Add("0002", "Ram", 20000);
            dt.Rows.Add("0003", "Alice", 30000);
            dt.Rows.Add("0004", "David", 40000);
           
            Gridview1.DataSource = dt;
            Gridview1.DataBind();

        }

        protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

         
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                Label Amount = (Label)e.Row.FindControl("Label1");

                decimal Presents = Convert.ToDecimal(Amount.Text);
                total += Presents;

            }

            if (e.Row.RowType == DataControlRowType.Footer)
            {

                Label lblTotal = (Label)e.Row.FindControl("lblTotal");

                lblTotal.Text = total.ToString();

            }



        }
    }
}

Hope this helps.
Accepted