123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using EasyModbusClient.businessBody;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using YG.Device;
- namespace IMCS.Device
- {
- public class DeviceRfid
- {
- private static DeviceRfid deviceRfid = new DeviceRfid();
- public static DeviceRfid Instance { get { return deviceRfid; } }
- /// <summary>
- ///
- /// </summary>
- /// <param name="url"></param>
- /// <param name="rfidvalue">rfid需要写入的值</param>
- /// <param name="rfidaddress">FFID写入的地址</param>
- /// <param name="writeswitchaddress">写入开关</param>
- private void RfidWrite(DeviceList url, string rfidvalue, string rfidaddress, string writeswitchaddress)
- {
- url.DeviceSend(rfidaddress, rfidvalue.ReturnBtyesWtitString(80));
- System.Threading.Thread.Sleep(1000);
- short mc = 1;
- url.DeviceSend(writeswitchaddress, mc);
- System.Threading.Thread.Sleep(1000);
- mc = 0;
- url.DeviceSend(writeswitchaddress, mc);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="device"></param>
- /// <param name="readswitchrfidaddress">读取的开关</param>
- /// <param name="startaddress"需要读取的地址</param>
- /// <returns></returns>
- private string RfidRead(DeviceList device, string readswitchrfidaddress, string startaddress)
- {
- string value = "";
- short mc = 1;
- device.DeviceSend(readswitchrfidaddress, mc);
- System.Threading.Thread.Sleep(1000);
- mc = 0;
- device.DeviceSend(readswitchrfidaddress, mc);
- System.Threading.Thread.Sleep(1000);
- value =Encoding.ASCII.GetString( device.DeviceRead<byte[]>(startaddress,80)).Replace("\0","");
- return value;
- }
- public bool DeviceSend(List<RfidDefaultList> rfid, string url)
- {
- bool result = false;
- DeviceList device = YG.DeviceManage.Instance.GetOne(url);
- if (rfid.Count > 0 && device != null)
- {
- rfid.ForEach((m) =>
- {
- short mc = 0;
- if (m.index.Equals(1))
- {
- RfidWrite(device, m.val, "DB200.1304.0", "DB200.114");
- //device.DeviceSend("DB200.372", m.val.ReturnBtyesWtitString(256));
- //System.Threading.Thread.Sleep(300);
- //mc = 1;
- //device.DeviceSend("DB200.114", mc);
- //System.Threading.Thread.Sleep(300);
- //mc = 0;
- //device.DeviceSend("DB200.114", mc);
- }
- else
- {
- RfidWrite(device, m.val, "DB200.1384.0", "DB200.630");
- //device.DeviceSend("DB200.888", m.val.ReturnBtyesWtitString(256));
- //System.Threading.Thread.Sleep(300);
- //mc = 1;
- //device.DeviceSend("DB200.630", mc);
- //System.Threading.Thread.Sleep(300);
- //mc = 0;
- //device.DeviceSend("DB200.630", mc);
- }
- result = true;
- });
- }
- return result;
- }
- public List<RfidDefaultList> DeviceRead(string url)
- {
- List<RfidDefaultList> list = new List<RfidDefaultList>();
- bool result = false;
- DeviceList device = YG.DeviceManage.Instance.GetOne(url);
- if (device != null)
- {
- {
- list.Add(new RfidDefaultList() { index = 1, val = RfidRead(device, "DB200.112", "DB200.1144.0") });
- list.Add(new RfidDefaultList() { index = 2, val = RfidRead(device, "DB200.628", "DB200.1224.0") });
-
- }
- }
- return list;
- }
- }
- }
|