Ejemplo n.º 1
0
        private void bwrkReadVFDDefs_DoWork(object sender, DoWorkEventArgs e)
        {
            int status = 0;
            V1000_ModbusRTU_Comm comm   = new V1000_ModbusRTU_Comm();
            ModbusRTUMsg         msg    = new ModbusRTUMsg(0x1F);
            ModbusRTUMaster      modbus = new ModbusRTUMaster();
            List <ushort>        tmp    = new List <ushort>();

            VFD_Vals.Clear();
            if (comm.OpenCommPort(ref spVFD) == 0x0001)
            {
                ProgressArgs.VFDRead_Total_Units = V1000_xlRead_List.Count;

                for (int i = 0; i < V1000_xlRead_List.Count; i++)
                {
                    ProgressArgs.VFDRead_Unit     = i;
                    ProgressArgs.VFDRead_Progress = (byte)(((float)i / ProgressArgs.VFDRead_Total_Units) * 100);
                    bwrkReadVFDDefs.ReportProgress(ProgressArgs.VFDRead_Progress);
                    if (bwrkReadVFDDefs.CancellationPending)
                    {
                        e.Cancel = true;
                        bwrkReadVFDDefs.ReportProgress(0);
                        return;
                    }

                    V1000_Param_Data data = new V1000_Param_Data();

                    msg.Clear();
                    msg = modbus.CreateMessage(msg.SlaveAddr, ModbusRTUMaster.ReadReg, Convert.ToUInt16(V1000_xlRead_List[i].RegAddress, 16), 1, tmp);

                    status = comm.DataTransfer(ref msg, ref spVFD);
                    if (status == 0x0001)
                    {
                        // extract pertinent VFD parameter information the Excel File
                        data.ParamNum   = V1000_xlRead_List[i].ParamNum;
                        data.ParamName  = V1000_xlRead_List[i].ParamName;
                        data.Multiplier = Convert.ToUInt16(V1000_xlRead_List[i].Multiplier);

                        // Supplement the Excel file information with actual response from the VFD
                        data.RegAddress = msg.StartReg;
                        data.ParamVal   = msg.Data[0];
                        data.DefVal     = msg.Data[0];

                        VFD_Vals.Add(data);
                    }
                }

                ProgressArgs.VFDRead_Progress = 100;
                ProgressArgs.VFDRead_Stat     = 0x02;
                e.Result = 0x02;
                comm.CloseCommPort(ref spVFD);
                bwrkReadVFDDefs.ReportProgress(100);
            }
        }
Ejemplo n.º 2
0
        private void bwrkReadVFDVals_DoWork(object sender, DoWorkEventArgs e)
        {
            int status = 0;
            V1000_ModbusRTU_Comm comm   = new V1000_ModbusRTU_Comm();
            ModbusRTUMsg         msg    = new ModbusRTUMsg(SlaveAddress);
            ModbusRTUMaster      modbus = new ModbusRTUMaster();
            List <ushort>        tmp    = new List <ushort>();

            // proceed further only if opening of communication port is successful
            if (comm.OpenCommPort(ref spVFD) == 0x0001)
            {
                ProgressArgs.VFDRead_Total_Units = V1000_Vals.Count;

                for (int i = 0; i < ProgressArgs.VFDRead_Total_Units; i++)
                {
                    if (bwrkReadVFDVals.CancellationPending)
                    {
                        e.Cancel = true;
                        bwrkReadVFDVals.ReportProgress(0);
                        return;
                    }

                    msg.Clear();
                    msg = modbus.CreateMessage(msg.SlaveAddr, ModbusRTUMaster.ReadReg, V1000_Vals[i].RegAddress, 1, tmp);

                    status = comm.DataTransfer(ref msg, ref spVFD);
                    if (status == 0x0001)
                    {
                        V1000_Vals[i].ParamVal = msg.Data[0];

                        // Create a string version for display purposes of the actual paramater value
                        if (V1000_Vals[i].NumBase == 16)
                        {
                            V1000_Vals[i].ParamValDisp = "0x" + V1000_Vals[i].ParamVal.ToString("X4");
                        }
                        else
                        {
                            V1000_Vals[i].ParamValDisp = ((float)V1000_Vals[i].ParamVal / V1000_Vals[i].Multiplier).ToString() + " " + V1000_Vals[i].Units;
                        }
                    }

                    ProgressArgs.VFDRead_Unit     = i;
                    ProgressArgs.VFDRead_Progress = (byte)(((float)i / ProgressArgs.VFDRead_Total_Units) * 100);
                    bwrkReadVFDVals.ReportProgress((int)ProgressArgs.VFDRead_Progress);
                }

                ProgressArgs.VFDRead_Progress = 100;
                ProgressArgs.VFDRead_Stat     = 0x02;
                e.Result = 0x02;
                comm.CloseCommPort(ref spVFD);
                bwrkReadVFDVals.ReportProgress(100);
            }
        }
Ejemplo n.º 3
0
        private void btnTransmit_Click(object sender, EventArgs e)
        {
            int                  stat = 0;
            ModbusRTUMsg         msg  = new ModbusRTUMsg();
            V1000_ModbusRTU_Comm comm = new V1000_ModbusRTU_Comm();

            if (cmbSerialPort.GetItemText(cmbSerialPort.SelectedItem) == "")
            {
                MessageBox.Show("Error! No Serial Port Selected!!");
                return;
            }

            msg = OutputMsg.Copy();
            comm.OpenCommPort(ref spVFD);
            stat = comm.DataTransfer(ref msg, ref spVFD);
            if (stat == 0x0001)
            {
                lbVFDResponse.Items.Add(CreateModbusRTUDataString(msg));   // Add raw message data byte breakdown to listbox.

                switch (msg.FuncCode)
                {
                case ModbusRTUMaster.ReadReg:
                    dgvVFDResponse.Rows.Add(new string[]   {
                        "0x" + msg.SlaveAddr.ToString("X2"),
                        "0x" + msg.FuncCode.ToString("X2"),
                        "0x" + msg.StartReg.ToString("X4"),
                        msg.RegCount.ToString(),
                        CreateModbusRTUDataString(msg.Data)
                    });
                    break;

                case ModbusRTUMaster.WriteReg:
                    dgvVFDResponse.Rows.Add(new string[]    {
                        "0x" + msg.SlaveAddr.ToString("X2"),
                        "0x" + msg.FuncCode.ToString("X2"),
                        "0x" + msg.StartReg.ToString("X4"),
                        msg.RegCount.ToString(),
                    });
                    break;

                case ModbusRTUMaster.Loopback:
                    dgvVFDResponse.Rows.Add(new string[]   {
                        "0x" + msg.SlaveAddr.ToString("X2"),
                        "0x" + msg.FuncCode.ToString("X2"),
                        "0x" + msg.SubFunction.ToString("X4"),
                        CreateModbusRTUDataString(msg.Data)
                    });
                    break;
                }
            }
            comm.CloseCommPort(ref spVFD);
        }
Ejemplo n.º 4
0
        private void btnVFDReset_Click(object sender, EventArgs e)
        {
            V1000_ModbusRTU_Comm comm   = new V1000_ModbusRTU_Comm();
            ModbusRTUMsg         msg    = new ModbusRTUMsg(0x1F);
            ModbusRTUMaster      modbus = new ModbusRTUMaster();
            List <ushort>        val    = new List <ushort>();

            msg.Clear();
            val.Clear();
            val.Add(2220);
            msg = modbus.CreateMessage(msg.SlaveAddr, ModbusRTUMaster.WriteReg, 0x0103, 1, val);

            comm.OpenCommPort(ref spVFD);
            int status = comm.DataTransfer(ref msg, ref spVFD);

            if (status != 0x0001)
            {
                MessageBox.Show("VFD Parameter Reset to Default Failure!!");
            }
            comm.CloseCommPort(ref spVFD);
        }
Ejemplo n.º 5
0
        private void bwrkModVFD_DoWork(object sender, DoWorkEventArgs e)
        {
            int status = 0;
            V1000_ModbusRTU_Comm comm   = new V1000_ModbusRTU_Comm();
            ModbusRTUMsg         msg    = new ModbusRTUMsg(0x1F);
            ModbusRTUMaster      modbus = new ModbusRTUMaster();
            List <ushort>        val    = new List <ushort>();

            // proceed further only if opening of communication port is successful
            if (comm.OpenCommPort(ref spVFD) == 0x0001)
            {
                ProgressArgs.VFDWrite_Total_Units = VFD_Sched_Chng_Vals.Count;

                for (int i = 0; i < ProgressArgs.VFDWrite_Total_Units; i++)
                {
                    ProgressArgs.VFDWrite_Unit     = i;
                    ProgressArgs.VFDWrite_Progress = (byte)(((float)i / ProgressArgs.VFDWrite_Total_Units) * 100);
                    bwrkModVFD.ReportProgress(ProgressArgs.VFDWrite_Progress);
                    if (bwrkModVFD.CancellationPending)
                    {
                        e.Cancel = true;
                        ProgressArgs.VFDWrite_Stat = ProgressEventArgs.Stat_Canceled;
                        bwrkModVFD.ReportProgress(0);
                        return;
                    }

                    msg.Clear();
                    val.Clear();
                    val.Add(VFD_Sched_Chng_Vals[i].ParamVal);
                    msg = modbus.CreateMessage(msg.SlaveAddr, ModbusRTUMaster.WriteReg, VFD_Sched_Chng_Vals[i].RegAddress, 1, val);

                    status = comm.DataTransfer(ref msg, ref spVFD);
                    if (status != 0x0001)
                    {
                        MessageBox.Show("VFD Parameter Update Failure!!");
                        e.Cancel = true;
                        ProgressArgs.VFDWrite_Stat = ProgressEventArgs.Stat_Error;
                        bwrkModVFD.ReportProgress(0);
                        break;
                    }
                }

                //
                if (status == 0x0001)
                {
                    // Update all the progress and status flags
                    ProgressArgs.VFDWrite_Progress = 100;
                    ProgressArgs.VFDWrite_Stat     = ProgressEventArgs.Stat_Complete;
                    e.Result = 0x02;

                    // Save the parameter changes in the VFD
                    status = comm.SaveParamChanges(0x1F, ref spVFD);
                    if (status != 0x0001)
                    {
                        MessageBox.Show("VFD Modified Parameter Save Failure!!");
                    }
                    bwrkModVFD.ReportProgress(100);
                }

                // Close the communication port and report the thread as complete
                comm.CloseCommPort(ref spVFD);
            }
        }