[0001]利用超级终端原理实现波特Perten检测仪、福斯Foss近红外的数据与外围系统集成打通

    近期集团购置了一批取样检测的近红外设备,但由于是老外的设备,在国内没有提供二开和集成的技术支持,所以只能靠自己摸索,由于之前搞过利用超级终端工具读取地磅的数据,这次同样利用了超级终端原理,花费大概2周时间,实现了设备与外围系统集成,现将实现关键点分享如下:

1.网上购置串口数据线

2.整体方案设计

3.波特Perten检测仪核心代码实现

 1         void sp1_DataReceived(object sender, SerialDataReceivedEventArgs e)
 2         {
 3             if (sp1.IsOpen)
 4             {
 5                 txtReceive.SelectAll();
 6                 txtReceive.SelectionColor = Color.Blue;         //改变字体的颜色
 7 
 8                 if (rdSendStr.Checked)                          //'发送字符串'单选按钮
 9                 {
10                     byte[] byteRead = new byte[sp1.BytesToRead];    //BytesToRead:sp1接收的字符个数
11                     txtReceive.Text = sp1.ReadLine();
12                     string strData = txtReceive.Text;
13                     string[] mm = Regex.Split(strData, "\\s+", RegexOptions.IgnoreCase);
14                     txtBillCode.Text = mm[3];
15                     txtsf.Text = mm[4];
16                     txtrz.Text = mm[5];
17                     txtWD.Text = mm[6];
18 
19                     if (cbTimeSend.Checked)
20                     {
21                         int i = 0;
22                         SCModel model = new SCModel();
23 
24                         model.id = Guid.NewGuid().ToString();
25                         model.corpid = txtCorpId.Text;
26                         model.corpname = txtCorpName.Text;
27                         model.mb = Convert.ToDouble(txtMB.Text);
28                         model.rss = Convert.ToDouble(txtRSS.Text);
29                         model.zz = Convert.ToDouble(txtZZ.Text);
30 
31                         model.bz = txtReceive.Text;
32                         model.checkdate = DateTime.Now.ToString("yyyy-MM-dd");
33                         model.checktime = model.checkdate + " " + mm[1];
34                         model.billcode = txtBillCode.Text;
35                         model.sf = Convert.ToDouble(txtsf.Text);
36                         model.rz = Convert.ToDouble(txtrz.Text)*10;
37                         model.wd = Convert.ToDouble(txtWD.Text);
38 
39                         try
40                         {
41                             string strSql = "insert into sbt_sc5200 (id,"
42                                                                   + "weak,"
43                                                                   + "corpname,"
44                                                                   + "checkdate,"
45                                                                   + "analysistime,"
46                                                                   + "samplenumber,"
47                                                                   + "Moisture,"
48                                                                   + "RongZ,"
49                                                                   + "WD,"
50                                                                   + "MeiB,"
51                                                                   + "ReSSL,"
52                                                                   + "ZaZhi,"
53                                                                   + "bz) "
54                                                                   + "values ('" + model.id + "','"
55                                                                   + model.corpid + "',N'"
56                                                                   + model.corpname + "','"
57                                                                   + model.checkdate + "','"
58                                                                   + model.checktime + "','"
59                                                                   + model.billcode + "',"
60                                                                   + model.sf + ","
61                                                                   + model.rz + ","
62                                                                   + model.wd + ","
63                                                                   + model.mb + ","
64                                                                   + model.rss + ","
65                                                                   + model.zz + ",'"
66                                                                   + model.bz + "')";
67                             i = DBUtility.DbHelperSQL.ExecuteSql(strSql);
68                             if (i > 0)
69                             {
70                                 txtSend.Text = "单据" + model.billcode + "检测值成功上传Mosaic平台";
71                             }
72                             else
73                             {
74                                 txtSend.Text = "单据" + model.billcode + "检测值上传Mosaic平台失败";
75                             }
76                         }
77                         catch (Exception ex)
78                         {
79                             txtSend.Text = "单据" + model.billcode + "检测值上传Mosaic平台失败,错误为:" + ex.ToString();
80                         }
81                     }
82                     sp1.DiscardInBuffer();                      //清空SerialPort控件的Buffer 
83                 }
84             }
85             else
86             {
87                 MessageBox.Show("请打开某个串口", "错误提示");
88             }
89         }
View Code

4.福斯Foss近红外核心代码实现

1             string serverName = "192.168.10.XXX";//改为实际IP
2             int serverPort = "8000";
3             string userLogin = "foss";
4             string userPassword = "123456";//改为实际密码
5             IntegrationClient serverProxy = new IntegrationClient();
6             Result connectionResult = serverProxy.InitializeConnection(serverName, serverPort, userLogin, userPassword, "MosaicSystem42");
View Code

5.运行效果

posted @ 2020-09-07 00:07  花椒开发笔记  阅读(445)  评论(0)    收藏  举报