protected override object[] wsmbtReadMethod(ushort startAdd, ushort count, WSMBTControl wsmbtControl)
        {
            short[] registers = new short[26];
            wsmbtControl.ReadInputRegisters(1, startAdd, count, registers);

            return(Array.ConvertAll(registers, item => (object)item));
        }
예제 #2
0
        public bool ScanOnce()
        {
            bool bRet = true;

            WSMBS.Result sres;
            WSMBT.Result tres;

            sres = WSMBS.Result.SUCCESS;
            tres = WSMBT.Result.SUCCESS;
            for (int Index = 0; Index < m_scanArea.Count; Index++)
            {
                if (m_nProcotol == 2)
                {
                    //write register
                    if (queue.Count > 0)
                    {
                        WrReg_Coil node = queue.Dequeue();
                        bool       val  = (node.val != 0);
                        if (node.cmd == 0)
                        {
                            tres = tcp_svr.WriteSingleCoil((byte)m_nStation, node.adr, val);
                        }
                        if (node.cmd == 2)
                        {
                            tres = tcp_svr.WriteSingleRegister((byte)m_nStation, node.adr, node.val);
                        }
                    }
                    else
                    {
                        //read register
                        switch (m_nFunc)
                        {
                        case 0:
                            tres = tcp_svr.ReadCoils((byte)m_nStation, m_scanArea[Index].start_adr, (ushort)m_scanArea[Index].length, m_bValue[Index]);
                            break;

                        case 1:
                            tres = tcp_svr.ReadDiscreteInputs((byte)m_nStation, m_scanArea[Index].start_adr, (ushort)m_scanArea[Index].length, m_bValue[Index]);
                            break;

                        case 2:
                            tres = tcp_svr.ReadHoldingRegisters((byte)m_nStation, m_scanArea[Index].start_adr, (ushort)m_scanArea[Index].length, m_sValue[Index]);
                            break;

                        case 3:
                            tres = tcp_svr.ReadInputRegisters((byte)m_nStation, m_scanArea[Index].start_adr, (ushort)m_scanArea[Index].length, m_sValue[Index]);
                            break;
                        }
                    }
                    if (tres == WSMBT.Result.SUCCESS)
                    {
                        nSucc++;
                    }
                    else
                    {
                        nFail++;
                        err_msg = tres.ToString();
                        bRet    = false;
                    }
                }
                else
                {
                    //write register
                    if (queue.Count > 0)
                    {
                        WrReg_Coil node = queue.Dequeue();
                        bool       val  = (node.val != 0);
                        if (node.cmd == 0)
                        {
                            sres = ser_svr.WriteSingleCoil((byte)m_nStation, node.adr, val);
                        }
                        if (node.cmd == 2)
                        {
                            sres = ser_svr.WriteSingleRegister((byte)m_nStation, node.adr, node.val);
                        }
                    }
                    else
                    {
                        //read register
                        switch (m_nFunc)
                        {
                        case 0:
                            sres = ser_svr.ReadCoils((byte)m_nStation, m_scanArea[Index].start_adr, (ushort)m_scanArea[Index].length, m_bValue[Index]);
                            break;

                        case 1:
                            sres = ser_svr.ReadDiscreteInputs((byte)m_nStation, m_scanArea[Index].start_adr, (ushort)m_scanArea[Index].length, m_bValue[Index]);
                            break;

                        case 2:
                            sres = ser_svr.ReadHoldingRegisters((byte)m_nStation, m_scanArea[Index].start_adr, (ushort)m_scanArea[Index].length, m_sValue[Index]);
                            break;

                        case 3:
                            sres = ser_svr.ReadInputRegisters((byte)m_nStation, m_scanArea[Index].start_adr, (ushort)m_scanArea[Index].length, m_sValue[Index]);
                            break;
                        }
                        if (tres == WSMBT.Result.SUCCESS)
                        {
                            nSucc++;
                        }
                        else
                        {
                            nFail++;
                            err_msg = tres.ToString();
                            bRet    = false;
                        }
                    }
                }
            }
            return(bRet);
        }