12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112 |
- using Sunny.UI;
- using System;
- using System.Collections;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace HRT_Measure
- {
- public class ReadPLCHelp
- {
- public static WindowDisplay EnumWindowDisplay = WindowDisplay.主界面;
- public static Dictionary<string ,string> dictM01 = new Dictionary<string ,string>();
- public static Dictionary<string, string> dictM02 = new Dictionary<string, string>();
- public static Dictionary<string, string> dictM04 = new Dictionary<string, string>();
- public static Thread thReadPLCM01M02 = new Thread(new ThreadStart(ThReadPLCM01M02));
- public static Thread thReadPLCM03 = new Thread(new ThreadStart(ThReadPLCM03));
- public static Thread thReadPLCM04M05 = new Thread(new ThreadStart(ThReadPLCM04M05));
- public static Thread thPressure = new Thread(new ThreadStart(ThPressure));
- public static int iM01M02IOStation = 0;
- public static int iM03IOStation = 0;
- public static int iM04M05IOStation = 0;
- public static int iM01M02AxisStation = 0;
- public static int iM03AxisStation = 0;
- public static int iM04M05AxisStation = 0;
- //public static bool isM01M02Show = false;
- //public static bool isM03Show = false;
- //public static bool isM04M05Show = false;
- //public static bool isWeightShow = false;
- //压机
- public static List<string> listPressureStr = new List<string>();
- public static Dictionary<string, ClsPressure> dictPressure = new Dictionary<string, ClsPressure>();
- public static string str主缸当前位置 = "";
- public static string str主缸当前压力 = "";
- //public static bool is记录保压数据 = false;
- public static ConcurrentQueue<short> queuePressureSignals = new ConcurrentQueue<short>();
- public static UpTrigger upTrigger = new UpTrigger();
- //称重
- public static string strWeightStartAdd = "DB136.502.4";//称重开始信号
- //public static bool isWeightStart = false;
- public static string[] arrWeightStartSignalsAdd = new string[10] { "DB31.0", "DB31.2", "DB31.4", "DB31.6", "DB31.8", "DB31.10", "DB31.12", "DB31.14", "DB31.16", "DB31.18" };
- public static short[] arrShortWeightStart = new short[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- public static string[] arrWeightDoneAdd = new string[10] { "DB31.20", "DB31.24", "DB31.28", "DB31.32", "DB31.36", "DB31.40", "DB31.44", "DB31.48", "DB31.52", "DB31.56" };
- public static string[] arrWeightDoneStatus = new string[10] { "DB31.60", "DB31.62", "DB31.64", "DB31.66", "DB31.68", "DB31.70", "DB31.72", "DB31.74", "DB31.76", "DB31.78" };
- //public static int[] arrWeightValue = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- public static void GetPressureInfo()
- {
- listPressureStr.Clear();
- #region MyRegion
- listPressureStr.Add("当前产品型号, D1000, short, 1");
- listPressureStr.Add("主缸当前压力设定,D78,short,0.1");
- listPressureStr.Add("主缸当前流量设定,D80,short,1");
- listPressureStr.Add("主缸当前位置,D62,short,0.1");
- listPressureStr.Add("主缸当前压力,D34,short,0.1");
- listPressureStr.Add("工件计数,D90,short,1");
- listPressureStr.Add("当前动作,D100,short,1");
- listPressureStr.Add("操作提示,D1,short,1");
- listPressureStr.Add("当前模式提示,D3,short,1");
- listPressureStr.Add("步骤1油缸压力设定1,D220,short,0.1");
- listPressureStr.Add("步骤1油缸保压时间设定1,D221,short,0.1");
- listPressureStr.Add("步骤2油缸压力设定1,D222,short,0.1");
- listPressureStr.Add("步骤2油缸保压时间设定1,D223,short,0.1");
- listPressureStr.Add("步骤3油缸压力设定1,D224,short,0.1");
- listPressureStr.Add("步骤3油缸保压时间设定1,D225,short,0.1");
- listPressureStr.Add("步骤1停止顶出位置设定1,D300,short,0.1");
- listPressureStr.Add("步骤1减速顶出位置设定1,D301,short,0.1");
- listPressureStr.Add("步骤2停止顶出位置设定1,D302,short,0.1");
- listPressureStr.Add("步骤2减速顶出位置设定1,D303,short,0.1");
- listPressureStr.Add("步骤3停止顶出位置设定1,D304,short,0.1");
- listPressureStr.Add("步骤3减速顶出位置设定1,D305,short,0.1");
- listPressureStr.Add("步骤1油缸压力设定2,D226,short,0.1");
- listPressureStr.Add("步骤1油缸保压时间设定2,D227,short,0.1");
- listPressureStr.Add("步骤2油缸压力设定2,D228,short,0.1");
- listPressureStr.Add("步骤2油缸保压时间设定2,D229,short,0.1");
- listPressureStr.Add("步骤3油缸压力设定2,D230,short,0.1");
- listPressureStr.Add("步骤3油缸保压时间设定2,D231,short,0.1");
- listPressureStr.Add("步骤1停止顶出位置设定2,D306,short,0.1");
- listPressureStr.Add("步骤1减速顶出位置设定2,D307,short,0.1");
- listPressureStr.Add("步骤2停止顶出位置设定2,D308,short,0.1");
- listPressureStr.Add("步骤2减速顶出位置设定2,D309,short,0.1");
- listPressureStr.Add("步骤3停止顶出位置设定2,D310,short,0.1");
- listPressureStr.Add("步骤3减速顶出位置设定2,D311,short,0.1");
- listPressureStr.Add("步骤1油缸压力设定3,D232,short,0.1");
- listPressureStr.Add("步骤1油缸保压时间设定3,D233,short,0.1");
- listPressureStr.Add("步骤2油缸压力设定3,D234,short,0.1");
- listPressureStr.Add("步骤2油缸保压时间设定3,D235,short,0.1");
- listPressureStr.Add("步骤3油缸压力设定3,D236,short,0.1");
- listPressureStr.Add("步骤3油缸保压时间设定3,D237,short,0.1");
- listPressureStr.Add("步骤1停止顶出位置设定3,D312,short,0.1");
- listPressureStr.Add("步骤1减速顶出位置设定3,D313,short,0.1");
- listPressureStr.Add("步骤2停止顶出位置设定3,D314,short,0.1");
- listPressureStr.Add("步骤2减速顶出位置设定3,D315,short,0.1");
- listPressureStr.Add("步骤3停止顶出位置设定3,D316,short,0.1");
- listPressureStr.Add("步骤3减速顶出位置设定3,D317,short,0.1");
- listPressureStr.Add("步骤1油缸压力设定4,D238,short,0.1");
- listPressureStr.Add("步骤1油缸保压时间设定4,D239,short,0.1");
- listPressureStr.Add("步骤2油缸压力设定4,D240,short,0.1");
- listPressureStr.Add("步骤2油缸保压时间设定4,D241,short,0.1");
- listPressureStr.Add("步骤3油缸压力设定4,D242,short,0.1");
- listPressureStr.Add("步骤3油缸保压时间设定4,D243,short,0.1");
- listPressureStr.Add("步骤1停止顶出位置设定4,D318,short,0.1");
- listPressureStr.Add("步骤1减速顶出位置设定4,D319,short,0.1");
- listPressureStr.Add("步骤2停止顶出位置设定4,D320,short,0.1");
- listPressureStr.Add("步骤2减速顶出位置设定4,D321,short,0.1");
- listPressureStr.Add("步骤3停止顶出位置设定4,D322,short,0.1");
- listPressureStr.Add("步骤3减速顶出位置设定4,D323,short,0.1");
- listPressureStr.Add("步骤1油缸压力设定5,D244,short,0.1");
- listPressureStr.Add("步骤1油缸保压时间设定5,D245,short,0.1");
- listPressureStr.Add("步骤2油缸压力设定5,D246,short,0.1");
- listPressureStr.Add("步骤2油缸保压时间设定5,D247,short,0.1");
- listPressureStr.Add("步骤3油缸压力设定5,D248,short,0.1");
- listPressureStr.Add("步骤3油缸保压时间设定5,D249,short,0.1");
- listPressureStr.Add("步骤1停止顶出位置设定5,D324,short,0.1");
- listPressureStr.Add("步骤1减速顶出位置设定5,D325,short,0.1");
- listPressureStr.Add("步骤2停止顶出位置设定5,D326,short,0.1");
- listPressureStr.Add("步骤2减速顶出位置设定5,D327,short,0.1");
- listPressureStr.Add("步骤3停止顶出位置设定5,D328,short,0.1");
- listPressureStr.Add("步骤3减速顶出位置设定5,D329,short,0.1");
- listPressureStr.Add("步骤1油缸压力设定6,D250,short,0.1");
- listPressureStr.Add("步骤1油缸保压时间设定6,D251,short,0.1");
- listPressureStr.Add("步骤2油缸压力设定6,D252,short,0.1");
- listPressureStr.Add("步骤2油缸保压时间设定6,D253,short,0.1");
- listPressureStr.Add("步骤3油缸压力设定6,D254,short,0.1");
- listPressureStr.Add("步骤3油缸保压时间设定6,D255,short,0.1");
- listPressureStr.Add("步骤1停止顶出位置设定6,D330,short,0.1");
- listPressureStr.Add("步骤1减速顶出位置设定6,D331,short,0.1");
- listPressureStr.Add("步骤2停止顶出位置设定6,D332,short,0.1");
- listPressureStr.Add("步骤2减速顶出位置设定6,D333,short,0.1");
- listPressureStr.Add("步骤3停止顶出位置设定6,D334,short,0.1");
- listPressureStr.Add("步骤3减速顶出位置设定6,D335,short,0.1");
- listPressureStr.Add("快顶压力设定值,D340,short,0.1");
- listPressureStr.Add("快顶流量设定值,D341,short,1");
- listPressureStr.Add("慢顶压力设定值,D342,short,0.1");
- listPressureStr.Add("慢顶流量设定值,D343,short,1");
- listPressureStr.Add("慢退压力设定值,D344,short,0.1");
- listPressureStr.Add("慢退流量设定值,D345,short,1");
- listPressureStr.Add("快退压力设定值,D346,short,0.1");
- listPressureStr.Add("快退流量设定值,D347,short,1");
- listPressureStr.Add("空载压力设置,D348,short,0.1");
- listPressureStr.Add("空载流量设置,D349,short,1");
- #endregion
- dictPressure.Clear();
- for (int i = 0; i < listPressureStr.Count; i++)
- {
- ClsPressure clsPressure = new ClsPressure(listPressureStr[i]);
- dictPressure.Add(clsPressure.Name, clsPressure);
- }
- queuePressureSignals.Clear();
- }
- public static void LoadPLCAdd()
- {
- dictM01.Clear();
- dictM02.Clear();
- dictM04.Clear();
- dictPressure.Clear();
- #region M01M02M04M05
- //M01
- dictM01.Add("药A暂存当前盒数", "DB20.476");
- dictM01.Add("药B暂存当前盒数", "DB20.478");
- dictM01.Add("抛盖暂存槽当前数量", "DB20.492");
- dictM01.Add("空桶暂存槽当前数量", "DB20.490");
- //M02
- dictM02.Add("药A称重配比重量", "DB14.20");
- dictM02.Add("A料仓1当前重量", "DB20.76");
- dictM02.Add("A料仓2当前重量", "DB20.80");
- dictM02.Add("A料仓3当前重量", "DB20.84");
- dictM02.Add("A料仓4当前重量", "DB20.88");
- dictM02.Add("A料仓5当前重量", "DB20.92");
- dictM02.Add("药B称重配比重量", "DB14.24");
- dictM02.Add("B料仓1当前重量", "DB20.96");
- dictM02.Add("B料仓2当前重量", "DB20.100");
- dictM02.Add("B料仓3当前重量", "DB20.104");
- dictM02.Add("B料仓4当前重量", "DB20.108");
- dictM02.Add("B料仓5当前重量", "DB20.112");
- //M04
- dictM04.Add("允许下料", "DB186.26.0");
- dictM04.Add("当前检测高度", "DB31.50");
- dictM04.Add("当前重量", "DB31.8");
- dictM04.Add("产品高度", "DB80.0");
- dictM04.Add("产品重量", "DB80.4");
- dictM04.Add("相机结果", "DB80.8");
- dictM04.Add("废料数量", "DB80.12");
- dictM04.Add("合格数量", "DB80.16");
- dictM04.Add("盘数", "DB80.20");
- dictM04.Add("NG数量", "DB80.22");
- dictM04.Add("本次完成箱子数量", "DB80.26");
- dictM04.Add("产品信息打包上传", "DB80.40.0");
- #endregion
- GetPressureInfo();
- thReadPLCM01M02.IsBackground = true;
- thReadPLCM01M02.Start();
- thReadPLCM03.IsBackground = true;
- thReadPLCM03.Start();
- thReadPLCM04M05.IsBackground = true;
- thReadPLCM04M05.Start();
- thPressure.IsBackground = true;
- thPressure.Start();
- }
- #region GetValue
- #region M01M02
- public static void GetM01M02InitValue(PLCInitIO plcInitIO, CommPLC commPLC)
- {
- try
- {
- plcInitIO.isHandOrAuto = plcInitIO.HandOrAutoAdd != "" ? GetM01M02BoolValue(plcInitIO.HandOrAutoAdd, commPLC) : false;
- plcInitIO.isInitDone = plcInitIO.InitDoneAdd != "" ? GetM01M02BoolValue(plcInitIO.InitDoneAdd, commPLC) : false;
- plcInitIO.isAutoRunning = plcInitIO.AutoRunningAdd != "" ? GetM01M02BoolValue(plcInitIO.AutoRunningAdd, commPLC) : false;
- plcInitIO.isAlm = plcInitIO.AlmAdd != "" ? GetM01M02BoolValue(plcInitIO.AlmAdd, commPLC) : false;
- plcInitIO.isWait = plcInitIO.WaitAdd != "" ? GetM01M02BoolValue(plcInitIO.WaitAdd, commPLC) : false;
- plcInitIO.isBtnInit = plcInitIO.btnInitAdd != "" ? GetM01M02BoolValue(plcInitIO.btnInitAdd, commPLC) : false;
- plcInitIO.isBtnExceptionQuit = plcInitIO.btnExcetionQuitAdd != "" ? GetM01M02BoolValue(plcInitIO.btnExcetionQuitAdd, commPLC) : false;
- plcInitIO.isBtnStop = plcInitIO.btnStopAdd != "" ? GetM01M02BoolValue(plcInitIO.btnStopAdd, commPLC) : false;
- plcInitIO.isBtnStart = plcInitIO.btnStartAdd != "" ? GetM01M02BoolValue(plcInitIO.btnStartAdd, commPLC) : false;
- plcInitIO.isBtnHandOrAuto = plcInitIO.btnHandOrAutoAdd != "" ? GetM01M02BoolValue(plcInitIO.btnHandOrAutoAdd, commPLC) : false;
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- }
- public static void GetM01M02AlmValue(Dictionary <string,ClsAlm> dictAlm, CommPLC commPLC)
- {
- foreach (var item in dictAlm)
- {
- try
- {
- item.Value.isAlm = item.Value.AlmAdd != "" ? GetM01M02BoolValue(item.Value.AlmAdd, commPLC) : false;
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- }
- }
- public static void GetM01M02CylinderValue(Dictionary<string,ClsPLCIO> dictIO, CommPLC commPLC)
- {
- foreach (var item in dictIO)
- {
- try
- {
- item.Value.isLedResetOn = item.Value.LedResetAdd != "" ? GetM01M02BoolValue(item.Value.LedResetAdd, commPLC) : false ;
- item.Value.isLedSetOn = item.Value.LedSetAdd != "" ? GetM01M02BoolValue(item.Value.LedSetAdd, commPLC): false;
- item.Value.isSensorResetOn = item.Value.SensorResetAdd != "" ? GetM01M02BoolValue(item.Value.SensorResetAdd, commPLC): false;
- item.Value.isSensorSetOn = item.Value.SensorSetAdd != "" ? GetM01M02BoolValue(item.Value.SensorSetAdd, commPLC): false;
- item.Value.isResetEnableOn = item.Value.ResetEnableAdd != "" ? GetM01M02BoolValue(item.Value.ResetEnableAdd, commPLC): false;
- item.Value.isSetEnableOn = item.Value.SetEnableAdd != "" ? GetM01M02BoolValue(item.Value.SetEnableAdd, commPLC): false;
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- //Thread.Sleep(1);
- }
- }
- public static void GetM01M02AxisPos(Dictionary<string,ClsAxisPos> dictAxisPos,CommPLC commPLC)
- {
- try
- {
- foreach (var item in dictAxisPos)
- {
- item.Value.isLightOn = item.Value.LightAdd != "" ? GetM01M02BoolValue(item.Value.LightAdd, commPLC) : false;
- commPLC.ReadUshort(item.Value.GoAdd, out item.Value.GoCurrValue,out string str );
- //Thread.Sleep(1);
- }
- }
- catch (Exception )
- {
- // MessageBox.Show(ex.ToString());
- }
- }
- public static void GetM01M02Axis(ClsAxis dictAxis, CommPLC commPLC)
- {
- try
- {
- dictAxis.is使能完成 = dictAxis.使能完成 != "" ? GetM01M02BoolValue(dictAxis.使能完成, commPLC) : false;
- dictAxis.is运行允许 = dictAxis.运行允许 != "" ? GetM01M02BoolValue(dictAxis.运行允许, commPLC) : false;
- dictAxis.is异常 = dictAxis.异常 != "" ? GetM01M02BoolValue(dictAxis.异常, commPLC) : false;
- dictAxis.isPositiveLimitOn = dictAxis.正极限 != "" ? GetM01M02BoolValue(dictAxis.正极限, commPLC) : false;
- dictAxis.isOriginalLimitOn = dictAxis.原点 != "" ? GetM01M02BoolValue(dictAxis.原点, commPLC) : false;
- dictAxis.isNegativeLimitOn = dictAxis.负极限 != "" ? GetM01M02BoolValue(dictAxis.负极限, commPLC) : false;
- dictAxis.is轴使能 = dictAxis.轴使能 != "" ? GetM01M02BoolValue(dictAxis.轴使能, commPLC) : false;
- dictAxis.i当前位置 = GetM01M02IntValue(dictAxis.当前位置, commPLC);
- dictAxis.s异常代码 = GetM01M02Int16Value(dictAxis.异常代码, commPLC);
- dictAxis.i点动速度 = GetM01M02IntValue(dictAxis.点动速度, commPLC);
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- }
- #endregion
- #region M03
- public static void GetM03InitValue(PLCInitIO plcInitIO, CommPLC commPLC)
- {
- try
- {
- plcInitIO.isHandOrAuto = plcInitIO.HandOrAutoAdd != "" ? GetM03BoolValue(plcInitIO.HandOrAutoAdd, commPLC) : false;
- plcInitIO.isInitDone = plcInitIO.InitDoneAdd != "" ? GetM03BoolValue(plcInitIO.InitDoneAdd, commPLC) : false;
- plcInitIO.isAutoRunning = plcInitIO.AutoRunningAdd != "" ? GetM03BoolValue(plcInitIO.AutoRunningAdd, commPLC) : false;
- plcInitIO.isAlm = plcInitIO.AlmAdd != "" ? GetM03BoolValue(plcInitIO.AlmAdd, commPLC) : false;
- plcInitIO.isWait = plcInitIO.WaitAdd != "" ? GetM03BoolValue(plcInitIO.WaitAdd, commPLC) : false;
- plcInitIO.isBtnInit = plcInitIO.btnInitAdd != "" ? GetM03BoolValue(plcInitIO.btnInitAdd, commPLC) : false;
- plcInitIO.isBtnExceptionQuit = plcInitIO.btnExcetionQuitAdd != "" ? GetM03BoolValue(plcInitIO.btnExcetionQuitAdd, commPLC) : false;
- plcInitIO.isBtnStop = plcInitIO.btnStopAdd != "" ? GetM03BoolValue(plcInitIO.btnStopAdd, commPLC) : false;
- plcInitIO.isBtnStart = plcInitIO.btnStartAdd != "" ? GetM03BoolValue(plcInitIO.btnStartAdd, commPLC) : false;
- plcInitIO.isBtnHandOrAuto = plcInitIO.btnHandOrAutoAdd != "" ? GetM03BoolValue(plcInitIO.btnHandOrAutoAdd, commPLC) : false;
- }
- catch (Exception)
- {
- //MessageBox.Show(ex.ToString());
- }
- }
- public static void GetM03AlmValue(Dictionary<string, ClsAlm> dictAlm, CommPLC commPLC)
- {
- foreach (var item in dictAlm)
- {
- try
- {
- item.Value.isAlm = item.Value.AlmAdd != "" ? GetM03BoolValue(item.Value.AlmAdd, commPLC) : false;
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- }
- }
- public static void GetM03CylinderValue(Dictionary<string, ClsPLCIO> dictIO, CommPLC commPLC)
- {
- foreach (var item in dictIO)
- {
- try
- {
- item.Value.isLedResetOn = item.Value.LedResetAdd != "" ? GetM03BoolValue(item.Value.LedResetAdd, commPLC) : false;
- item.Value.isLedSetOn = item.Value.LedSetAdd != "" ? GetM03BoolValue(item.Value.LedSetAdd, commPLC) : false;
- item.Value.isSensorResetOn = item.Value.SensorResetAdd != "" ? GetM03BoolValue(item.Value.SensorResetAdd, commPLC) : false;
- item.Value.isSensorSetOn = item.Value.SensorSetAdd != "" ? GetM03BoolValue(item.Value.SensorSetAdd, commPLC) : false;
- item.Value.isResetEnableOn = item.Value.ResetEnableAdd != "" ? GetM03BoolValue(item.Value.ResetEnableAdd, commPLC) : false;
- item.Value.isSetEnableOn = item.Value.SetEnableAdd != "" ? GetM03BoolValue(item.Value.SetEnableAdd, commPLC) : false;
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- //Thread.Sleep(1);
- }
- }
- public static void GetM03AxisPos(Dictionary<string, ClsAxisPos> dictAxisPos, CommPLC commPLC)
- {
- try
- {
- foreach (var item in dictAxisPos)
- {
- item.Value.isLightOn = item.Value.LightAdd != "" ? GetM03BoolValue(item.Value.LightAdd, commPLC) : false;
- commPLC.ReadUshort(item.Value.GoAdd, out item.Value.GoCurrValue, out string str);
- Thread.Sleep(1);
- }
-
- }
- catch (Exception )
- {
- // MessageBox.Show(ex.ToString());
- }
- }
- public static void GetM03Axis(ClsAxis dictAxis, CommPLC commPLC)
- {
- try
- {
- dictAxis.is使能完成 = dictAxis.使能完成 != "" ? GetM03BoolValue(dictAxis.使能完成, commPLC) : false;
- dictAxis.is运行允许 = dictAxis.运行允许 != "" ? GetM03BoolValue(dictAxis.运行允许, commPLC) : false;
- dictAxis.is异常 = dictAxis.异常 != "" ? GetM03BoolValue(dictAxis.异常, commPLC) : false;
- dictAxis.isPositiveLimitOn = dictAxis.正极限 != "" ? GetM03BoolValue(dictAxis.正极限, commPLC) : false;
- dictAxis.isOriginalLimitOn = dictAxis.原点 != "" ? GetM03BoolValue(dictAxis.原点, commPLC) : false;
- dictAxis.isNegativeLimitOn = dictAxis.负极限 != "" ? GetM03BoolValue(dictAxis.负极限, commPLC) : false;
- dictAxis.i当前位置 = GetM03IntValue(dictAxis.当前位置, commPLC);
- dictAxis.s异常代码 = GetM03Int16Value(dictAxis.异常代码, commPLC);
- dictAxis.i点动速度 = GetM03IntValue(dictAxis.点动速度, commPLC);
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- }
- #endregion
- #region M04M05
- public static void GetM04M05InitValue(PLCInitIO plcInitIO, CommPLC commPLC)
- {
- try
- {
- plcInitIO.isHandOrAuto = plcInitIO.HandOrAutoAdd != "" ? GetM04M05BoolValue(plcInitIO.HandOrAutoAdd, commPLC) : false;
- plcInitIO.isInitDone = plcInitIO.InitDoneAdd != "" ? GetM04M05BoolValue(plcInitIO.InitDoneAdd, commPLC) : false;
- plcInitIO.isAutoRunning = plcInitIO.AutoRunningAdd != "" ? GetM04M05BoolValue(plcInitIO.AutoRunningAdd, commPLC) : false;
- plcInitIO.isAlm = plcInitIO.AlmAdd != "" ? GetM04M05BoolValue(plcInitIO.AlmAdd, commPLC) : false;
- plcInitIO.isWait = plcInitIO.WaitAdd != "" ? GetM04M05BoolValue(plcInitIO.WaitAdd, commPLC) : false;
- plcInitIO.isBtnInit = plcInitIO.btnInitAdd != "" ? GetM04M05BoolValue(plcInitIO.btnInitAdd, commPLC) : false;
- plcInitIO.isBtnExceptionQuit = plcInitIO.btnExcetionQuitAdd != "" ? GetM04M05BoolValue(plcInitIO.btnExcetionQuitAdd, commPLC) : false;
- plcInitIO.isBtnStop = plcInitIO.btnStopAdd != "" ? GetM04M05BoolValue(plcInitIO.btnStopAdd, commPLC) : false;
- plcInitIO.isBtnStart = plcInitIO.btnStartAdd != "" ? GetM04M05BoolValue(plcInitIO.btnStartAdd, commPLC) : false;
- plcInitIO.isBtnHandOrAuto = plcInitIO.btnHandOrAutoAdd != "" ? GetM04M05BoolValue(plcInitIO.btnHandOrAutoAdd, commPLC) : false;
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- }
- public static void GetM04M05AlmValue(Dictionary<string, ClsAlm> dictAlm, CommPLC commPLC)
- {
- foreach (var item in dictAlm)
- {
- try
- {
- item.Value.isAlm = item.Value.AlmAdd != "" ? GetM04M05BoolValue(item.Value.AlmAdd, commPLC) : false;
- }
- catch (Exception )
- {
- // MessageBox.Show(ex.ToString());
- }
- }
- }
- public static void GetM04M05CylinderValue(Dictionary<string, ClsPLCIO> dictIO, CommPLC commPLC)
- {
- foreach (var item in dictIO)
- {
- try
- {
- item.Value.isLedResetOn = item.Value.LedResetAdd != "" ? GetM04M05BoolValue(item.Value.LedResetAdd, commPLC) : false;
- item.Value.isLedSetOn = item.Value.LedSetAdd != "" ? GetM04M05BoolValue(item.Value.LedSetAdd, commPLC) : false;
- item.Value.isSensorResetOn = item.Value.SensorResetAdd != "" ? GetM04M05BoolValue(item.Value.SensorResetAdd, commPLC) : false;
- item.Value.isSensorSetOn = item.Value.SensorSetAdd != "" ? GetM04M05BoolValue(item.Value.SensorSetAdd, commPLC) : false;
- item.Value.isResetEnableOn = item.Value.ResetEnableAdd != "" ? GetM04M05BoolValue(item.Value.ResetEnableAdd, commPLC) : false;
- item.Value.isSetEnableOn = item.Value.SetEnableAdd != "" ? GetM04M05BoolValue(item.Value.SetEnableAdd, commPLC) : false;
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- //Thread.Sleep(1);
- }
- }
- public static void GetM04M05AxisPos(Dictionary<string, ClsAxisPos> dictAxisPos, CommPLC commPLC)
- {
- try
- {
- foreach (var item in dictAxisPos)
- {
- item.Value.isLightOn = item.Value.LightAdd != "" ? GetM04M05BoolValue(item.Value.LightAdd, commPLC) : false;
- commPLC.ReadUshort(item.Value.GoAdd, out item.Value.GoCurrValue, out string str);
- //Thread.Sleep(1);
- }
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- }
- public static void GetM04M05Axis(ClsAxis dictAxis, CommPLC commPLC)
- {
- try
- {
- dictAxis.is使能完成 = dictAxis.使能完成 != "" ? GetM04M05BoolValue(dictAxis.使能完成, commPLC) : false;
- dictAxis.is运行允许 = dictAxis.运行允许 != "" ? GetM04M05BoolValue(dictAxis.运行允许, commPLC) : false;
- dictAxis.is异常 = dictAxis.异常 != "" ? GetM04M05BoolValue(dictAxis.异常, commPLC) : false;
- dictAxis.isPositiveLimitOn = dictAxis.正极限 != "" ? GetM04M05BoolValue(dictAxis.正极限, commPLC) : false;
- dictAxis.isOriginalLimitOn = dictAxis.原点 != "" ? GetM04M05BoolValue(dictAxis.原点, commPLC) : false;
- dictAxis.isNegativeLimitOn = dictAxis.负极限 != "" ? GetM04M05BoolValue(dictAxis.负极限, commPLC) : false;
- dictAxis.i当前位置 = GetM04M05IntValue(dictAxis.当前位置, commPLC);
- dictAxis.s异常代码 = GetM04M05Int16Value(dictAxis.异常代码, commPLC);
- dictAxis.i点动速度 = GetM04M05IntValue(dictAxis.点动速度, commPLC);
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- }
- #endregion
- #endregion
- private static void ThReadPLCM01M02()
- {
- while(true)
- {
- if(!ProgramHelp.Instance.commPLC_M01M02.isPLCConnected)
- {
- Thread.Sleep(5);
- continue;
- }
- GetM01M02InitValue(PLCCylinder.dictPLC_InitIO["M01M02"], ProgramHelp.Instance.commPLC_M01M02);
- foreach (var itemM01 in dictM01)
- {
- short sResult = GetM01M02Int16Value(itemM01.Value, ProgramHelp.Instance.commPLC_M01M02);
- SetM01Result(sResult, itemM01.Key);
- }
- //foreach (var itemM02 in dictM02)
- //{
- // short sResult = GetM01M02Int16Value(itemM02.Value, ProgramHelp.Instance.commPLC_M01M02);
- // SetM02Result(sResult, itemM02.Key);
- //}
- PLCResultHelp.isM01_清料 = GetM01M02BoolValue("DB20.496.0", ProgramHelp.Instance.commPLC_M01M02);
- for (int i = 0; i < 10; i++)
- {
- arrShortWeightStart[i] = GetM01M02Int16Value(arrWeightStartSignalsAdd[i], ProgramHelp.Instance.commPLC_M01M02);
- }
- PLCResultHelp.isM01_称重开始 = GetM01M02BoolValue(strWeightStartAdd, ProgramHelp.Instance.commPLC_M01M02);
- //if (PLCResultHelp.isM01_称重开始)
- //{
-
- //}
- foreach (var itemM02 in dictM02)
- {
- int iResult = GetM01M02IntValue(itemM02.Value, ProgramHelp.Instance.commPLC_M01M02);
- SetM02Result(iResult, itemM02.Key);
- }
- GetM01M02AlmValue(PLCCylinder.dictM01M02_Alm, ProgramHelp.Instance.commPLC_M01M02);//
- if (EnumWindowDisplay != WindowDisplay.上料称重房)
- {
- Thread.Sleep(2);
- continue;
- }
- try
- {
- //ClsWeightHelp.GetWeightValue();//称重房
- if (EnumWindowDisplay == WindowDisplay.上料称重房)
- {
- switch (iM01M02IOStation)
- {
- case 0:
- GetM01M02CylinderValue(PLCCylinder.dictM01M02_上料工位, ProgramHelp.Instance.commPLC_M01M02);
- break;
- case 1:
- GetM01M02CylinderValue(PLCCylinder.dictM01M02_取出工位, ProgramHelp.Instance.commPLC_M01M02);
- break;
- case 2:
- GetM01M02CylinderValue(PLCCylinder.dictM01M02_提升机工位, ProgramHelp.Instance.commPLC_M01M02);
- break;
- case 3:
- GetM01M02CylinderValue(PLCCylinder.dictM01M02_称重工位, ProgramHelp.Instance.commPLC_M01M02);
- break;
- case 4:
- GetM01M02CylinderValue(PLCCylinder.dictM01M02_出口工位, ProgramHelp.Instance.commPLC_M01M02);
- break;
- }
- switch(iM01M02AxisStation)
- {
- case 0:
- GetM01M02AxisPos(PLCAxisPos.dictM01M02_取料X轴, ProgramHelp.Instance.commPLC_M01M02);
- GetM01M02Axis(PLCAxis.dictM01M02_轴["取料X轴"], ProgramHelp.Instance.commPLC_M01M02);
- break;
- case 1:
- GetM01M02AxisPos(PLCAxisPos.dictM01M02_取料Y轴, ProgramHelp.Instance.commPLC_M01M02);
- GetM01M02Axis(PLCAxis.dictM01M02_轴["取料Y轴"], ProgramHelp.Instance.commPLC_M01M02);
- break;
- case 2:
- GetM01M02AxisPos(PLCAxisPos.dictM01M02_取料Z轴, ProgramHelp.Instance.commPLC_M01M02);
- GetM01M02Axis(PLCAxis.dictM01M02_轴["取料Z轴"], ProgramHelp.Instance.commPLC_M01M02);
- break;
- case 3:
- GetM01M02AxisPos(PLCAxisPos.dictM01M02_取料R轴, ProgramHelp.Instance.commPLC_M01M02);
- GetM01M02Axis(PLCAxis.dictM01M02_轴["取料R轴"], ProgramHelp.Instance.commPLC_M01M02);
- break;
- case 4:
- GetM01M02AxisPos(PLCAxisPos.dictM01M02_上料站X轴, ProgramHelp.Instance.commPLC_M01M02);
- GetM01M02Axis(PLCAxis.dictM01M02_轴["上料站X轴"], ProgramHelp.Instance.commPLC_M01M02);
- break;
- case 5:
- GetM01M02AxisPos(PLCAxisPos.dictM01M02_上料站Y轴, ProgramHelp.Instance.commPLC_M01M02);
- GetM01M02Axis(PLCAxis.dictM01M02_轴["上料站Y轴"], ProgramHelp.Instance.commPLC_M01M02);
- break;
- case 6:
- GetM01M02AxisPos(PLCAxisPos.dictM01M02_上料站Z轴, ProgramHelp.Instance.commPLC_M01M02);
- GetM01M02Axis(PLCAxis.dictM01M02_轴["上料站Z轴"], ProgramHelp.Instance.commPLC_M01M02);
- break;
- }
- //GetM01M02Axis(PLCAxis.dictM01M02_轴, ProgramHelp.Instance.commPLC_M01M02);
- }
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- Thread.Sleep(1);
- }
- }
- private static void ThReadPLCM03()
- {
- while (true)
- {
- if (!ProgramHelp.Instance.commPLC_M03.isPLCConnected)
- {
- Thread.Sleep(5);
- continue;
- }
- GetM03InitValue(PLCCylinder.dictPLC_InitIO["M03"], ProgramHelp.Instance.commPLC_M03);
- GetM03AlmValue(PLCCylinder.dictM03_Alm, ProgramHelp.Instance.commPLC_M03);//
- if (EnumWindowDisplay != WindowDisplay.压机房)
- {
- Thread.Sleep(2);
- continue;
- }
- try
- {
- if (EnumWindowDisplay == WindowDisplay.压机房)
- {
- switch (iM03IOStation)
- {
- case 0:
- GetM03CylinderValue(PLCCylinder.dictM03_整平工位, ProgramHelp.Instance.commPLC_M03);
- break;
- case 1:
- GetM03CylinderValue(PLCCylinder.dictM03_装冲工位, ProgramHelp.Instance.commPLC_M03);
- break;
- case 2:
- GetM03CylinderValue(PLCCylinder.dictM03_压合工位, ProgramHelp.Instance.commPLC_M03);
- break;
- case 3:
- GetM03CylinderValue(PLCCylinder.dictM03_清洗工位, ProgramHelp.Instance.commPLC_M03);
- break;
- case 4:
- GetM03CylinderValue(PLCCylinder.dictM03_下流线工位, ProgramHelp.Instance.commPLC_M03);
- break;
- case 5:
- GetM03CylinderValue(PLCCylinder.dictM03_出料口工位, ProgramHelp.Instance.commPLC_M03);
- break;
- }
- switch (iM03AxisStation)
- {
- case 0:
- //GetM03AxisPos(PLCAxisPos.dictM03_取料X轴, ProgramHelp.Instance.commPLC_M03);
- GetM03Axis(PLCAxis.dictM03_轴["压机流线伺服"], ProgramHelp.Instance.commPLC_M03);
- break;
- case 1:
- //GetM03AxisPos(PLCAxisPos.dictM03_取料Y轴, ProgramHelp.Instance.commPLC_M03);
- GetM03Axis(PLCAxis.dictM03_轴["压机前流线伺服"], ProgramHelp.Instance.commPLC_M03);
- break;
- }
- //GetM03Axis(PLCAxis.dictM03_轴, ProgramHelp.Instance.commPLC_M03);
- }
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- Thread.Sleep(1);
- }
- }
- private static void ThReadPLCM04M05()
- {
- while(true)
- {
- if (!ProgramHelp.Instance.commPLC_M04M05.isPLCConnected)
- {
- Thread.Sleep(5);
- continue;
- }
- GetM04M05InitValue(PLCCylinder.dictPLC_InitIO["M04M05"], ProgramHelp.Instance.commPLC_M04M05);
- foreach (var itemM04 in dictM04)
- {
- switch (itemM04.Key)
- {
- case "允许下料":
- PLCResultHelp.isM04_允许下料 = GetM04M05BoolValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
- break;
- case "当前检测高度":
- PLCResultHelp.fM04_当前检测高度 = GetM04M05RealValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
- break;
- case "当前重量":
- PLCResultHelp.fM04_当前重量 = Convert.ToSingle(GetM04M05IntValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05)) / 100;
- break;
- //case "产品高度":
- // PLCResultHelp.fM04_产品高度 = GetM04M05RealValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
- // break;
- //case "产品重量":
- // PLCResultHelp.fM04_产品重量 = GetM04M05IntValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
- // break;
- //case "废料数量":
- // PLCResultHelp.fM04_废料数量 = GetM04M05IntValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
- // break;
- //case "合格数量":
- // PLCResultHelp.fM04_合格数量 = GetM04M05IntValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
- // break;
- //case "相机结果":
- // ProgramHelp.Instance.commPLC_M04M05.ReadString(itemM04.Value, out PLCResultHelp.fM04_相机结果, out string str);
- // break;
- //case "盘数":
- // PLCResultHelp.fM04_盘数 = GetM04M05Int16Value(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
- // break;
- case "产品信息打包上传":
- PLCResultHelp.isM04_产品信息打包上传 = GetM04M05BoolValue(itemM04.Value, ProgramHelp.Instance.commPLC_M04M05);
- break;
- }
- }
- int iM05Result = GetM04M05IntValue("DB186.12", ProgramHelp.Instance.commPLC_M04M05);
- PLCResultHelp.iM05_箱数 = iM05Result;
- GetM04M05AlmValue(PLCCylinder.dictM04M05_Alm, ProgramHelp.Instance.commPLC_M04M05);//
- if (EnumWindowDisplay != WindowDisplay.检测装箱房)
- {
- Thread.Sleep(5);
- continue;
- }
- try
- {
- if (EnumWindowDisplay == WindowDisplay.检测装箱房)
- {
- switch (iM04M05IOStation)
- {
- case 0:
- GetM04M05CylinderValue(PLCCylinder.dictM04M05_ST0进口门工位, ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 1:
- GetM04M05CylinderValue(PLCCylinder.dictM04M05_取出工位, ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 2:
- GetM04M05CylinderValue(PLCCylinder.dictM04M05_清洗工位, ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 3:
- GetM04M05CylinderValue(PLCCylinder.dictM04M05_提升机工位, ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 4:
- GetM04M05CylinderValue(PLCCylinder.dictM04M05_测量工位, ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 5:
- GetM04M05CylinderValue(PLCCylinder.dictM04M05_装盘工位, ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 6:
- GetM04M05CylinderValue(PLCCylinder.dictM04M05_出盘工位, ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 7:
- GetM04M05CylinderValue(PLCCylinder.dictM04M05_下流线工位, ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 8:
- GetM04M05CylinderValue(PLCCylinder.dictM04M05_下料站工位, ProgramHelp.Instance.commPLC_M04M05);
- break;
- }
- switch (iM04M05AxisStation)
- {
- case 0:
- GetM04M05AxisPos(PLCAxisPos.dictM04M05_取料X轴, ProgramHelp.Instance.commPLC_M04M05);
- GetM04M05Axis(PLCAxis.dictM04M05_轴["取料X轴"], ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 1:
- GetM04M05AxisPos(PLCAxisPos.dictM04M05_取料Y轴, ProgramHelp.Instance.commPLC_M04M05);
- GetM04M05Axis(PLCAxis.dictM04M05_轴["取料Y轴"], ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 2:
- GetM04M05AxisPos(PLCAxisPos.dictM04M05_装盘X轴, ProgramHelp.Instance.commPLC_M04M05);
- GetM04M05Axis(PLCAxis.dictM04M05_轴["装盘X轴"], ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 3:
- GetM04M05AxisPos(PLCAxisPos.dictM04M05_装盘Y轴, ProgramHelp.Instance.commPLC_M04M05);
- GetM04M05Axis(PLCAxis.dictM04M05_轴["装盘Y轴"], ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 4:
- GetM04M05AxisPos(PLCAxisPos.dictM04M05_装盘Z轴, ProgramHelp.Instance.commPLC_M04M05);
- GetM04M05Axis(PLCAxis.dictM04M05_轴["装盘Z轴"], ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 5:
- GetM04M05AxisPos(PLCAxisPos.dictM04M05_下料站X轴, ProgramHelp.Instance.commPLC_M04M05);
- GetM04M05Axis(PLCAxis.dictM04M05_轴["下料站X轴"], ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 6:
- GetM04M05AxisPos(PLCAxisPos.dictM04M05_下料站Y轴, ProgramHelp.Instance.commPLC_M04M05);
- GetM04M05Axis(PLCAxis.dictM04M05_轴["下料站Y轴"], ProgramHelp.Instance.commPLC_M04M05);
- break;
- case 7:
- GetM04M05AxisPos(PLCAxisPos.dictM04M05_下料站Z轴, ProgramHelp.Instance.commPLC_M04M05);
- GetM04M05Axis(PLCAxis.dictM04M05_轴["下料站Z轴"], ProgramHelp.Instance.commPLC_M04M05);
- break;
- }
- //GetM04M05Axis(PLCAxis.dictM04M05_轴, ProgramHelp.Instance.commPLC_M04M05);
- }
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- Thread.Sleep(1);
- }
- }
- private static void ThPressure()
- {
- short svalue = 0;
- float fvalue = 0;
- int ivalue = 0;
- string str;
- while (true)
- {
- if (!ProgramHelp.Instance.comm压机.isPLCConnected)
- {
- Thread.Sleep(5);
- continue;
- }
- //if(EnumWindowDisplay != WindowDisplay.压力机)
- //{
- // Thread.Sleep(5);
- // continue;
- //}
- try
- {
- foreach (var item in dictPressure)
- {
- if(item.Value.type == "short")
- {
- ProgramHelp.Instance.comm压机.ReadShort(item.Value.Address, out svalue, out str);
- item.Value.value = (svalue * item.Value.Scale).ToString();
- if(item.Value.Name == "主缸当前位置")
- {
- str主缸当前位置 = item.Value.value;
- }
- if (item.Value.Name == "主缸当前压力")
- {
- str主缸当前压力 = item.Value.value;
- }
- if(item.Value.Name == "当前动作")
- {
- upTrigger.Now = item.Value.value == "1" ? true : false;
- if(upTrigger.OutPut)
- {
- queuePressureSignals.Enqueue(1);
- }
- }
- }
- else if(item.Value.type == "float")
- {
- ProgramHelp.Instance.comm压机.ReadFloat(item.Value.Address, out fvalue, out str);
- item.Value.value =(fvalue * item.Value.Scale).ToString("0.0");
- }
- else if(item.Value.type == "int")
- {
- ProgramHelp.Instance.comm压机.ReadInt(item.Value.Address, out ivalue, out str);
- item.Value.value = (ivalue * item.Value.Scale).ToString();
- }
- Thread.Sleep(1);
- }
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- Thread.Sleep(2);
- }
- }
- #region read function
- #region M01M02
- public static bool GetM01M02BoolValue(string add, CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return false;
- commPLC.ReadCoin(add, out bool result, out string str);
- return result;
- }
- public static int GetM01M02IntValue(string add,CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return 0;
- commPLC.ReadInt(add,out int result,out string str);
- return result;
- }
- public static Int16 GetM01M02Int16Value(string add,CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return 0;
- commPLC.ReadShort(add, out Int16 result, out string str);
- return result;
- }
- public static float GetM01M02RealValue(string add,CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return 0;
- commPLC.ReadFloat(add, out float result, out string str);
- return result;
- }
- #endregion
- #region M03
- public static bool GetM03BoolValue(string add, CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return false;
- commPLC.ReadCoin(add, out bool result, out string str);
- return result;
- }
- public static int GetM03IntValue(string add, CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return 0;
- commPLC.ReadInt(add, out int result, out string str);
- return result;
- }
- public static Int16 GetM03Int16Value(string add, CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return 0;
- commPLC.ReadShort(add, out Int16 result, out string str);
- return result;
- }
- public static float GetM03RealValue(string add, CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return 0;
- commPLC.ReadFloat(add, out float result, out string str);
- return result;
- }
- #endregion
- #region M04M05
- public static bool GetM04M05BoolValue(string add, CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return false;
- commPLC.ReadCoin(add, out bool result, out string str);
- return result;
- }
- public static int GetM04M05IntValue(string add, CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return 0;
- commPLC.ReadInt(add, out int result, out string str);
- return result;
- }
- public static Int16 GetM04M05Int16Value(string add, CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return 0;
- commPLC.ReadShort(add, out Int16 result, out string str);
- return result;
- }
- public static float GetM04M05RealValue(string add, CommPLC commPLC)
- {
- if (!commPLC.isPLCConnected) return 0;
- commPLC.ReadFloat(add, out float result, out string str);
- return result;
- }
- #endregion
- #endregion
- #region write function
- public static void SetBoolValue(string add, CommPLC commPLC,bool value)
- {
- if (!commPLC.isPLCConnected) return ;
- commPLC.WriteCoin(add, value, out string str);
- }
- public static void SetIntValue(string add, CommPLC commPLC,int value)
- {
- if (!commPLC.isPLCConnected) return;
- commPLC.WriteInt(add, value, out string str);
- }
- public static void SetInt16Value(string add, CommPLC commPLC,short value)
- {
- if (!commPLC.isPLCConnected) return;
- commPLC.WriteShort(add, value, out string str);
- }
- public static void SetRealValue(string add, CommPLC commPLC,float value)
- {
- if (!commPLC.isPLCConnected) return;
- commPLC.WriteFloat(add, value, out string str);
- }
- #endregion
- #region SetValue
- public static void SetM01Result(short value,string keyName)
- {
- switch(keyName)
- {
- case "药A暂存当前盒数":
- PLCResultHelp.iM01_药A暂存当前盒数 = value;
- break;
- case "药B暂存当前盒数":
- PLCResultHelp.iM01_药B暂存当前盒数 = value;
- break;
- case "抛盖暂存槽当前数量":
- PLCResultHelp.iM01_抛盖暂存槽当前数量 = value;
- break;
- case "空桶暂存槽当前数量":
- PLCResultHelp.iM01_空桶暂存槽当前数量 = value;
- break;
- }
- }
- public static void SetM02Result(int value, string keyName)
- {
- switch (keyName)
- {
- case "药A称重配比重量":
- PLCResultHelp.iM02_药A称重配比重量 = value;
- break;
- case "A料仓1当前重量":
- PLCResultHelp.iM02_A料仓1当前重量 = value;// 1000
- break;
- case "A料仓2当前重量":
- PLCResultHelp.iM02_A料仓2当前重量 = value;// 1000
- break;
- case "A料仓3当前重量":
- PLCResultHelp.iM02_A料仓3当前重量 = value ;// 1000
- break;
- case "A料仓4当前重量":
- PLCResultHelp.iM02_A料仓4当前重量 = value;// 1000
- break;
- case "A料仓5当前重量":
- PLCResultHelp.iM02_A料仓5当前重量 = value;// 1000
- break;
- case "药B称重配比重量":
- PLCResultHelp.iM02_药B称重配比重量 = value;
- break;
- case "B料仓1当前重量":
- PLCResultHelp.iM02_B料仓1当前重量 = value;// 1000
- break;
- case "B料仓2当前重量":
- PLCResultHelp.iM02_B料仓2当前重量 = value;// 1000
- break;
- case "B料仓3当前重量":
- PLCResultHelp.iM02_B料仓3当前重量 = value;// 1000
- break;
- case "B料仓4当前重量":
- PLCResultHelp.iM02_B料仓4当前重量 = value;// 1000
- break;
- case "B料仓5当前重量":
- PLCResultHelp.iM02_B料仓5当前重量 = value;// 1000
- break;
- }
- }
- public static void SetM04ResultInt(int value,string keyName)
- {
- //switch(keyName)
- //{
- // case "产品重量":
- // PLCResultHelp.iM04_产品重量 = value;
- // break;
- // case "废料数量":
- // PLCResultHelp.iM04_废料数量 = value;
- // break;
- // case "合格数量":
- // PLCResultHelp.iM04_合格数量 = value;
- // break;
- //}
- }
- public static void SetM04ResultShort(short value, string keyName)
- {
- //switch (keyName)
- //{
- // case "产品重量":
- // PLCResultHelp.iM04_相机结果 = value;
- // break;
- // case "废料数量":
- // PLCResultHelp.iM04_盘数 = value;
- // break;
- //}
- }
- #endregion
- }
- }
|