目前共有6篇帖子。
【抗干擾代碼】AVR單片機自動複位由於電壓不足導致ENC28J60網卡出現的故障
1樓 巨大八爪鱼 2017-5-28 17:53
【main.c】
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/sfr_defs.h>
#include <stdio.h>
#include "uip/uip_arp.h"
#include "uip/timer.h"
#include "uip/uip.h"
#include "ENC28J60.h"

#define ETHHDR ((struct uip_eth_hdr *)&uip_buf[0])

const uint8_t seg8[] PROGMEM = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90}; // 共陽數碼管段碼錶
uint8_t flag_disp = 0; // 是否插了網線, 初值必須為0 (開機時只有網線是插上的, 才會自動觸發LINK中斷)
uint8_t pkt_in = 0; // 是否有數據包進來
uint16_t num_disp = 0; // 數碼管顯示的數字
clock_time_t clocktime = 0; // 當前時鐘值
uint16_t next_ptr = 0;

clock_time_t clock_time(void)
{
    return clocktime;
}

void uip_appcall(void)
{
    char ch;
    if (uip_connected())
        uip_conn->appstate = 0;
    if (uip_newdata())
        uip_conn->appstate = 1;
    if (uip_acked())
        uip_conn->appstate++;

    if (uip_acked() || uip_newdata() || uip_rexmit())
    {
        switch (uip_conn->appstate)
        {
        case 1:
            uip_send_P(PSTR("HTTP/1.1 200 OK\r\nContent-Length: 86\r\nKeep-Alive: timeout=5, max=100\r\nConnection: Keep-Alive\r\nContent-Type: text/html\r\n\r\n<b>Hello World!</b><br>This is a very <i>long</i> string!!!<br><b>Connection ID: </b>"));
            break;
        case 2:
            ch = '0' + (uip_conn - uip_conns);
            uip_send(&ch, 1);
            break;
        case 3:
            uip_close();
        }
    }
}

void myapp_init(void)
{
    uip_listen(HTONS(80));
}

void read_packet(void)
{
    uint16_t status[2];

    ENC28J60_SelectBank(0);
    num_disp = ENC28J60_Read(ERXWRPTL) | (ENC28J60_Read(ERXWRPTH) << 8); // 數碼管上顯示接收寫指針的位置
    ENC28J60_Write(ERDPTL, next_ptr & 0xff); // 將讀指針移動到當前數據包處
    ENC28J60_Write(ERDPTH, next_ptr >> 8);

    ENC28J60_ReadBuffer((uint8_t *)&next_ptr, sizeof(next_ptr)); // 讀取下一個數據包的位置
    ENC28J60_ReadBuffer((uint8_t *)status, sizeof(status)); // status vector
    uip_len = status[0] - 4; // 數據包大小
   
    if (uip_len <= UIP_BUFSIZE)
        ENC28J60_ReadBuffer(uip_buf, uip_len);
    else
        uip_len = 0; // 內存不足, 丟棄
    // 注意: 數據包與數據包之間可能有填充位元組

    ENC28J60_Write(ERXRDPTL, next_ptr & 0xff); // 允許之後接收的數據將該區域覆蓋
    ENC28J60_Write(ERXRDPTH, next_ptr >> 8);
    ENC28J60_SetBits(ECON2, ECON2_PKTDEC, ENCSET); // 數據包數減1
}

void send_packet(void)
{
    GICR &= ~_BV(INT2);
    ENC28J60_SelectBank(0);
    ENC28J60_Write(ETXSTL, ENC_SEND_START & 0xff); // 數據首地址
    ENC28J60_Write(ETXSTH, ENC_SEND_START >> 8);
    ENC28J60_Write(ETXNDL, (ENC_SEND_START + uip_len) & 0xff); // 數據尾地址
    ENC28J60_Write(ETXNDH, (ENC_SEND_START + uip_len) >> 8);

    ENC28J60_Write(EWRPTL, ENC_SEND_START & 0xff); // 設置寫指針位置
    ENC28J60_Write(EWRPTH, ENC_SEND_START >> 8);
    ENC28J60_WriteBufferByte(0); // 寫入控制位元組
    ENC28J60_WriteBuffer(uip_buf, uip_len); // 寫入要發送的數據
    ENC28J60_SetBits(ECON1, ECON1_TXRTS, ENCSET); // 開始發送

    while (ENC28J60_Read(ECON1) & ECON1_TXRTS); // 等待發送完畢
    GICR |= _BV(INT2);
}

void beep(void)
{
    uint8_t old = TCCR2;
    uint16_t i;
    TIMSK &= ~_BV(TOIE2); // 關閉定時器2中斷
    TCCR2 = _BV(WGM20) | _BV(COM21) | _BV(CS21); // Phase Correct PWM, 8分頻: 2.71kHz
    TIFR = _BV(TOV2);
    for (i = 0; i < 2000; i++) // 738ms
    {
        while ((TIFR & _BV(TOV2)) == 0);
        TIFR = _BV(TOV2); // 清除標誌
    }
    TCCR2 = old;
    TIMSK |= _BV(TOIE2); // 重開定時器2中斷
}

int main(void)
{
    struct timer arp_timer, periodic_timer;
    uint8_t i;
    uip_ipaddr_t ipaddr;

    ACSR = _BV(ACD); // 禁用模擬比較器

    // 蜂鳴器配置
    PORTD = _BV(PORTD7);
    DDRD = _BV(DDB7);
    OCR2 = 0x80; // 占空比50%
    if (MCUCSR & _BV(WDRF))
    {
        // 若觸發了看門狗複位, 則蜂鳴器響鈴
        MCUCSR &= ~_BV(WDRF);
        beep();
    }

    WDTCR = _BV(WDE) | _BV(WDP2) |  _BV(WDP1) | _BV(WDP0); // 看門狗配置

    // SPI埠配置
    DDRB = _BV(DDB7) | _BV(DDB5) | _BV(DDB4);
    SPSR = _BV(SPI2X); // 選擇2分頻: 11.0592MHz/2=5.5296MHz, 遠低於最高允許速度20MHz
    SPCR = _BV(SPE) | _BV(MSTR); // 開SPI, 設為主模式

    // 中斷引腳配置(INT2_PB2): 下降沿觸發
    MCUCSR &= ~_BV(ISC2);
    // 注意: 即使GICR中的INT2沒有打開, 但只要INT2上有下降沿, GIFR中的INTF2標誌也會置位
    // 只有此後打開了INT2中斷和全局中斷, 才執行中斷函數

    // 數碼管動態掃描配置
    DDRA = 0xff; // 配置段選埠
    PORTA = 0xff; // 熄滅數碼管
    DDRC = _BV(DDC7) | _BV(DDC6) | _BV(DDC5) | _BV(DDC4) | _BV(DDC0); // 配置位選埠
    sei(); // 開總中斷
    TIMSK |= _BV(TOIE0); // 開定時器中斷
    TCNT0 = 0xff; // 先讓定時器溢出一次, 點亮數碼管
    TCCR0 |= _BV(CS02); // 開定時器0: 設為256分頻, 總溢出時間約為5.926ms

    // uip時鐘定時器
    TIMSK |= _BV(TOIE2);
    TCNT2 = 40; // 定時20ms
    TCCR2 = _BV(CS22) | _BV(CS20); // 1024分頻

    timer_set(&arp_timer, CLOCK_SECOND * 10);
    timer_set(&periodic_timer, CLOCK_SECOND / 2);

    ENC28J60_Init();
    uip_init();
    uip_ipaddr(ipaddr, 192, 168, 1, 50); // IP位址
    uip_sethostaddr(ipaddr);
    uip_ipaddr(ipaddr, 192, 168, 1, 1); // 網關
    uip_setdraddr(ipaddr);
    uip_ipaddr(ipaddr, 255, 255, 255, 0); // 子網掩碼
    uip_setnetmask(ipaddr);

    myapp_init();

    GICR |= _BV(INT2); // 開網卡中斷
    while (1)
    {
        // 讀取一個數據包
        if (pkt_in)
        {
            asm("wdr");
            GICR &= ~_BV(INT2); // 進入臨界區之前必須關網卡中斷!
            read_packet();
            ENC28J60_SelectBank(1);
            if (!ENC28J60_Read(EPKTCNT)) // 若已接收完全部數據包
            {
                pkt_in = 0;
                ENC28J60_SetBits(EIE, EIE_PKTIE, ENCSET); // 則重開數據包接收中斷
            }
            GICR |= _BV(INT2); // 重開網卡中斷
        }

        if (uip_len > 0)
        {
            asm("wdr");
            if (ETHHDR->type == htons(UIP_ETHTYPE_IP))
            {
                uip_arp_ipin();
                uip_input();
                if (uip_len > 0)
                {
                    uip_arp_out();
                    send_packet();
                }
            }
            else if (ETHHDR->type == htons(UIP_ETHTYPE_ARP))
            {
                uip_arp_arpin();
                if (uip_len > 0)
                    send_packet();
            }
        }
        else if (timer_expired(&periodic_timer))
        {
            asm("wdr"); // 喂狗
            timer_reset(&periodic_timer);
            for (i = 0; i < UIP_CONNS; i++)
            {
                uip_periodic(i);
                if (uip_len > 0)
                {
                    uip_arp_out();
                    send_packet();
                }
            }
        }

        if (timer_expired(&arp_timer))
        {
            asm("wdr");
            timer_reset(&arp_timer);
            uip_arp_timer();

            /* ----- 抗干擾 ----- */
            // 若網卡控制器自身發生了複位, 或者中斷被意外關閉, 則需要重新初始化 (一般都是因為供電不足導致的)
            if (!pkt_in)
            {
                GICR &= ~_BV(INT2); // 進入臨界區, 關網卡中斷, 防止時序錯亂
                if ((ENC28J60_Read(ECON1) & ECON1_RXEN) == 0) // 檢測到RXEN意外置0, 接收模塊停止工作
                {
                    // 蜂鳴器發出警報
                    for (i = 0; i < 4; i++)
                    {
                        asm("wdr");
                        beep();
                    }

                    // 先暫時讓單片機進入低功耗模式
                    // 增加電壓不足的情況下網卡恢復正常工作的可能性
                    PORTA = 0xff; // 熄滅數碼管
                    TCNT2 = 0; // 用定時器2中斷作為喚醒源
                    // 在這裡應將其他耗電量大的設備全部關閉
                    MCUCR |= _BV(SE) | _BV(SM0); // ADC Noise Reduction Mode
                    asm("sleep");
                    MCUCR &= ~_BV(SE);

                    // 網卡複位
                    next_ptr = 0;
                    ENC28J60_Init();
                    timer_reset(&arp_timer);

                    // 如果網卡電壓不夠, 那麼這裡複位後雖然配置是正確的, 但無法接收任何數據包
                    // 再插一根USB線供電即可解決此問題
                }
                GICR |= _BV(INT2);
            }
        }
    }
}

// 網卡中斷
ISR(INT2_vect)
{
    uint8_t status;
    // 現在INT2為低電平
    ENC28J60_SetBits(EIE, EIE_INTIE, ENCCLR); // 該語句執行完畢後, INT2引腳會回到高電平, 之後新來的網卡中斷都將處於pending狀態
    // 如果在執行該函數期間恰好又來了一個中斷, 那麼肯定能被本次中斷函數處理到
    GICR &= ~_BV(INT2); // 開全局中斷前, 應防止INT2引腳由於外部干擾導致重入本中斷函數
                        // 如果幹擾時間過長, 看門狗將自動複位
    sei(); // 允許數碼管掃描中斷搶佔本中斷, 防止數碼管閃爍
   
    status = ENC28J60_Read(EIR); // 獲取所有網卡中斷的狀態
    // 一個一個處理:
    if (status & EIR_PKTIF)
    {
        /* 收到新數據包 */
        pkt_in = 1;
        ENC28J60_SetBits(EIE, EIE_PKTIE, ENCCLR); // 暫時關閉該中斷
    }
    if (status & EIR_LINKIF)
    {
        ENC28J60_ReadPhy(PHIR); // 清除中斷標誌
        flag_disp = ENC28J60_IsPluggedIn();
    }

    // 處理其他中斷: if (status & ....) {....} // 不能加else!

    ENC28J60_SetBits(EIE, EIE_INTIE, ENCSET); // 如果還有新來的中斷沒處理, 那麼INT2將出現下降沿, 退出後再次執行本函數, 不會和當前的函數嵌套
    cli();
    GICR |= _BV(INT2);
    // 退出時將自動執行sei();
}

// 數碼管動態掃描
// 每次只掃描一位, 從低位到高位
ISR(TIMER0_OVF_vect)
{
    static uint16_t numbuf;
    static uint8_t mask = _BV(PORTC7);
    TCNT0 = 0x90; // 每個數碼管點亮的時間: (256-144)/256 * 5.926ms = 2.592625ms
    if (mask == _BV(PORTC7))
        numbuf = num_disp; // 重裝數字

    PORTC |= _BV(PORTC7) | _BV(PORTC6) | _BV(PORTC5) | _BV(PORTC4) | _BV(PORTC0); // 熄滅之前點亮的數碼管
    PORTA = pgm_read_byte(&seg8[numbuf % 10]); // 設置顯示字元
    PORTC &= ~mask; // 點亮數碼管
   
    // 下一次要點亮的數碼管
    mask >>= 1;
    if (mask == _BV(PORTC3))
    {
        mask = _BV(PORTC0);
        numbuf = flag_disp;
    }
    else if (mask == 0) // 若已掃描完一遍
        mask = _BV(PORTC7); // 則回到最低位
    else
        numbuf /= 10;
}

// uip定時中斷
ISR(TIMER2_OVF_vect)
{
    TCNT2 = 40;
    clocktime++;
}
2樓 巨大八爪鱼 2017-5-28 17:54
【網卡初始化代碼】
// 注意: 執行這些函數時一定要先關閉網卡中斷!!! 防止SPI序列被破壞
extern uint8_t flag_disp;

void ENC28J60_Init(void)
{
    ENC28J60_CS1; // 空閒狀態下CS應該為高電平
    ENC28J60_SystemReset();

    // 設置接收緩衝區的起點和終點
    ENC28J60_Write(ERXSTL, 0); // 起點設為0可以避免網卡本身的bug使讀指針跑飛
    ENC28J60_Write(ERXSTH, 0);
    ENC28J60_Write(ERXNDL, ENC_RECV_END & 0xff);
    ENC28J60_Write(ERXNDH, ENC_RECV_END >> 8);
    ENC28J60_Write(ERXRDPTL, 0); // 數據保護指針的位置
    ENC28J60_Write(ERXRDPTH, 0);

    // 配置MAC
    while ((ENC28J60_Read(ESTAT) & ESTAT_CLKRDY) == 0); // 等待MAC和PHY暫存器穩定
    ENC28J60_SelectBank(2);
    ENC28J60_Write(MACON1, MACON1_TXPAUS | MACON1_RXPAUS | MACON1_MARXEN); // 允許接收, 開流量控制
    ENC28J60_Write(MACON3, MACON3_PADCFG_0 | MACON3_TXCRCEN | MACON3_FRMLNEN | MACON3_FULDPX);
    ENC28J60_Write(MACON4, MACON4_DEFER);
    ENC28J60_Write(MABBIPG, 0x15);
    ENC28J60_Write(MAIPGL, 0x12);
    ENC28J60_Write(MAIPGH, 0x0c);

    // 設置網卡地址
    ENC28J60_SelectBank(3);
    ENC28J60_Write(MAADR1, UIP_ETHADDR0);
    ENC28J60_Write(MAADR2, UIP_ETHADDR1);
    ENC28J60_Write(MAADR3, UIP_ETHADDR2);
    ENC28J60_Write(MAADR4, UIP_ETHADDR3);
    ENC28J60_Write(MAADR5, UIP_ETHADDR4);
    ENC28J60_Write(MAADR6, UIP_ETHADDR5);

    // 配置PHY
    ENC28J60_WritePhy(PHCON1, PHCON1_PDPXMD); // 全雙工模式
    flag_disp = ENC28J60_IsPluggedIn(); // 獲取初始網路連接狀態

    // 允許接收數據包
    ENC28J60_Write(EIE, EIE_PKTIE | EIE_LINKIE | EIE_INTIE); // 如果收到了數據包, 或網路連接發生變化, 就觸發中斷
    ENC28J60_WritePhy(PHIE, PHIE_PLNKIE | PHIE_PGEIE); // 配置PHY中斷 (監測網路連接變化)
    ENC28J60_Write(ECON1, ECON1_RXEN);
}
3樓 巨大八爪鱼 2017-5-28 17:58
【調試用代碼:串口輸出暫存器狀態】
void status_check(void)
{
    char buf[80];
    uint8_t i;
    UBRRL = 5;
    UCSRB = _BV(TXEN);
    ENC28J60_SelectBank(1);
    sprintf_P(buf, PSTR("EIE=%d, EPKTCNT=%d, ECON1=%d, ERXFCON=%d, EIR=%d\r\n"), ENC28J60_Read(EIE), ENC28J60_Read(EPKTCNT), ENC28J60_Read(ECON1), ENC28J60_Read(ERXFCON), ENC28J60_Read(EIR));
    for (i = 0; buf[i] != '\0'; i++)
    {
        UDR = buf[i];
        while ((UCSRA & _BV(UDRE)) == 0);
    }
}
4樓 巨大八爪鱼 2017-5-28 18:08
用一個功率較小的手機充電器上的USB介面作為單片機的電源來測試。測試過程中由於電流不足、電壓不穩定,蜂鳴器響了十幾次(出現Request timed out.的地方),但最終網卡都成功複位了。
【可靠性測試結果】
C:\Users\Octopus>ping 192.168.1.50 -n 100

Pinging 192.168.1.50 with 32 bytes of data:
Reply from 192.168.1.50: bytes=32 time=6ms TTL=128
Reply from 192.168.1.50: bytes=32 time=15ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=5ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=10ms TTL=128
Reply from 192.168.1.50: bytes=32 time=33ms TTL=128
Reply from 192.168.1.50: bytes=32 time=7ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=28ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=5ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=15ms TTL=128
Request timed out.
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=9ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Request timed out.
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=7ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=42ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=15ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=6ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=5ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=5ms TTL=128
Request timed out.
Reply from 192.168.1.50: bytes=32 time=9ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=27ms TTL=128
Reply from 192.168.1.50: bytes=32 time=35ms TTL=128
Reply from 192.168.1.50: bytes=32 time=14ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Request timed out.
Reply from 192.168.1.50: bytes=32 time=5ms TTL=128

Ping statistics for 192.168.1.50:
    Packets: Sent = 100, Received = 82, Lost = 18 (18% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 42ms, Average = 5ms

C:\Users\Octopus>
5樓 巨大八爪鱼 2017-5-28 18:22
在下面的測試中使用單根USB線供電,電壓環境極不穩定。最後單片機進入睡眠模式也未能使網卡恢復正常工作,數碼管最終顯示1    0524,ping的結果為「Reply from 192.168.1.2: Destination host unreachable.」。
不過幾分鐘過去後,蜂鳴器響了起來,網卡再一次恢復工作。
【測試結果】
C:\Users\Octopus>ping 192.168.1.50 -n 100

Pinging 192.168.1.50 with 32 bytes of data:
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=7ms TTL=128
Reply from 192.168.1.50: bytes=32 time=10ms TTL=128
Reply from 192.168.1.50: bytes=32 time=6ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=22ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=15ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=6ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=5ms TTL=128
Reply from 192.168.1.50: bytes=32 time=12ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Request timed out.
Reply from 192.168.1.50: bytes=32 time=6ms TTL=128
Reply from 192.168.1.50: bytes=32 time=6ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Request timed out.
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=21ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=10ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=11ms TTL=128
Request timed out.
Request timed out.
Request timed out.
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.50: bytes=32 time=2005ms TTL=128
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Request timed out.
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Request timed out.
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=1002ms TTL=128
Request timed out.
Request timed out.
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.2: Destination host unreachable.

Ping statistics for 192.168.1.50:
    Packets: Sent = 100, Received = 47, Lost = 53 (53% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 2005ms, Average = 76ms

C:\Users\Octopus>

C:\Users\Octopus>ping 192.168.1.50 -n 100

Pinging 192.168.1.50 with 32 bytes of data:
Reply from 192.168.1.2: Destination host unreachable.
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Request timed out.
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Request timed out.
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Request timed out.
Request timed out.

Ping statistics for 192.168.1.50:
    Packets: Sent = 9, Received = 5, Lost = 4 (44% loss),
Approximate round trip times in milli-seconds:
    Minimum = 2ms, Maximum = 4ms, Average = 2ms
Control-C
^C
C:\Users\Octopus>
6樓 巨大八爪鱼 2017-5-28 18:26
現在改用兩根USB線來供電,網卡終於穩定工作。
不過為了保險起見,程序中仍應該保留網卡自動複位的代碼。
【測試結果】
C:\Users\Octopus>ping 192.168.1.50 -n 100

Pinging 192.168.1.50 with 32 bytes of data:
Reply from 192.168.1.50: bytes=32 time=6ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=11ms TTL=128
Reply from 192.168.1.50: bytes=32 time=37ms TTL=128
Reply from 192.168.1.50: bytes=32 time=7ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=5ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=46ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=10ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=7ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=7ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=13ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=20ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=13ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=27ms TTL=128
Reply from 192.168.1.50: bytes=32 time=29ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=9ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=7ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=44ms TTL=128
Reply from 192.168.1.50: bytes=32 time=5ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=9ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=13ms TTL=128
Reply from 192.168.1.50: bytes=32 time=6ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=17ms TTL=128
Reply from 192.168.1.50: bytes=32 time=70ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=6ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=9ms TTL=128
Reply from 192.168.1.50: bytes=32 time=4ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=7ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=71ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=32ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=6ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=16ms TTL=128
Reply from 192.168.1.50: bytes=32 time=22ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128
Reply from 192.168.1.50: bytes=32 time=3ms TTL=128
Reply from 192.168.1.50: bytes=32 time=2ms TTL=128
Reply from 192.168.1.50: bytes=32 time=1ms TTL=128

Ping statistics for 192.168.1.50:
    Packets: Sent = 100, Received = 100, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 71ms, Average = 7ms

C:\Users\Octopus>

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
 
 
©2010-2024 Arslanbar [手機版] [桌面版]
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。