public void TryConnectNpt(string portname, string connectorId, string PNPDeviceID) { ModbusDevice <NptRegisters> dev = new ModbusDevice <NptRegisters>(); WriteLog("Try connect " + PNPDeviceID + " on " + portname); if (dev.Connect(portname)) { WriteLog("Port Info for " + PNPDeviceID + ":" + dev.PortInfo()); System.Threading.Thread.Sleep(1000); WriteLog("Read DEVTYPE " + PNPDeviceID + " from " + NptRegisters.Registers._DEVTYPE); if (dev.ExecuteRead(NptRegisters.Registers._DEVTYPE, 2)) { System.Threading.Thread.Sleep(50); WriteLog("Read VERSION " + PNPDeviceID + " from " + NptRegisters.Registers._VERSION); if (dev.ExecuteRead(NptRegisters.Registers._VERSION, 2)) { WriteLog("Check DEVTYP " + PNPDeviceID + " for " + dev.RegistersData.DEVTYPE); if (DevTypesList.ContainsKey(dev.RegistersData.DEVTYPE)) { dev.DisConnect(); AttachedDevices.Add(connectorId, PNPDeviceID); DevAttachedEvent(new DevEventArgs() { ConnectorId = connectorId, PortName = portname, NptType = dev.RegistersData.DEVTYPE, PNPDeviceID = PNPDeviceID }); return; } } } } DevNotDetectedEvent(new DevEventArgs()); dev.DisConnect(); }
public void Init() { SlaveDeviceContext = new ModbusDevice <TCPContext>(new TCPContext(Hostname, Port), SlaveId); SlaveDeviceContext.Connect(); }