1.用户需求和 功能初步规划
功能改造点确认
节点4 车牌识别和称重数据采集
4.1旧的称重软件 ,称重仪表 和 串口 设置
地磅接线图 : 地磅传感器==>(圆形电缆)=>称重仪表==(rs232)=>旧称重软件(串口)
4.2新的 自开发 称重界面
设备连接方式:车牌识别 : 臻识车牌识别摄像机 ===>办公网络===>称重系统(臻识摄像头SDK)
地磅采集: 地磅传感器===>(圆形电缆)=>称重仪表===>康耐得 rs232转以太网模块===>办公网络===>称重软件(tcpip协议)
车头车尾影像: TP-Link TL-IPC544H-W6 室外监控摄像头 ===>办公网络===>称重系统(onvif协议)
4.3称重画面连接 称重仪表获取 重量
Com1 波特率 9600 数据位 8 停止位 1 奇偶校验 无 连接到康耐得模块 康耐得模块ip 10.8.20.252 端口8000
byte[] recvData = new byte[1024 * 10];
TcpClient client = new TcpClient();
//连接
client.BeginConnect("10.8.20.252", 8000, ConnectCallBack, client);
#region 连接康耐得模块 采集地磅数据
private void ConnectCallBack(IAsyncResult result)
{
TcpClient client = result.AsyncState as TcpClient;
try
{
client.EndConnect(result);
}
catch (Exception ex)
{
Console.WriteLine("which is " + ex.ToString());
return;
}
client.Client.BeginReceive(recvData, 0, recvData.Length, SocketFlags.None, RecvCallBack, client);
}
public void RecvCallBack(IAsyncResult result)
{
int count = -1;
try
{
count = client.Client.EndReceive(result);
}
catch (Exception ex)
{
//Console.WriteLine("远程计算机关闭");
return;
}
string msg = Encoding.ASCII.GetString(recvData, 0, count);
//Console.WriteLine("接到消息:");
//Console.WriteLine(msg);
SetText(msg);
client.Client.BeginReceive(recvData, 0, recvData.Length, SocketFlags.None, RecvCallBack, client);
}
private delegate void SetTextCallback(string text);
private void SetText(string text)
{
// InvokeRequired需要比较调用线程ID和创建线程ID
// 如果它们不相同则返回true
if (this.textBox6.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
char[] arr = text.ToCharArray();
Array.Reverse(arr);
text = new string(arr);
this.textBox6.Text = text;
listBox1.Items.Insert(0, DateTime.Now + "地磅重量" + text);
}
}
#endregion
4.4称重画面 连接 摄像头获取车牌照号
short nPort = Int16.Parse(txtPort.Text);
int handle = VzClientSDK.VzLPRClient_Open(txtIP.Text, (ushort)nPort, txtUserName.Text, txtPwd.Text);
if (handle == 0)
{
MessageBox.Show("打开设备失败!");
return;
}
protected override void DefWndProc(ref Message m)
{
IntPtr intptr;
VzClientSDK.VZ_LPR_MSG_PLATE_INFO plateInfo;
VzClientSDK.VZ_LPR_DEVICE_INFO deviceInfo;
int handle = 0;
switch (m.Msg)
{
case MSG_PLATE_INFO:
intptr = (IntPtr)m.WParam.ToInt32();
handle = m.LParam.ToInt32();
if (intptr != null)
{
plateInfo = (VzClientSDK.VZ_LPR_MSG_PLATE_INFO)Marshal.PtrToStructure(intptr, typeof(VzClientSDK.VZ_LPR_MSG_PLATE_INFO));
if (handle == GetPicBox1Handle())
{
// 显示车牌号
if (plateInfo.plate != "")
{
lblPlate.Text = plateInfo.plate;
textBoxX1.Text = plateInfo.plate;
listBox1.Items.Insert(0, lblPlate.Text);
msg(lblPlate.Text);
}
}
Marshal.FreeHGlobal(intptr);
}
break;
case MSG_DEVICE_INFO:
intptr = (IntPtr)m.WParam.ToInt32();
if (intptr != null)
{
deviceInfo = (VzClientSDK.VZ_LPR_DEVICE_INFO)Marshal.PtrToStructure(intptr, typeof(VzClientSDK.VZ_LPR_DEVICE_INFO));
ShowDevice(deviceInfo.device_ip, deviceInfo.serial_no);
Marshal.FreeHGlobal(intptr);
}
break;
default:
base.DefWndProc(ref m);
break;
}
}
4.5连接监控摄像头进行拍照,使用的EmguCV 组件 ,摄像头是 onvif协议
Install-Package EmguCV -Version 3.1.0.1
获取监控图像代码如下
string url = "rtsp://admin:admin@10.8.5.105:554/stream1";
Mat mat = new Mat();
Capture capture;
Thread GetImage;
Control.CheckForIllegalCrossThreadCalls = false;
GetImage = new Thread(GetFpsImg);
GetImage.Start();
private void GetFpsImg()
{
capture = new Capture(url);
while (true)
{
try
{
bool grab = capture.Grab();
bool isSuccess = capture.Retrieve(mat);
Thread.Sleep(130);
ParentpictureBox.Image = mat;//1080*1920
imageBox1.Image = mat;//1080*1920
}
catch (Exception)
{
}
}
}
摄像头安装方位
4.6程序逻辑
4.5.1车辆到到地磅指定位置 则车牌号自动填充到 车牌文本框 ;
4.5.2送货单号通过 弹窗 选择 取自 erp 800环境 (客户端需要安装hana驱动 "必须安装hana_odbc驱动_X86_64_20190112.zip")
select ekko.bedat, ekpo.ebeln, ekpo.ebelp, ekko.lifnr, lfa1.name1, ekpo.matnr, makt.maktx, ekpo.menge, t1.wemng
from saphanadb.ekpo
left join saphanadb.ekko on ekpo.ebeln = ekko.ebeln
left join saphanadb.makt on ekpo.matnr = makt.matnr
and makt.spras = '1'
left join saphanadb.lfa1 on ekko.lifnr = lfa1.lifnr
left join (select eket.ebeln, eket.ebelp, sum(eket.wemng) as wemng from saphanadb.eket group by eket.ebeln, eket.ebelp) as t1 on ekpo.ebeln =
t1.ebeln
and
ekpo.ebelp =
t1.ebelp
where saphanadb.ekpo.matnr = '000000001000017077'
and ekpo.menge > t1.wemng
order by ekko.bedat, ekpo.ebeln, ekpo.ebelp
4.5.3 通过上面的步骤 带出 送货单对应供应商
4.5.4物料号 需要按实际送货物料号由用户按实际送货情况选择,自动带出 品名规格
4.5.5 当 重量数据稳定了后 点重量写入 保存到数据库 ,同时 加入到下方表格第一行
节点5 水分检测/颗粒度检测 app
5.1
水分采用设备采集方式连接到系统
水分仪==(串口)è康耐得模块=è办公网络
数据采集采用一致独立的程序 放在服务器,水分仪测试完成 会主动上报报文给串口, 从而采集程序能自动拿到这个信息,然后保存到数据库即可
5.2
App中点采集
(未完待续)
点击加入群聊【SAP_MES行业交流】