public void CreateMapFromList()
        {
            List <IWriterMap <InsuranceMap> > listmap = new List <IWriterMap <InsuranceMap> >();
            var map1 = new WriteMap <InsuranceMap>(a => a.PolicyId, 0, "policy", true);
            var map2 = new WriteMap <InsuranceMap>(a => a.County, 1, "country", false);

            listmap.Add(map1);
            listmap.Add(map2);
            _insuranceMapper = new CsvWriterMapper <InsuranceMap>();
            _insuranceMapper.SetMap(listmap);
        }
Example #2
0
        public override bool CustomInit(DeviceInfo deviceInfo)
        {
            if (deviceInfo == null)
            {
                return(false);
            }

            try
            {
                device = deviceInfo;
                LoadSettings();
                if (protocol == "modbustcp")
                {
                    modbusCommand = new ModbusTCP(ipAddress, port);
                }

                if (protocol == "modbusrtu")
                {
                    modbusCommand = new ModbusRTU(portName, baudRate, parity, dataBits, stopBits);
                }

                if (protocol == "modbusascii")
                {
                    modbusCommand = new ModbusASCII(portName, baudRate, parity, dataBits, stopBits);
                }

                modbusCommand.OnMessage += modbusCommand_OnMessage;

                readInputsReadMap = new ReadInputs(slaveId, modbusCommand, device, maxNumberReadRegistersAtTime,
                                                   registerShift);
                readInputsReadMap.OnMessage += OnNewMessage;
                readInputsReadMap.InitMap();

                readCoilsReadMap = new ReadCoils(slaveId, modbusCommand, device, maxNumberReadRegistersAtTime,
                                                 registerShift);
                readCoilsReadMap.OnMessage += OnNewMessage;
                readCoilsReadMap.InitMap();

                readInputRegisters = new ReadInputRegisters(slaveId, modbusCommand, device, maxNumberReadRegistersAtTime,
                                                            registerShift);
                readInputRegisters.OnMessage += OnNewMessage;
                readInputRegisters.InitMap();

                readHoldingRegisters = new ReadHoldingRegisters(slaveId, modbusCommand, device, maxNumberReadRegistersAtTime,
                                                                registerShift);
                readHoldingRegisters.OnMessage += OnNewMessage;
                readHoldingRegisters.InitMap();

                writeSingleCoil            = new WriteSingleCoil(slaveId, modbusCommand, device, Locker);
                writeSingleCoil.OnMessage += OnNewMessage;
                writeSingleCoil.InitMap();

                writeSingleRegister            = new WriteSingleRegister(slaveId, modbusCommand, device, Locker);
                writeSingleRegister.OnMessage += OnNewMessage;
                writeSingleRegister.InitMap();

                writeMultipleCoils            = new WriteMultipleCoils(slaveId, modbusCommand, device, Locker);
                writeMultipleCoils.OnMessage += OnNewMessage;
                writeMultipleCoils.InitMap();

                writeMultipleRegisters            = new WriteMultipleRegisters(slaveId, modbusCommand, device, Locker);
                writeMultipleRegisters.OnMessage += OnNewMessage;
                writeMultipleRegisters.InitMap();

                new PlcThread(CustomWorkThread, null, "ModbusMasterIO_CustomWorkThread").Start();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }