class DM9051 - DM9051 Ethernet NIC Control
This class controls Ethernet NIC devices of DM9051
.
Currently, only the EC600N/EG912N/EG915N series and EC800MCN_LE are supported.
Constructor
ethernet.DM9051
class ethernet.DM9051(mac, ip='', subnet='', gateway='', spi_port=-1, spi_cs_pin=-1, extint_pin=-1, reset_pin=-1, work_mode=0)
Loads DM9051 driver, initializes DM9051 Ethernet NIC and returns DM9051 NIC object.
Parameter:
mac
- Byte stream. MAC address with a length of 6 bytes.ip
- IP address of Ethernet NIC. The default value is an empty string'', indicating that the default IP address is192.168.1.100
in the program.subnet
- Subnet mask address of Ethernet NIC. The default value is an empty string'', indicating that255.255.255.0
is used as the subnet mask.gateway
- Gateway address of Ethernet NIC. The default value is an empty string'', indicating that the last bit of IP address is replaced with1
as the gateway address.spi_port
- Connect to SPI port ofDM9051
. The default value is-1
, indicating that the last configured value is used and the default configuration in the program isSPI1
port.spi_cs_pin
- Connect toSPI
chip select GPIO pin ofDM9051
. The default value is-1
, indicating that the last configured value is used and the default configuration in the program isPin.GPIO13
.extint_pin
- Connect to external interrupt GPIO pin ofDM9051
. The default value is-1
, indicating that the last configured value is used and the default configuration in the program isPin.GPIO19
.reset_pin
- Connect to reset GPIO pin ofDM9051
. The default value is-1
, indicating that the last configured value is used and the default configuration in the program isPin.GPIO17
.work_mode
- Configure Ethernet working mode. The default mode is terminal mode.0
and1
respectively represents terminal mode and gateway mode. Terminal mode indicates that the module is used as a terminal device to connect to a network supply device to access the network. Gateway mode indicates that the module is used as a gateway to provide network access for external devices through LTE network.
The default value varies from platform to platform. It is recommended to define the available GPIO usage
Methods
DM9051.set_addr
nic.set_addr(ip, subnet, gateway)
Configures NIC static IP Address.
Parameter:
ip
- IP address of Ethernet NIC. The value is an empty string'', indicating that the default IP address is192.168.1.100
in the program.subnet
- Subnet mask address of Ethernet NIC. The value is an empty string'', indicating that255.255.255.0
is used as the subnet mask.gateway
- Gateway address of Ethernet NIC. The value is an empty string'', indicating that the last bit of IP address is replaced with1
as the gateway address.
Return Value:
0 - Successful execution
Other values - Failed execution
- Example
nic.set_addr('192.168.1.100', '', '')
DM9051.set_dns
nic.set_dns(primary_dns, secondary_dns)
Configures NIC DNS server.
Parameter:
primary_dns
- Primary address ofDNS
server .secondary_dns
- Secondary address ofDNS
server.
Return Value:
0 - Successful execution
Other values - Failed execution
Example:
nic.set_dns('8.8.8.8', '114.114.114.114')
DM9051.set_up
nic.set_up()
Enables NIC and then NIC processes network interfaces and messages normally.
DM9051.set_down
nic.set_down()
Disables NIC and then NIC no longer processes network interfaces and messages.
DM9051.dhcp
nic.dhcp()
Obtains dynamic IP. This method is used in the terminal mode so that IP information can be automatically obtained.
Return Value:
0 - Successful execution
Other values - Failed execution
DM9051.ipconfig
nic.ipconfig()
Obtains NIC network information. MAC address, host name, IP address type, IP address, subnet mask, gateway address and DNS server address can be obtained through this method.
Return Value:
List type.
The format is as follows:
[(mac, hostname), (iptype, ip, subnet, gateway, primary_dns,secondary_dns)].
Parameter | Type | Description |
---|---|---|
mac |
str |
mac address and the format is'XX-XX-XX-XX-XX-XX' . |
hostname |
str |
NIC name |
iptype |
str |
ip type. 4 indicates IPv4 and 6 indicates IPv6 . Currently, only IPv4 is supported. |
ip |
str |
IP address |
subnet |
str |
Subnet mask |
gateway |
str |
Gateway address |
primary_dns |
str |
Primary address of DNS server |
secondary_dns |
str |
Secondary address of DNS server |