Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            inputCommPortSingleton.GetInstance().initComm();
            if (!inputCommPortSingleton.GetInstance().openComm())
            {
                return;
            }

            //inputCommPortSingleton.GetInstance().writeMultiRegisters(modbusRegs);

            // use api
            byte   slaveid   = byte.Parse(textBox1.Text);
            ushort startaddr = ushort.Parse(textBox2.Text);
            float  f         = float.Parse(textBox3.Text);

            byte[] bytes   = BitConverter.GetBytes(f);
            ushort numregs = 10;

            using (ModbusRegisters modbusRegs = new ModbusRegisters(slaveid, startaddr, numregs))
            {
                int b0 = int.Parse(textBoxByte0.Text);
                int b1 = int.Parse(textBoxByte1.Text);
                int b2 = int.Parse(textBoxByte2.Text);
                int b3 = int.Parse(textBoxByte3.Text);

                modbusRegs.stReg[0].setHighReg(bytes[b0]);
                modbusRegs.stReg[0].setLowReg(bytes[b1]);
                modbusRegs.stReg[1].setHighReg(bytes[b2]);
                modbusRegs.stReg[1].setLowReg(bytes[b3]);
                inputCommPortSingleton.GetInstance().writeMultiRegisters(modbusRegs);
            }
        }
Beispiel #2
0
        void InitializeRegs()
        {
            tbPidSetting     = new TextBox[24];
            modbusRegs       = new ModbusRegisters(SLAVEID, STARTADDRESS, REGNUM);
            tbPidSetting[0]  = textBox1;
            tbPidSetting[1]  = textBox2;
            tbPidSetting[2]  = textBox3;
            tbPidSetting[3]  = textBox4;
            tbPidSetting[4]  = textBox5;
            tbPidSetting[5]  = textBox6;
            tbPidSetting[6]  = textBox7;
            tbPidSetting[7]  = textBox8;
            tbPidSetting[8]  = textBox9;
            tbPidSetting[9]  = textBox10;
            tbPidSetting[10] = textBox11;
            tbPidSetting[11] = textBox12;
            tbPidSetting[12] = textBox13;
            tbPidSetting[13] = textBox14;
            tbPidSetting[14] = textBox15;
            tbPidSetting[15] = textBox16;
            tbPidSetting[16] = textBox17;
            tbPidSetting[17] = textBox18;
            tbPidSetting[18] = textBox19;
            tbPidSetting[19] = textBox20;
            tbPidSetting[20] = textBox21;
            tbPidSetting[21] = textBox22;
            tbPidSetting[22] = textBox23;
            tbPidSetting[23] = textBox24;

            for (int i = 0; i < 24; i++)
            {
                tbPidSetting[i].KeyPress += new KeyPressEventHandler(new CheckUserInput().CheckIsNumber);
            }
        }
Beispiel #3
0
        void InitializeRegs()
        {
            tbTemratureCorrection     = new TextBox[18];
            modbusRegs                = new ModbusRegisters(SLAVEID, STARTADDRESS, REGNUM);
            tbTemratureCorrection[0]  = textBox1;
            tbTemratureCorrection[1]  = textBox2;
            tbTemratureCorrection[2]  = textBox3;
            tbTemratureCorrection[3]  = textBox4;
            tbTemratureCorrection[4]  = textBox5;
            tbTemratureCorrection[5]  = textBox6;
            tbTemratureCorrection[6]  = textBox7;
            tbTemratureCorrection[7]  = textBox8;
            tbTemratureCorrection[8]  = textBox9;
            tbTemratureCorrection[9]  = textBox10;
            tbTemratureCorrection[10] = textBox11;
            tbTemratureCorrection[11] = textBox12;
            tbTemratureCorrection[12] = textBox13;
            tbTemratureCorrection[13] = textBox14;
            tbTemratureCorrection[14] = textBox15;
            tbTemratureCorrection[15] = textBox16;
            tbTemratureCorrection[16] = textBox17;
            tbTemratureCorrection[17] = textBox18;

            for (int i = 0; i < 17; i++)
            {
                tbTemratureCorrection[i].KeyPress += new KeyPressEventHandler(new CheckUserInput().CheckIsNumber);
            }
        }
 private void buttonRefrigeration2_67_Click(object sender, EventArgs e)
 {
     using (ModbusRegisters modbusRegs = new ModbusRegisters(1, 0x4d, 1))
     {
         modbusRegs.stReg[0].value = 0x02;
         inputCommPortSingleton.GetInstance().writeMultiRegisters(modbusRegs);
     }
 }
Beispiel #5
0
 public void UpdateUIData(ModbusRegisters reg)
 {
     for (int i = 0; i < reg.numRegisters; i++)
     {
         tbTemratureCorrection[i].Text = reg.stReg[i].getShortValue().ToString();
     }
     buttonWTRead.Enabled  = true;
     buttonWTWrite.Enabled = true;
     buttonMain.Enabled    = true;
 }
Beispiel #6
0
        public void UpdateUIData(ModbusRegisters reg)
        {
            for (int i = 0; i < reg.numRegisters; i++)
            {
                tbPidSetting[i].Text = reg.stReg[i].getShortValue().ToString();
            }

            buttonPIDRead.Enabled  = true;
            buttonPIDWrite.Enabled = true;
            buttonMain.Enabled     = true;
        }
Beispiel #7
0
        // dataflg : 0 - left room, 1 - right room
        public void updateData(int dataflg, ModbusRegisters reg)
        {
            int run_time_h0 = reg.stReg[RUNTIME_M].getHighReg() / 60;
            int run_time_h1 = reg.stReg[RUNTIME_M].getLowReg() / 60;
            int run_time_m0 = reg.stReg[RUNTIME_M].getHighReg() % 60;
            int run_time_m1 = reg.stReg[RUNTIME_M].getLowReg() % 60;
            int run_time_s0 = reg.stReg[RUNTIME_S].getHighReg();
            int run_time_s1 = reg.stReg[RUNTIME_S].getLowReg();

            if (dataflg == 0) // left room
            {
                textBox1.Text = reg.stReg[TEMP_OIL0].getShortValue().ToString();
                textBox2.Text = reg.stReg[PID_RESULT0].getShortValue().ToString();

                textBox3.Text = reg.stReg[TIME_SUCK].getHighReg().ToString();
                textBox4.Text = reg.stReg[STATE_SUCKTUBE].getHighRegString();

                textBox5.Text = reg.stReg[TEMP_BATH0].getShortValue().ToString();
                textBox6.Text = reg.stReg[STATE_WORK].getHighRegString();

                textBox7.Text = reg.stReg[TIME_DROP].getHighReg().ToString();
                textBox8.Text = reg.stReg[UP_FLAG].getHighRegString();

                textBox9.Text  = string.Format("{0:D2}:{1:D2}:{2:D2}", run_time_h0, run_time_m0, run_time_s0);
                textBox10.Text = reg.stReg[ALLSTATE].getHighRegString();

                textBox11.Text = reg.stReg[ALARM].getHighRegString();
                textBox12.Text = reg.stReg[DOWN_FLAG].getHighRegString();

                addPoint(reg.stReg[TEMP_OIL0].getShortValue(), reg.stReg[TEMP_BATH0].getShortValue());
            }
            else // right room
            {
                textBox1.Text = reg.stReg[TEMP_OIL1].getShortValue().ToString();
                textBox2.Text = reg.stReg[PID_RESULT1].getShortValue().ToString();

                textBox3.Text = reg.stReg[TIME_SUCK].getLowReg().ToString();
                textBox4.Text = reg.stReg[STATE_SUCKTUBE].getLowRegString();

                textBox5.Text = reg.stReg[TEMP_BATH1].getShortValue().ToString();
                textBox6.Text = reg.stReg[STATE_WORK].getLowRegString();

                textBox7.Text = reg.stReg[TIME_DROP].getLowReg().ToString();
                textBox8.Text = reg.stReg[UP_FLAG].getLowRegString();

                textBox9.Text  = string.Format("{0:D2}:{1:D2}:{2:D2}", run_time_h1, run_time_m1, run_time_s1);
                textBox10.Text = reg.stReg[ALLSTATE].getLowRegString();

                textBox11.Text = reg.stReg[ALARM].getLowRegString();
                textBox12.Text = reg.stReg[DOWN_FLAG].getLowRegString();

                addPoint(reg.stReg[TEMP_OIL1].getShortValue(), reg.stReg[TEMP_BATH1].getShortValue());
            }
        }
        public void writeSingleRegister(ModbusRegisters regs, ushort value)
        {
            if (master == null)
            {
                return;
            }

            lock (locker)
            {
                master.WriteSingleRegister(regs.slaveid, regs.startAddress, value);
            }
        }
Beispiel #9
0
        public void UpdateUIData(ModbusRegisters reg)
        {
            for (int i = 0; i < lRegTextBox.Count; i++)
            {
                lRegTextBox[i].UpdateData();
            }

            buttonRead.Enabled  = true;
            buttonWrite.Enabled = true;
            buttonMain.Enabled  = true;
            //regTextBox1.UpdateData();
        }
Beispiel #10
0
        public int writeMultiRegisters(ModbusRegisters regs)
        {
            if (master == null)
            {
                commsts = COMMSTS_UNKONOWN;
                return(RET_INITFAILURE);
            }

            if (port.IsOpen == false)
            {
                commsts = COMMSTS_PORTNOTOPEN;
                return(RET_INITFAILURE);
            }

            lock (locker)
            {
                try
                {
                    for (int i = 0; i < regs.numRegisters; i++)
                    {
                        regs.values[i] = regs.stReg[i].value;
                    }

                    master.WriteMultipleRegisters(regs.slaveid, regs.startAddress, regs.values);
                }
                catch (TimeoutException ex)
                {
                    LogClass.GetInstance().WriteLogFile("WriteMultipleRegisters Timeout:" + port.WriteTimeout.ToString());
                    //MessageBox.Show("Serial Port Write Timeout:" + port.WriteTimeout.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (rtycnt++ < MAX_RETYR_COUNT)
                    {
                        return(RET_TIMEOUT);
                    }
                    else
                    {
                        commsts = COMMSTS_FAILURE;
                        return(RET_COMMERROR);
                    }
                }
                catch (Exception ex)
                {
                    LogClass.GetInstance().WriteExceptionLog(ex);
                    //MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    commsts = COMMSTS_FAILURE;
                    return(RET_FAILURE);
                }
            }
            rtycnt  = 0;
            commsts = COMMSTS_NORMAL;
            return(RET_OK);
        }
Beispiel #11
0
        void InitializeRegs()
        {
            lRegTextBox = new List <RegTextBox>();
            modbusRegs  = new ModbusRegisters(SLAVEID, STARTADDRESS, REGNUM);

            foreach (Control control in this.Controls)//遍历本窗体中所有的ComboBox控件
            {
                if (control.GetType().ToString() == "CommCtrlSystem.RegTextBox")
                {
                    (control as CommCtrlSystem.RegTextBox).setReg(ref modbusRegs);
                    //(control as CommCtrlSystem.RegTextBox).KeyPress += new KeyPressEventHandler(new CheckUserInput().CheckIsNumber);
                    lRegTextBox.Add(control as CommCtrlSystem.RegTextBox);
                }
            }
        }
        public void readRegister(ref ModbusRegisters regs)
        {
            if (master == null)
            {
                return;
            }

            lock (locker)
            {
                regs.values = master.ReadHoldingRegisters(regs.slaveid, regs.startAddress, regs.numRegisters);
                for (int i = 0; i < regs.numRegisters; i++)
                {
                    regs.stReg[i].value = regs.values[i];
                }
            }
        }
        public void writeMultiRegisters(ModbusRegisters regs)
        {
            if (master == null)
            {
                return;
            }

            lock (locker)
            {
                for (int i = 0; i < regs.numRegisters; i++)
                {
                    regs.values[i] = regs.stReg[i].value;
                }

                master.WriteMultipleRegisters(regs.slaveid, regs.startAddress, regs.values);
            }
        }
Beispiel #14
0
        public void setReg(ref ModbusRegisters reg)
        {
            this.reg = reg;

            switch (dataType)
            {
            case DataType.dtString:
            case DataType.dtLString:
            case DataType.dtHString:
                for (int i = 0; i < items.Count; i++)
                {
                    this.reg.stReg[_regIndex].addStringMap(items[i].index, items[i].mapstring);
                }

                break;

            default:
                break;
            }
        }
Beispiel #15
0
        private void button1_Click(object sender, EventArgs e)
        {
            // use user conctrl
            //inputCommPortSingleton.GetInstance().readRegister(ref modbusRegs);

            //for (int i = 0; i < lRegTextBox.Count; i++)
            //{
            //    lRegTextBox[i].UpdateData();
            //}

            // use api

            inputCommPortSingleton.GetInstance().initComm();
            if (!inputCommPortSingleton.GetInstance().openComm())
            {
                return;
            }
            byte   slaveid   = byte.Parse(textBox1.Text);
            ushort startaddr = ushort.Parse(textBox2.Text);
            ushort numregs   = 2;

            ModbusRegisters modbusRegs = new ModbusRegisters(slaveid, startaddr, numregs);

            inputCommPortSingleton.GetInstance().readRegister(ref modbusRegs);

            int b0 = int.Parse(textBoxByte0.Text);
            int b1 = int.Parse(textBoxByte1.Text);
            int b2 = int.Parse(textBoxByte2.Text);
            int b3 = int.Parse(textBoxByte3.Text);

            byte[] bytes = new byte[4];
            bytes[b0] = (byte)modbusRegs.stReg[0].getHighReg();
            bytes[b1] = (byte)modbusRegs.stReg[0].getLowReg();
            bytes[b2] = (byte)modbusRegs.stReg[1].getHighReg();
            bytes[b3] = (byte)modbusRegs.stReg[1].getLowReg();

            float f = BitConverter.ToSingle(bytes, 0);

            textBox3.Text = f.ToString();
        }
Beispiel #16
0
        void InitializeRegs()
        {
            modbusRegs = new ModbusRegisters(SLAVEID, STARTADDRESS, REGNUM);
            modbusRegs.stReg[CHECKFINISH].addStringMap(0, "");
            modbusRegs.stReg[CHECKFINISH].addStringMap(1, "冷滤点完成");
            modbusRegs.stReg[CHECKFINISH].addStringMap(2, "<51℃,未阻塞");
            modbusRegs.stReg[CHECKFINISH].addStringMap(3, "首次吸引超过60秒,放弃");
            modbusRegs.stReg[CHECKFINISH].addStringMap(4, "用户温度下限未阻塞");

            modbusRegs.stReg[STATE_WORK].addStringMap(0, "停止");
            modbusRegs.stReg[STATE_WORK].addStringMap(1, "加热");
            modbusRegs.stReg[STATE_WORK].addStringMap(2, "制冷");
            modbusRegs.stReg[STATE_WORK].addStringMap(3, "完成");
            modbusRegs.stReg[STATE_WORK].addStringMap(4, "故障");

            modbusRegs.stReg[ALARM].addStringMap(0, "无故障");
            modbusRegs.stReg[ALARM].addStringMap(1, "加热器故障");
            modbusRegs.stReg[ALARM].addStringMap(2, "制冷故障");
            modbusRegs.stReg[ALARM].addStringMap(3, "光电检测故障");
            modbusRegs.stReg[ALARM].addStringMap(4, "电磁阀故障");
            modbusRegs.stReg[ALARM].addStringMap(5, "超温故障");
            modbusRegs.stReg[ALARM].addStringMap(6, "制冷超时故障");
            modbusRegs.stReg[ALARM].addStringMap(7, "加热超时故障");
            modbusRegs.stReg[ALARM].addStringMap(8, "温度传感器故障");

            modbusRegs.stReg[STATE_SUCKTUBE].addStringMap(0, "无动作");
            modbusRegs.stReg[STATE_SUCKTUBE].addStringMap(1, "吸引");
            modbusRegs.stReg[STATE_SUCKTUBE].addStringMap(2, "释放");

            modbusRegs.stReg[UP_FLAG].addStringMap(0, "OFF");
            modbusRegs.stReg[UP_FLAG].addStringMap(1, "ON");

            modbusRegs.stReg[DOWN_FLAG].addStringMap(0, "OFF");
            modbusRegs.stReg[DOWN_FLAG].addStringMap(1, "ON");

            modbusRegs.stReg[ALLSTATE].addStringMap(0, "停止");
            modbusRegs.stReg[ALLSTATE].addStringMap(1, "启动");
        }
Beispiel #17
0
        public void UpdateUIData(ModbusRegisters reg)
        {
            textBoxRes0.Text = reg.stReg[CHECKFINISH].getHighRegString();
            textBoxRes1.Text = reg.stReg[CHECKFINISH].getLowRegString();

            textBox2.Text = reg.stReg[TEMP_OIL0].getFloatValue().ToString();
            textBox9.Text = reg.stReg[TEMP_OIL1].getFloatValue().ToString();

            textBox3.Text  = reg.stReg[TEMP_BATH0].getShortValue().ToString();
            textBox10.Text = reg.stReg[TEMP_BATH1].getShortValue().ToString();

            textBox3.Text  = reg.stReg[TEMP_BATH0].getShortValue().ToString();
            textBox10.Text = reg.stReg[TEMP_BATH1].getShortValue().ToString();

            textBox4.Text  = reg.stReg[ALLSTATE].getHighRegString();
            textBox11.Text = reg.stReg[ALLSTATE].getLowRegString();

            int run_time_h0 = reg.stReg[RUNTIME_M].getHighReg() / 60;
            int run_time_h1 = reg.stReg[RUNTIME_M].getLowReg() / 60;
            int run_time_m0 = reg.stReg[RUNTIME_M].getHighReg() % 60;
            int run_time_m1 = reg.stReg[RUNTIME_M].getLowReg() % 60;
            int run_time_s0 = reg.stReg[RUNTIME_S].getHighReg();
            int run_time_s1 = reg.stReg[RUNTIME_S].getLowReg();

            textBoxTime0.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", run_time_h0, run_time_m0, run_time_s0);
            textBoxTime1.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", run_time_h1, run_time_m1, run_time_s1);

            coldfilterpoint0 = reg.stReg[COLDFILTERPOINT0].getShortValue();
            coldfilterpoint1 = reg.stReg[COLDFILTERPOINT1].getShortValue();

            WindowManager.GetInstance().wrd1.updateData(0, reg);
            WindowManager.GetInstance().wrd2.updateData(1, reg);

            //Random random = new Random();
            //WindowManager.GetInstance().wrd1.addPoint0(random.Next(0, 10), random.Next(30, 50));
            //WindowManager.GetInstance().wrd2.addPoint0(random.Next(90, 100), random.Next(10, 40));
        }