public void ExWriteToSqlDB_StringData_Return2() { string[] data = new string[] { "111.111.111.111", "9", "", "9", "", "9", "", "9", "", "9", "", "9", "", "9", "", "9", "", "9", "" }; string[] setting = new string[] { "111.111.111.111", "test", "login", "pass", "False" }; int monitor_id = 2; holdingRegisters.ReadHoldingRegisters(Arg.Any <ModbusIpMaster>(), 1).ReturnsForAnyArgs("1"); holdingRegisters.CreateModBus(Arg.Any <TcpClient>(), out Arg.Any <ModbusIpMaster>()).Returns(true); Port port = new Port(logger, holdingRegisters, 1); int actual = port.Start_Processing(data, monitor_id, setting); Assert.That(actual, Is.EqualTo(2)); }
public void Poluminal_DataRowAndList_ReturnList() { List <string> ans = new List <string>(); string[] data = new string[] { "111.111.111.111", "9", "1", "9", "1", "9", "1", "9", "1", "9", "", "9", "", "9", "", "9", "", "9", "" }; holdingRegisters.ReadHoldingRegisters(Arg.Any <ModbusIpMaster>(), 1).ReturnsForAnyArgs("1000"); holdingRegisters.CreateModBus(Arg.Any <TcpClient>(), out Arg.Any <ModbusIpMaster>()).Returns(true); Port port = new Port(logger, holdingRegisters, 1); ans = port.ReadDataTcp(data); Assert.IsNotNull(ans); }
/// <summary> /// Подключение к прибору по протоколу TCP /// </summary> /// <returns></returns> public int ConnectTcp(string ipAddress) { if (master_tcp != null) { master_tcp.Dispose(); } if (tcpClient != null) { tcpClient.Close(); } try { tcpClient = new TcpClient(); IAsyncResult asyncResult = tcpClient.BeginConnect(ipAddress, 502, null, null); asyncResult.AsyncWaitHandle.WaitOne(3000, true); //ожидание 3 секунды if (!asyncResult.IsCompleted) { tcpClient.Close(); error = $"{name_monitor[monitor]}. Ошибка подключения, проверьте параметры подключения в файле конфигурации"; Debug.WriteLine(error); _logger.Error(error); return(0); } // Создание ModbusTCP соединения try { bool master_flag = _modbustcp.CreateModBus(tcpClient, out master_tcp); if (!master_flag) { throw new InvalidOperationException(); } } catch (InvalidOperationException ex) { error = $"{name_monitor[monitor]}. Прибор недоступен. Проверьте статус прибора или соединения"; Debug.WriteLine(error); _logger.Error(error, ex); return(1); } return(11); } catch (ArgumentNullException ex) { error = $"{name_monitor[monitor]}. Файл конфигурации недоступен. Выполните конфигурирование программы"; _logger.Error(error, ex); Debug.WriteLine(error); return(4); } }
public void ReadDataExcept1_StringData_Returt1() { string[] data = new string[] { "1", "3", "4" }; string[] settings = new string[] { "3" }; int actual; int monitor_id = 1; holdingRegisters.ReadHoldingRegisters(Arg.Any <ModbusIpMaster>(), Arg.Any <ushort>()).Throws(new Exception()); holdingRegisters.CreateModBus(Arg.Any <TcpClient>(), out Arg.Any <ModbusIpMaster>()).Returns(true); var sut = new Port(logger, holdingRegisters, 1); actual = sut.Start_Processing(data, monitor_id, settings); Assert.That(actual, Is.EqualTo(1)); }