public static void Main() { led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState); config = new I2CDevice.Configuration(address, clockRateKHz); device = new I2CDevice(config); WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true); Dhcp.EnableDhcp(new byte[] { 0x00, 0x26, 0x1C, 0x7B, 0x29, 0xE8 }, "tt"); while (true) { uploadData(gatherData()); getHeaterStatus(); setHeaterStatus(); Thread.Sleep(updateTime); } }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append("Description : ").AppendLine(Description); sb.Append("MacAddress : ").AppendLine(MacAddress); sb.Append("Index : ").AppendLine(Index.ToString()); sb.Append("Id : ").AppendLine(Id.ToString()); sb.Append("Type : ").AppendLine(AdapterType); sb.Append("DHCP : ").AppendLine(Dhcp.ToString()); sb.AppendLine("Gateways :"); foreach (IpAddressInfo item in Gateways) { sb.AppendLine(item.ToString()); } sb.AppendLine("IpAdresses :"); foreach (IpAddressInfo item in IpAddresses) { sb.AppendLine(item.ToString()); } return(sb.ToString()); }
/// <summary> /// Initialize connection /// </summary> public DataPointService(Credentials credentials, string projectName, string hubId, int intervalMilliseconds) { // Configure Internet connection byte[] mac = { 0x00, 0x26, 0x1C, 0x7B, 0x29, 0xE8 }; string hostname = "idiotsdk"; WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true); Dhcp.EnableDhcp(mac, hostname); Dhcp.RenewDhcpLease(); // Set current time NTPTime("pool.ntp.org"); // Set interval between requests this.RequestInterval = intervalMilliseconds; this.username = credentials.Username; this.credentials = credentials; this.projectName = projectName; this.hubId = hubId; // TODO: Display info on screen module }
/// <summary> /// Синхронный запуск сканирования. /// </summary> public void Start() { // Статусы. InProgress = true; Stopped = false; // Перебор подсетей и опрос арендованных айпи-адресов по snmp. Logger.AddLog("Определение списка IP-адресов подсетей."); foreach (var subnet in subnets) { try { subnet.Clients = Dhcp.FindDhcpClients(dncpServer, subnet.Address); } catch (Exception ex) { Logger.AddLog(ex.Message); } } ProgressMax = subnets.Select(x => x.Clients.Count).Sum(); ProgressValue = 0; Logger.AddLog("Опрос IP-адресов."); foreach (var subnet in subnets) { if (subnet.Clients.Any()) { foreach (var addr in subnet.Clients) { // Токен остановки выполнения. if (token.IsCancellationRequested) { InProgress = false; Stopped = true; return; } // Установка прогресса выполнения. ProgressPercent = ++ProgressValue / ProgressMax; // Переменная ответа. SnmpV1Packet response; // Отправка запроса. try { response = SendRequest(addr.Ip); } catch { continue; } // Запись значений. string netname = response.Pdu.VbList[0].Value.ToString(); string model = response.Pdu.VbList[1].Value.ToString(); string serialNumber = response.Pdu.VbList[2].Value.ToString(); var printer = new Printer(subnet, addr.Ip, model, serialNumber, netname); // Валидация и добавление принтера в репозиторий. List <ValidationResult> results = printer.Validate(new ValidationContext(printer)).ToList(); if (!results.Any()) { subnet.AddPrinter(printer); DeviceRepository.AddPrinter(printer); Logger.AddLog($"Обнаружен принтер - {printer.Model}, сетевое имя - {printer.NetName}, IP - {printer.Ip}."); } } if (!DeviceRepository.Subnets.Contains(subnet)) { DeviceRepository.AddSubnet(subnet); } } else { Logger.AddLog($"В подсети {subnet.Address} нет арендованных IP адресов."); } } Logger.AddLog("Сканирование завершено."); InProgress = false; Stopped = true; }
/// <summary> /// Writes DHCP configuration data to the diagnostic output /// </summary> /// <param name="dhcp">The DHCP configuration data to write</param> private void OutputDHCPInfo(Dhcp dhcp) { this.OutputIpAddressInfo(dhcp.Address); this.OutputDiagnosticString(" Lease Obtained {0}\n", dhcp.LeaseObtained.ToLocalTime().ToString()); this.OutputDiagnosticString(" Lease Expires {0}\n", dhcp.LeaseExpires.ToLocalTime().ToString()); }
/// <summary> /// Initalizes the network shield to use a DHCP connection and the provided MAC address. /// </summary> /// <param name="mac"> /// This must be a unique MAC address value represented as a byte array. /// Here is a resource for generating random MAC addresses: http://www.macvendorlookup.com/ /// </param> public static void Initialize(byte[] mac) { // Configure the ethernet port WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9, true); // WIZnet interface on FEZ Panda Dhcp.EnableDhcp(mac, "FEZDomino"); }