private static float ReadAutonA114(Modbus.Device.IModbusSerialMaster master, double serialDevice, byte IDAddress) { //return 10f; string deviceName = "A114*." + ((serialDevice < 1000) ? "0" + ((int)serialDevice).ToString() : ((int)serialDevice).ToString()); float level = -1; for (int i = 0; i < 3; i++) { try { AutonDeviceDisconnect(master, IDAddress); System.Threading.Thread.Sleep(5000); AutonDeviceConnect(master, deviceName, IDAddress); Authenticate(master, IDAddress); CurrentStateCheck(master, IDAddress); SettingAuton(master, IDAddress); level = (float)SingleMeasure(master, IDAddress); AutonDeviceDisconnect(master, IDAddress); break; } catch { System.Threading.Thread.Sleep(5000); } } return(level); }
private static void StartPorts() { foreach (InputM inputM in Inputs) { if (!((Service.InputCommon)inputM.Input).IsUsed) { continue; } if (inputM.Input.GetType() == typeof(Service.InputSerial)) { SerialPort port = new SerialPort() { PortName = ((Service.InputSerial)inputM.Input).PortName, BaudRate = ((Service.InputSerial)inputM.Input).BaudRate, Parity = ((Service.InputSerial)inputM.Input).Parity, StopBits = ((Service.InputSerial)inputM.Input).StopBits, Handshake = ((Service.InputSerial)inputM.Input).Handshake, ReadBufferSize = ((Service.InputSerial)inputM.Input).ReadBufferSize, ReadTimeout = ((Service.InputSerial)inputM.Input).ReadTimeout, DtrEnable = ((Service.InputSerial)inputM.Input).Dtr, RtsEnable = ((Service.InputSerial)inputM.Input).Rts }; SerialPorts.Add(port); if (((Service.InputCommon)inputM.Input).InputType == Service.InputType.COMText) { port.DataReceived += Port_DataReceived; } else { Modbus.Device.IModbusSerialMaster serialMaster = Modbus.Device.ModbusSerialMaster.CreateRtu(port); serialMaster.Transport.Retries = 3; port.ReadTimeout = 3000; port.WriteTimeout = 3000; serialMaster.Transport.WaitToRetryMilliseconds = 3000; inputM.MasterSerial = serialMaster; } try { port.Open(); } catch { Status = 3; new Service.MessageView("Не удается подключиться к " + port.PortName + " порту", "Ошибка", Service.MessageViewMode.Error); } ResetSerialPort.Start(); } else { TcpClient client = new TcpClient(); client.BeginConnect(((Service.InputEthernet)inputM.Input).IPSlave, ((Service.InputEthernet)inputM.Input).Port, null, null); inputM.MasterTCP = Modbus.Device.ModbusIpMaster.CreateIp(client); inputM.MasterTCP.Transport.Retries = 1; inputM.MasterTCP.Transport.WaitToRetryMilliseconds = 900; } } if (TimerWorkModbus == null) { TimerWorkModbus = new Timer(1000); TimerWorkModbus.Enabled = true; TimerWorkModbus.Elapsed += TimerWorkModbus_Elapsed; //TimerWorkModbus.AutoReset = false; } Status = 2; }