using iCore.Rtdb;
using iCore.Rtdb.RtdbTable;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
namespace Common
{
public class MemoryTableDataSocket
{
private CoredbClient cln = null;
//[Obsolete]
public MemoryTableDataSocket(string sPoint)
{ //""tarantool://guest@192.1.3.54:20"+计量点编号
try
{
cln = new CoredbClient(AppConfigCache.icoredbTcp);// + sPoint.Substring(3, 2));//计量网
}
catch (Exception ex)
{
WriteLog("MemoryTableData:" + cln);
}
}
public MemoryTableDataSocket(string sPoint, string serverUrl)
{ //""tarantool://guest@192.1.3.54:20"+计量点编号
try
{
cln = new CoredbClient(serverUrl);// + sPoint.Substring(3, 2));//计量网
}
catch (Exception ex)
{
WriteLog("MemoryTableData:" + cln);
}
}
#region 监控界面使用
///
/// 根据计量点取采集的值
/// CAR11PlcStauts PLC控制器状态 "0:初始值 数采服务器每隔2秒向PLC写入值1234;PLC会每隔2S不停用值4321覆盖"
/// CAR11MesWeight 上位机仪表重量 129160
/// HMI11LightWest HMI下发前红绿灯命令 "远控模式下:1、前红绿灯为绿灯;2、前红绿灯为红灯;"
/// CAR11LightWest 前红绿灯 "1、前红绿灯为绿灯;2、前红绿灯为红灯;"
/// CAR11LightEast 后红绿灯 "1、前红绿灯为绿灯;2、前红绿灯为红灯;"
/// HMI11CaptureWest HMI控制前抓拍触发信号 "0、不操作;1、HMI下发西边抓拍单元抓拍信号;"
/// HMI11CaptureEast HMI控制后抓拍触发信号 "0、不操作;1、HMI下发东边抓拍单元抓拍信号;"
/// HMI11ClearZero HMI下发仪表清零指令 1:HMI对仪表清零
/// CAR11StaticStatus 车辆检测 "0、东西方向激光均无报警; 1、过磅时,西边激光报警;2、过磅时,东边激光报警;3、过磅时,东西两边激光均报警"
/// CAR11InfraredWest 前车量检测状态 "1、前激光报警;2、前激光无报警;"
/// CAR11InfraredEast 后车量检测状态 "1、后激光报警;2、后激光无报警;"
/// CAR11ZeroWeightStatus 汽车空磅状态 0、其它,1、零点报警,红绿灯变红,
/// HMI11SwitchLight 红绿灯远控/自动 "1、远方切换开关处于自动控制位置;2、远方切换开关处于远方控制位置;远方切换方开关位于界面上"
/// CAR11SwitchLight PLC红绿灯控制模式状态 "PLC有三种控制模式:1、自动、2、远控;3、检修。 优先权从高到低:检修>远控>自动。PLC默认为自动控制,设2个切换开关,2个在远方操作人员在界面上,可完成远控/自动切换。一个开关在现场PLC控制箱中,可完成检修/自动切换。"
/// CAR11VlDirection 左红外光栅检测 1、光栅报警;2、光栅无报警
/// CAR11VlPLCWeight 右红外光栅检测 1、光栅报警;2、光栅无报警
///
public List getWarnInfo(string sPoint)
{
try
{
List ltn = (List)cln.CallRpc("LiveData:readByPointId", new object[] { sPoint });
return ltn;
}
catch (Exception ex)
{
WriteLog("读采集数据异常错误:" + ex.Message);
return null;
}
}
///
/// 写入控制表(道闸,仪表,红外,LED等)
///
/// 计量点
/// 操作类型
/// 被写入的信息
/// 用户编号
/// 异常信息接收
///
public bool writeWarnInfo(string sPoint, string OptionType, string value, string strUserID, out string errorInfo)
{
try
{
string strPntid = sPoint.Replace("CAR", "HMI") + OptionType;
cln.CallRpc("Control:doCommand", new object[] { strPntid, value, strUserID });
errorInfo = "";
return true;
}
catch (Exception ex)
{
WriteLog("写入信息到内存表异常!" + ex.Message);
errorInfo = "写入信息到内存表异常!" + ex.Message;
return false;
}
}
#endregion 监控界面使用
#region 计量主程序使用
///
/// 读取Live表 某个字段信息
///
///
/// CAR11
/// PowerStatus
/// JArray arr[0].Tagname, arr[0].Value, arr[0].DateTime, arr[0].Source
public JArray LiveTable(string PointIdKey, string TagName)
{
try
{
List arr = (List)cln.CallRpc("Live.Table:select", new object[] { PointIdKey + TagName });//读
if (arr != null && arr.Count > 0)
{
JArray jArray = new JArray(arr[0].Tagname, arr[0].Value, arr[0].DateTime, arr[0].Source);
return jArray;
}
return null;
}
catch (Exception exp)
{
WriteLog("LiveTable:" + exp.Message + exp.StackTrace);
return null;
}
}
///
/// 读取实时表,一个计量点只有一条数据(重量,稳定,红外,车号等信息)
///
///
/// 计量点编号
///
/// MemoryTableDataSocket MemoClass = new MemoryTableDataSocket(strPntNo);
/// JArray aryValue = MemoClass.TrackTable(strPntNo);//Track表数据每个计量点的数据
/// string pointId = aryValue[0]; string carNo = aryValue[1];
/// 对照如下:
/// 0 pointid 计量点 string CAR11,CAR12,CAR13等计量点编号
/// 1 status 车辆状态 number 0:等待车辆 1:车辆上称 2:重量不稳定 3:重量稳定 4:计量完成 5:下称
/// 2 carno 车号 string 鄂B23955
/// 3 weight 重量 number
/// 4 weightStatus 重量状态 number 0:重量稳定; 1:重量不稳定; 2:空磅
/// 5 parkStatus 停车状态 number 0:正常(头尾都未压线) 1:车头压线 2:车尾压线 3:两头压线; 记录在重量稳定后生成
/// 6 datetime 上称时间 uint 当前时间的距离1970.1.1.08:00时间的秒数; 秒
/// 7 LicType 车牌类型 number 0:车牌抓拍; 1:RFID 识别
/// 8 WeightSave 计量保存重量 uint
/// 9 FinishTime 过磅完成时间 uint 秒
/// 10 entry 入口 string East = 东边, West = 西边
/// 11 exit 出口 string East = 东边, West = 西边
/// 12 platenoList 抓拍车牌信息 array "{direct, plateno} direct:string 方向 plateno: string 车牌/电子车牌"
/// 13 rfidList RFID识别车牌信息 array "{direct, plateno} direct:string 方向plateno: string 车牌/电子车牌"
///
public JArray TrackTable(string PointIdKey)
{
try
{
Log.GetInstance().WriteLog(36, "开始读取数采实时库 车号:" + PbCache.lockCarNo + ";重量:" + PbCache.lockWgt + ";时间:" + DateTime.Now.ToLongTimeString());
List