예제 #1
0
파일: WrapperBll.cs 프로젝트: wpmyj/OF2.0
        public void sendCommand(CommDeviceModbuseControlEntity obj)
        {
            COMMUNICATERESULT ret = new COMMUNICATERESULT();

            byte[]              tempbyte = new byte[2];
            CommandClass        OneSetCommand;
            List <CommandClass> SetCommandList = new List <CommandClass>();
            bool isEnabled = ReceiveTimer.Enabled;

            if (isEnabled)
            {
                ReceiveTimer.Stop();
            }
            try
            {
                if ((Port.PortType == Protocol.Modbus_USBPort)) //USB端口Modbus协议特殊处理
                {
                    SetCommandList = CommandCreat.CreatModbusSetDivInfoCommandList(Port.PortType, (byte)obj.DivID, obj.functioncode, obj.SetData, obj.SetInfoStartAdr, obj.RegisterLen);
                    lock (LockObject)
                    {
                        ret = PortBll.SetData(SetCommandList);
                    }
                }
                else
                {
                    OneSetCommand = CommandCreat.CreatModbusSetDivInfoCommand(Port.PortType, (byte)obj.DivID, obj.functioncode, obj.SetData, obj.SetInfoStartAdr, obj.RegisterLen);
                    lock (LockObject)
                    {
                        ret = PortBll.SetData(OneSetCommand);
                    }
                }
                obj.IsSuccess = ret == COMMUNICATERESULT.OK ? true : false;
            }
            finally
            {
                if (isEnabled)
                {
                    ReceiveTimer.Start();
                }
            }
        }
예제 #2
0
파일: WrapperBll.cs 프로젝트: wpmyj/OF2.0
        public void SetDivInfo(Object Object)
        {
            CommDeviceModbuseControlEntity tempEntity = new CommDeviceModbuseControlEntity();
            COMMUNICATERESULT ret = new COMMUNICATERESULT();

            byte[]              tempbyte = new byte[2];
            CommandClass        OneSetCommand;
            List <CommandClass> SetCommandList = new List <CommandClass>();

            if (ReceiveTimer.Enabled)
            {
                ReceiveTimer.Stop();
            }
            try
            {
                if (Object is CommDeviceModbuseControlEntity)
                {
                    tempEntity = (CommDeviceModbuseControlEntity)Object;
                    if ((Port.PortType == Protocol.Modbus_USBPort)) //USB端口Modbus协议特殊处理
                    {
                        SetCommandList = CommandCreat.CreatModbusSetDivInfoCommandList(Port.PortType, (byte)tempEntity.DivID, tempEntity.functioncode, tempEntity.SetData, tempEntity.SetInfoStartAdr, tempEntity.RegisterLen);
                        lock (LockObject)
                        {
                            ret = PortBll.SetData(SetCommandList);
                        }
                    }
                    else
                    {
                        switch (Port.PortType)
                        {
                        case Protocol.Modbus_SerialPort:
                        case Protocol.Modbus_TCPIPPort:
                            OneSetCommand = CommandCreat.CreatModbusSetDivInfoCommand(Port.PortType, (byte)tempEntity.DivID, tempEntity.functioncode, tempEntity.SetData, tempEntity.SetInfoStartAdr, tempEntity.RegisterLen);
                            break;

                        default:
                            OneSetCommand = CommandCreat.CreatModbusSetDivInfoCommand(Port.PortType, (byte)tempEntity.DivID, tempEntity.functioncode, tempEntity.SetData, tempEntity.SetInfoStartAdr, tempEntity.RegisterLen);
                            break;
                        }
                        lock (LockObject)
                        {
                            ret = PortBll.SetData(OneSetCommand);
                        }
                    }
                    if (ret == COMMUNICATERESULT.OK)
                    {
                        tempEntity.IsSuccess = true;
                    }
                }
            }
            finally
            {
                ReceiveTimer.Start();
            }
            switch (Port.PortType)//只有在Modbus协议通讯时才返回通讯结果
            {
            case Protocol.Modbus_SerialPort:
            case Protocol.Modbus_TCPIPPort:
            case Protocol.Modbus_USBPort:
                if (SetInfoResultMethod != null)
                {
                    SetInfoResultMethod.Invoke(tempEntity);
                }
                break;
            }
        }