Example #1
0
 /*
  * decodeSetMessage函数,处理SET命令的函数
  * 虚函数,方法已实现,会自动将SET命令后的参数进行一一赋值
  * 如有需要,可在仪器类中重写该函数
  */
 public virtual void decodeSetMessage(ModbusMessage s)
 {
     foreach (DictionaryEntry de in s.Data)
     {
         DataOperate.WriteAny((String)de.Key, Code, de.Value);
     }
 }
Example #2
0
        /*
         * 接受数据函数,每次收到数据会自动调用该函数进行解析成ModBusMessage
         * 该函数会根据MessageType去调用不同的解析函数
         */
        public override void ReceiveMsg(String s)
        {
            ModbusMessage message = ModbusMessageHelper.decodeModbusMessage(s);

            switch (message.MsgType)
            {
            case ModbusMessage.MessageType.RESPONSE:
                decodeResponseMessage(message);
                break;

            case ModbusMessage.MessageType.CMD:
                decodeCmdMessage(message);
                break;

            case ModbusMessage.MessageType.REPORT:
                decodeReportMessage(message);
                break;

            case ModbusMessage.MessageType.SET:
                decodeSetMessage(message);
                break;

            case ModbusMessage.MessageType.GET:
                break;
            }
        }
Example #3
0
 /*
 * decodeReportMessage函数,处理REPORT命令的函数
 * 虚函数,方法已实现,会自动将REPORT命令后的参数进行一一处理
 * 如有需要,可在仪器类中重写该函数
 */
 public virtual void decodeReportMessage(ModbusMessage s)
 {
     foreach (DictionaryEntry de in s.Data)
     {
         DataOperate.WriteAny((String)de.Key, Code ,de.Value);
     }
 }
Example #4
0
        public override void decodeCmdMessage(ModbusMessage msg)
        {
            String cmd = (String)msg.Data["Cmd"];

            if ("Start".Equals(cmd))
            {
                //dispenTimer.Start();
                this.MDF_Cmd = "Start";
            }
            if ("Reset".Equals(cmd))
            {
                MDF_WhichDish = 1;
                MDF_WhichStack = 1;
                this.MDF_Cmd = "Reset";
            }
            if ("Stop".Equals(cmd))
            {
                //dispenTimer.Stop();
                this.MDF_Cmd = "Stop";
            }
            if ("Auto".Equals(cmd))
            {
                this.MDF_Cmd = "Auto";
            }

            this.sendOKResponse();
        }
Example #5
0
 /*
 * decodeResponseMessage函数,处理Response命令的函数
 * 虚函数,方法已实现,会自动给出消息的Response答复
 * 如有需要,可在仪器类中重写该函数
 */
 public virtual void decodeResponseMessage(ModbusMessage s)
 {
     ModbusMessageDataCreator creator = new ModbusMessageDataCreator();
     creator.addKeyPair("Result", "OK");
     string msg = ModbusMessageHelper.createModbusMessage(ModbusMessage.messageTypeToByte(ModbusMessage.MessageType.RESPONSE), creator.getDataBytes());
     this.SendMsg(msg);
 }
Example #6
0
        /*
         * decodeResponseMessage函数,处理Response命令的函数
         * 虚函数,方法已实现,会自动给出消息的Response答复
         * 如有需要,可在仪器类中重写该函数
         */
        public virtual void decodeResponseMessage(ModbusMessage s)
        {
            ModbusMessageDataCreator creator = new ModbusMessageDataCreator();

            creator.addKeyPair("Result", "OK");
            string msg = ModbusMessageHelper.createModbusMessage(ModbusMessage.messageTypeToByte(ModbusMessage.MessageType.RESPONSE), creator.getDataBytes());

            this.SendMsg(msg);
        }
Example #7
0
        /*
         * SendModBusMsg函数,以ModBus协议的方式发送数据
         * ModbusMessage.MessageType 有{ CMD, RESPONSE, GET, SET, REPORT }
         * Key 和 Value 分别指的是生成ModBusMessage的键和值
         * 通常来说Key为变量名,Value为该变量的值,示例:SendModBusMsg(ModbusMessage.MessageType.REPORT,"MPF_PlateNum","10");
         * 函数完成的就是将这组Key,Value封装成ModBusMessage然后发送出去
         */
        public void SendModBusMsg(ModbusMessage.MessageType type, String key, Object value)
        {
            ModbusMessageDataCreator creator = new ModbusMessageDataCreator();

            creator.addKeyPair(key, (String)value);
            string msg = ModbusMessageHelper.createModbusMessage(ModbusMessage.messageTypeToByte(type), creator.getDataBytes());

            this.SendMsg(msg);
        }
Example #8
0
        /*
         * SendModBusMsg函数,以ModBus协议的方式发送数据
         * ModbusMessage.MessageType 有{ CMD, RESPONSE, GET, SET, REPORT }
         * htable指的是多组的Key和Value,主要用于多个键以及值的数据发送
         * 函数完成的就是将这htable包含的多组Key,Value封装成ModBusMessage然后发送出去
         */
        public void SendModBusMsg(ModbusMessage.MessageType type, Hashtable htable)
        {
            ModbusMessageDataCreator creator = new ModbusMessageDataCreator();

            foreach (DictionaryEntry de in htable)
            {
                creator.addKeyPair((string)de.Key, (string)de.Value);
            }
            string msg = ModbusMessageHelper.createModbusMessage(ModbusMessage.messageTypeToByte(type), creator.getDataBytes());

            this.SendMsg(msg);
        }
Example #9
0
        public static ModbusMessage decodeModbusMessage(String msg)//读取消息
        {
            ModbusMessage res = new ModbusMessage();

            byte[] cmd = StringByteHelper.StringToBytes(msg);
            if (!check_modbus_message(cmd))
            {
                return(null);
            }
            res.Dev     = cmd[3];
            res.MsgType = ModbusMessage.byteToMessageType(cmd[4]);
            int len = cmd[2] - 3;

            byte[] data = new byte[len];
            for (int i = 0; i < len; i++)
            {
                data[i] = cmd[i + 5];
            }
            String    s   = Encoding.Default.GetString(data);
            Hashtable map = new Hashtable();

            String[] words = s.Split(';');
            String[] parts;
            for (int i = 0; i < words.Length; i++)
            {
                if (words[i].Length == 0)
                {
                    continue;
                }
                parts = words[i].Split('=');
                if (parts.Length != 2)
                {
                    return(null);
                }
                map.Add(parts[0], parts[1]);
            }
            res.Data = map;
            return(res);
        }
Example #10
0
 /*
 * decodeCmdMessage函数,处理CMD命令的函数
 * 虚函数实现,可根据需要在仪器类中实现相关处理方法
 */
 public virtual void decodeCmdMessage(ModbusMessage s)
 {
 }
Example #11
0
 /*
  * SendModBusMsg函数,以ModBus协议的方式发送数据
  * ModbusMessage.MessageType 有{ CMD, RESPONSE, GET, SET, REPORT }
  * htable指的是多组的Key和Value,主要用于多个键以及值的数据发送
  * 函数完成的就是将这htable包含的多组Key,Value封装成ModBusMessage然后发送出去
  */
 public void SendModBusMsg(ModbusMessage.MessageType type, Hashtable htable)
 {
     ModbusMessageDataCreator creator = new ModbusMessageDataCreator();
     foreach (DictionaryEntry de in htable)
     {
         creator.addKeyPair((string)de.Key, (string)de.Value);
     }
     string msg = ModbusMessageHelper.createModbusMessage(ModbusMessage.messageTypeToByte(type), creator.getDataBytes());
     this.SendMsg(msg);
 }
Example #12
0
 /*
  * SendModBusMsg函数,以ModBus协议的方式发送数据
  * ModbusMessage.MessageType 有{ CMD, RESPONSE, GET, SET, REPORT }
  * Key 和 Value 分别指的是生成ModBusMessage的键和值
  * 通常来说Key为变量名,Value为该变量的值,示例:SendModBusMsg(ModbusMessage.MessageType.REPORT,"MPF_PlateNum","10");
  * 函数完成的就是将这组Key,Value封装成ModBusMessage然后发送出去
  */
 public void SendModBusMsg(ModbusMessage.MessageType type, String key, Object value)
 {
     ModbusMessageDataCreator creator = new ModbusMessageDataCreator();
     creator.addKeyPair(key, (String)value);
     string msg = ModbusMessageHelper.createModbusMessage(ModbusMessage.messageTypeToByte(type), creator.getDataBytes());
     this.SendMsg(msg);
 }
Example #13
0
 //读取消息
 public static ModbusMessage decodeModbusMessage(String msg)
 {
     ModbusMessage res = new ModbusMessage();
     byte[] cmd = StringByteHelper.StringToBytes(msg);
     if (!check_modbus_message(cmd)) return null;
     res.Dev = cmd[3];
     res.MsgType = ModbusMessage.byteToMessageType(cmd[4]);
     int len = cmd[2] - 3;
     byte[] data = new byte[len];
     for (int i = 0; i < len; i++)
     {
         data[i] = cmd[i + 5];
     }
     String s = Encoding.Default.GetString(data);
     Hashtable map = new Hashtable();
     String[] words = s.Split(';');
     String[] parts;
     for (int i = 0; i < words.Length; i++)
     {
         if (words[i].Length == 0) continue;
         parts = words[i].Split('=');
         if (parts.Length != 2) return null;
         map.Add(parts[0], parts[1]);
     }
     res.Data = map;
     return res;
 }
Example #14
0
        //解码报告消息
        public override void decodeReportMessage(ModbusMessage msg)
        {
            String reportType = (String)msg.Data["ReportType"];
            if ("MDF_Current".Equals(reportType))
            {

                MDF_Current1 = double.Parse((String)msg.Data["MDF_Current1"]);
                MDF_Current2 = double.Parse((String)msg.Data["MDF_Current2"]);
                MDF_Current3 = double.Parse((String)msg.Data["MDF_Current3"]);
                MDF_Current4 = double.Parse((String)msg.Data["MDF_Current4"]);
            }
            if ("MDF".Equals(reportType))
            {
                String Stackcode = (String)msg.Data["MDF_WhichStack"];
                String Petricode = (String)msg.Data["MDF_WhichDish"];
                String Barcode = (String)msg.Data["MDF_BarCode"];
                MDFDispenMessage xinXi = new MDFDispenMessage();
                xinXi.Stackcode = Stackcode;
                xinXi.Petricode = Petricode;
                xinXi.Barcode = Barcode;
                lock (DispenMessages)
                {
                    DispenMessages.Add(xinXi);
                }
                lock (RefreshObject)
                {
                    needRefreshMessages = true;
                }
            }
        }
Example #15
0
 private void decodeSetMessage(ModbusMessage message)
 {
     DeviceType type = EnumHelper.deviceStringToDeviceType((String)message.Data["DeviceType"]);
     IsVirt = false;
     CurrentDeviceType = type;
     if (type == DeviceType.Dispen)
     {
         String subType = (String)message.Data["SubType"];
         if ("PeiYangMin".Equals(subType))
         {
             SubType = AutoDispenTwincatDevice.AutoDispenType.PeiYangMin;
         }
         else
         {
             SubType = AutoDispenTwincatDevice.AutoDispenType.ShenKongBan;
         }
     }
     IdentifyID = (String)message.Data["IdentifyID"];
     Code = (String)message.Data["Code"];
     Name = (String)message.Data["Name"];
     SerialID = (String)message.Data["SerialID"];
 }
Example #16
0
        //解码报告消息
        public override void decodeReportMessage(ModbusMessage msg)
        {
            String reportType = (String)msg.Data["ReportType"];

            if ("MPF_Current".Equals(reportType))
            {

                MPF_Current1 = double.Parse((String)msg.Data["MPF_Current1"]);
                MPF_Current2 = double.Parse((String)msg.Data["MPF_Current2"]);
                MPF_Current3 = double.Parse((String)msg.Data["MPF_Current3"]);
                MPF_Current4 = double.Parse((String)msg.Data["MPF_Current4"]);
            }
            if ("MPF".Equals(reportType))
            {
                String PlateNum = (String)msg.Data["MPF_Whichplate"];
                String Barcode = (String)msg.Data["MPF_BarCode"];
                MPFDispenMessage disMsg = new MPFDispenMessage();
                disMsg.PlateNum = PlateNum;
                disMsg.Barcode = Barcode;
                lock (DispenMessages)
                {
                    DispenMessages.Add(disMsg);
                }
                lock (RefreshObject)
                {
                    needRefreshMessages = true;
                }
            }
        }
Example #17
0
 /*
  * decodeCmdMessage函数,处理CMD命令的函数
  * 虚函数实现,可根据需要在仪器类中实现相关处理方法
  */
 public virtual void decodeCmdMessage(ModbusMessage s)
 {
 }
Example #18
0
 //解码报告消息
 //*/
 private void decodeReportMessage(ModbusMessage msg)
 {
     String reportType = (String)msg.Data["ReportType"];
     if ("Currency".Equals(reportType))
     {
         MDF_Current1 = double.Parse((String)msg.Data["Currency1"]);
         MDF_Current2 = double.Parse((String)msg.Data["Currency2"]);
         MDF_Current3 = double.Parse((String)msg.Data["Currency3"]);
     }
     if ("ShenKongBan".Equals(reportType))
     {
         String KongBanHao = (String)msg.Data["KongBanHao"];
         String TiaoMaHao = (String)msg.Data["TiaoMaHao"];
         FenZhuangXinXi xinXi = new FenZhuangXinXi();
         xinXi.DuiMaHao = KongBanHao;
         xinXi.TiaoMaHao = TiaoMaHao;
         lock (FenZhuangMessages)
         {
             FenZhuangMessages.Add(xinXi);
         }
         lock (RefreshObject)
         {
             needRefreshMessages = true;
         }
     }
     if ("PeiYangMin".Equals(reportType))
     {
         String DuiMaHao = (String)msg.Data["DuiMaHao"];
         String PeiYangMinHao = (String)msg.Data["PeiYangMinHao"];
         String TiaoMaHao = (String)msg.Data["TiaoMaHao"];
         FenZhuangXinXi xinXi = new FenZhuangXinXi();
         xinXi.DuiMaHao = DuiMaHao;
         xinXi.PeiYangMinHao = PeiYangMinHao;
         xinXi.TiaoMaHao = TiaoMaHao;
         lock (FenZhuangMessages)
         {
             FenZhuangMessages.Add(xinXi);
         }
         lock (RefreshObject)
         {
             needRefreshMessages = true;
         }
     }
 }
Example #19
0
 public override void decodeResponseMessage(ModbusMessage msg)
 {
     this.sendOKResponse();
 }
Example #20
0
 public override void decodeSetMessage(ModbusMessage msg)
 {
     String setType = (String)msg.Data["SetType"];
 }
Example #21
0
 public override void decodeReportMessage(ModbusMessage msg)
 {
     String reportType = (String)msg.Data["ReportType"];
     if ("YouKongBan".Equals(reportType))
     {
         int f = int.Parse((String)msg.Data["Flag"]);
         if (f > 0) MMA_PlateDetect = true;
         else MMA_PlateDetect = false;
         if (MMA_PlateDetect)
         {
             MMA_currentBarCode = (String)msg.Data["TiaoMaHao"];
         }
         else
         {
             send_cmd("Next");
         }
     }
     if ("Value".Equals(reportType))
     {
         String key;
         bool hasFinish = false;
         if (MMA_CurrentValues == null)
         {
             MMA_CurrentValues = new float[MultiTunnelVirtualDevice.MMA_TestRowIndex][];
             for (int i = 0; i < MultiTunnelVirtualDevice.MMA_TestRowIndex; i++)
             {
                 MMA_CurrentValues[i] = new float[MultiTunnelVirtualDevice.MMA_TestColumnIndex];
             }
         }
         lock (MMA_CurrentValues)
         {
             foreach (Object ob in msg.Data.Keys)
             {
                 key = (String)ob;
                 if (key.StartsWith("v"))
                 {
                     int index = int.Parse(key.Substring(1, key.Length - 1));
                     int i = index / MultiTunnelVirtualDevice.MMA_TestColumnIndex;
                     int j = index % MultiTunnelVirtualDevice.MMA_TestColumnIndex;
                     if (index == MultiTunnelVirtualDevice.MMA_TestColumnIndex * MultiTunnelVirtualDevice.MMA_TestRowIndex - 1) hasFinish = true;
                     float v = float.Parse((String)msg.Data[key]);
                     MMA_CurrentValues[i][j] = v;
                 }
             }
         }
         if (hasFinish)
         {
             if (MMA_PreValues == null)
             {
                 MMA_PreValues = MMA_CurrentValues;
                 MMA_preBarCode = MMA_currentBarCode;
             }
             else
             {
                 lock (MMA_PreValues)
                 {
                     MMA_PreValues = MMA_CurrentValues;
                     MMA_preBarCode = MMA_currentBarCode;
                 }
             }
             lock (MMA_CurrentValues)
             {
                 MMA_CurrentValues = null;
                 MMA_currentBarCode = null;
             }
         }
     }
 }
Example #22
0
 public override void decodeCmdMessage(ModbusMessage msg)
 {
     String cmd = (String)msg.Data["Cmd"];
 }
Example #23
0
 //*
 private void decodeResponseMessage(ModbusMessage msg)
 {
     //String s = AutoDispenDeviceMessageCreator.createOKResponse();
     //this.SendMsg(s);
 }
Example #24
0
 public override void decodeSetMessage(ModbusMessage msg)
 {
     String setType = (String)msg.Data["SetType"];
     if ("MPF_NumAndVol".Equals(setType))
     {
         this.MPF_PlateNum = Int32.Parse((String)msg.Data["MPF_PlateNum"]);
         this.MPF_Volsperwell = double.Parse((String)msg.Data["MPF_Volsperwell"]);
     }
 }
Example #25
0
        //解码报告消息
        public override void decodeReportMessage(ModbusMessage msg)
        {
            String reportType = (String)msg.Data["ReportType"];
            if ("OD".Equals(reportType))
            {
                lock (KeyObject)
                {
                    if (HAC_OD_rowl == null) //为OD_rowl开辟空间,更新OD表
                    {
                        HAC_OD_rowl = new int[8][];
                        for (int i = 0; i < 8; i++)
                        {
                            HAC_OD_rowl[i] = new int[12];
                            for (int j = 0; j < 12; j++)
                            {
                                HAC_OD_rowl[i][j] = Convert.ToInt32(((String)msg.Data["OD"])[12*i + j]);
                            }
                        }
                    }

                    for (int i = 0; i < 8; i++)  //更新OD表
                        for (int j = 0; j < 12; j++)
                        {
                            HAC_OD_rowl[i][j] = Convert.ToInt32(((String)msg.Data["OD"])[12 * i + j]);
                        }

                    //Database mydb = new Database();
                    //mydb.inserthacod(1, OD_rowl, 1);
                }

            }

            if ("TH".Equals(reportType))
            {
                this.HAC_TH_temperature1 = Convert.ToInt32((String)msg.Data["TH_temperature1"]);
                this.HAC_TH_temperature2 = Convert.ToInt32((String)msg.Data["TH_temperature2"]);
                this.HAC_TH_temperature3 = Convert.ToInt32((String)msg.Data["TH_temperature3"]);
                this.HAC_TH_humidity1 = Convert.ToInt32((String)msg.Data["TH_humidity1"]);
                this.HAC_TH_humidity2 = Convert.ToInt32((String)msg.Data["TH_humidity2"]);

                //Database mydb = new Database();
                //mydb.inserthactmpmod(1, 1, this.TH_temperature1, TH_temperature2, TH_temperature3, TH_humidity1, TH_humidity2);

            }

            if ("System".Equals(reportType))
            {
                this.HAC_Sys_DeviceInfo = Convert.ToInt32((String)msg.Data["Sys_DeviceInfo"]);
                this.HAC_Sys_Status = Convert.ToInt32((String)msg.Data["Sys_Status"]);
                this.HAC_Sys_Batch_Info = Convert.ToInt32((String)msg.Data["Sys_Batch_Info"]);

                //Database mydb = new Database();
                //mydb.inserthacstate(1, this.Sys_Status);
            }

            if ("Code".Equals(reportType))
            {
                this.HAC_InBarCode = (String)msg.Data["Add_Num"];
                this.HAC_InBarCode = (String)msg.Data["Rem_Num"];

                //Database mydb = new Database();
                //mydb.inserthacbarcode(Add_Num, Rem_Num, 1);
            }

            if ("Motor".Equals(reportType))
            {
                this.HAC_Motor_text_speed = Convert.ToInt32((String)msg.Data["Motor_text_speed"]);
                this.HAC_Motor_elecspeed = Convert.ToInt32((String)msg.Data["Motor_elecspeed"]);
                this.HAC_Motor_Status = Convert.ToInt32((String)msg.Data["Motor_Status"]);
                this.HAC_Motor_Power = Convert.ToInt32((String)msg.Data["Motor_Power"]);

                //Database mydb = new Database();
                //mydb.inserthacengine(1, Motor_elecspeed, Motor_Power, Motor_text_speed, Motor_Status);
            }
        }
Example #26
0
 public override void decodeSetMessage(ModbusMessage msg)
 {
     String setType = (String)msg.Data["SetType"];
     if ("MDF_NumAndVol".Equals(setType))
     {
         this.MDF_NumsperStack = Int32.Parse((String)msg.Data["MDF_NumsperStack"]);
         this.MDF_VolsperDish = double.Parse((String)msg.Data["MDF_VolsperDish"]);
     }
 }