Hi everyone,
coming back from vacation i've prepared a little hardware to evaluate the ENC28J60 chip and the SPI Ethernet library.
It is all OK, but i need to manually open/close my TCP connection, and i can't see a working way: it seems that SPI_Ethernet_UserTCP automatically opens/closes connection and i can't overload this part (i need that because i'm writing a ModBUS TCP master/slave protocol) .
I can accept an automatic connection opening, but i need at least to control closing job...
Can you help me (especially Bruno )?
Thank you very much
CG
A problem with SPI Ethernet driver
-
- Posts: 144
- Joined: 09 May 2007 23:31
- Location: Florence - Italy
- Contact:
Hi CG,
unfortunately there is no way to keep a TCP connection alive with the present and very next release of the ethernet library . the socket is closed when SPI_Ethernet_UserTCP returns.
a TCP/IP socket with full TCP/IP stack is planned in the future.
what do you think about using modbus over UDP ?
unfortunately there is no way to keep a TCP connection alive with the present and very next release of the ethernet library . the socket is closed when SPI_Ethernet_UserTCP returns.
a TCP/IP socket with full TCP/IP stack is planned in the future.
what do you think about using modbus over UDP ?
Bruno
Bored with 7-segment ? Try the [url=http://www.micro-examples.com/public/microex-navig/doc/079-touchclock.html]TouchClock[/url]
Bored with 7-segment ? Try the [url=http://www.micro-examples.com/public/microex-navig/doc/079-touchclock.html]TouchClock[/url]
-
- Posts: 144
- Joined: 09 May 2007 23:31
- Location: Florence - Italy
- Contact:
Thank you, bruno,bruno wrote:Hi CG,
unfortunately there is no way to keep a TCP connection alive with the present and very next release of the ethernet library . the socket is closed when SPI_Ethernet_UserTCP returns.
a TCP/IP socket with full TCP/IP stack is planned in the future.
what do you think about using modbus over UDP ?
unfortunately i need modbus over TCP because SCADAs use this protocol, and not the UDP one. I don't know how did you implement these functions
My team would be happy to help completing the TCP/IP stack, would you like to share libraries with us?
Please reply (by PM if you prefer!)...
(i'm substantially an hardware engineer )
Thanks
CG
Re: A problem with SPI Ethernet driver
hello
Have you had any response regarding the TCP / IP module ENC28J60 because I'd like to create a remote that sends information to the server TCP / IP.
My remote control is a client, and he therefore possible to use this module ENC28J60 as a customer?
Other problems are that I should send a message from the server so that both system logs and sends its message and also a random connection loss.
I would like my client connects to the server, and remains connected after sending my message.
here is my code the:
He would have my remote sends messages through the port 3040, but I can not define it uses that port, though I put the remotePort = 3040.
thank you for your help in advance.
bye
Have you had any response regarding the TCP / IP module ENC28J60 because I'd like to create a remote that sends information to the server TCP / IP.
My remote control is a client, and he therefore possible to use this module ENC28J60 as a customer?
Other problems are that I should send a message from the server so that both system logs and sends its message and also a random connection loss.
I would like my client connects to the server, and remains connected after sending my message.
here is my code the:
Code: Select all
program enc_ethernet
' mE ehternet NIC pinout
dim
SPI_Ethernet_Rst as sbit at LATC0_bit ' for writing to output pin always use latch (PIC18 family)
SPI_Ethernet_CS as sbit at LATC1_bit ' for writing to output pin always use latch (PIC18 family)
SPI_Ethernet_Rst_Direction as sbit at TRISC0_bit
SPI_Ethernet_CS_Direction as sbit at TRISC1_bit
' end ethernet NIC definitions
dim myMacAddr as byte[6] ' my MAC address
myIpAddr as byte[4] ' my IP address
gwIpAddr as byte[4] ' gateway (router) IP address
ipMask as byte[4] ' network mask (for example : 255.255.255.0)
dnsIpAddr as byte[4] ' DNS server IP address
IpAddr as byte[4]
remoteHost1 as byte[4] 'IP serveur
dim etat as integer
txt as string[20]
const SPI_Ethernet_HALFDUPLEX = 0
const SPI_Ethernet_FULLDUPLEX = 1
sub function Spi_Ethernet_UserTCP(dim byref remoteHost as byte[4],
dim remotePort, localPort, reqLength as word, dim byref canClose as byte) as word
if(localPort <> 3040) then ' I listen only to web request on port 3040
result = 0
exit
end if
result =0
remoteHost[0] = 192
remoteHost[1] = 168
remoteHost[2] = 20
remoteHost[3] = 70
remotePort = 3040
localPort = 3040
canClose = 0
result = result + Spi_Ethernet_putString(@txt)
end sub
sub function Spi_Ethernet_UserUDP(dim byref remoteHoste as byte[4],
dim remotePorte, destPorte, reqLength as word) as word
result = 0
end sub
main:
ADCON0 = %0110 ' convertisseur A/D off
PORTB = 0
TRISB = 0xFF ' PORTB en entrée pour les boutons
' set mac address
myMacAddr[0] = 0x00
myMacAddr[1] = 0x14
myMacAddr[2] = 0xA5
myMacAddr[3] = 0x76
myMacAddr[4] = 0x19
myMacAddr[5] = 0x3F
' set IP address
myIpAddr[0] = 192
myIpAddr[1] = 168
myIpAddr[2] = 20
myIpAddr[3] = 60
' set gateway address
gwIpAddr[0] = 192
gwIpAddr[1] = 168
gwIpAddr[2] = 20
gwIpAddr[3] = 6
' set dns address
dnsIpAddr[0] = 192
dnsIpAddr[1] = 168
dnsIpAddr[2] = 20
dnsIpAddr[3] = 1
'set subnet mask
ipMask[0] = 255
ipMask[1] = 255
ipMask[2] = 255
ipMask[3] = 0
'Ip serveur
remoteHost1[0] = 192
remoteHost1[1] = 168
remoteHost1[2] = 20
remoteHost1[3] = 70
SPI1_Init() ' init spi module
SPI_Ethernet_Init(myMacAddr, myIpAddr,SPI_Ethernet_HALFDUPLEX) ' init ethernet module
SPI_Ethernet_setUserHandlers(@SPI_Ethernet_UserTCP, @SPI_Ethernet_UserUDP) ' set user handlers
etat = 0
txt = "run" + chr(13)
' dhcp will not be used here, so use preconfigured addresses
SPI_Ethernet_confNetwork(ipMask, gwIpAddr, dnsIpAddr)
do
Spi_Ethernet_readPacket()
loop until SPI_Ethernet_doPacket() <> 1
while TRUE ' do forever
SPI_Ethernet_doPacket() ' process incoming Ethernet packets
txt = "halt" + chr(13)
Spi_Ethernet_readPacket()
' if PORTB.0=1 then
' txt= "run"+ chr(13)
' SPI_Ethernet_doPacket()
' Spi_Ethernet_readPacket()
' SPI_Ethernet_sendudp(remoteHost1, 3040, 3040, @txt, 20)
' goto fin
' end if
'
' if PORTB.1=1 then
' txt= "halt"+ chr(13)
' SPI_Ethernet_doPacket()
' Spi_Ethernet_readPacket()
' goto fin
' end if
'
' if PORTB.2=1 then
' txt= "gotoTime " + "6000" + chr(13)
' SPI_Ethernet_doPacket()
' Spi_Ethernet_readPacket()
' goto fin
' end if
'
' if PORTB.3=1 then
' txt= "gotoControlCue " + chr(34)+ "F1" + chr(34) + chr(13)
' SPI_Ethernet_doPacket()
' Spi_Ethernet_readPacket()
' goto fin
' end if
'
' if PORTB.4=1 then
' select case etat
' case 0
' txt= "standBy true"+ chr(13)
' etat = 1
' SPI_Ethernet_doPacket()
' Spi_Ethernet_readPacket()
' goto fin
' case 1
' txt= "standBy false"+ chr(13)
' etat = 0
' SPI_Ethernet_doPacket()
' Spi_Ethernet_readPacket()
' goto fin
' end select
' end if
'
'
' fin:
' txt = " "
' delay_us(200)
' SPI_Ethernet_doPacket()
wend
end.
He would have my remote sends messages through the port 3040, but I can not define it uses that port, though I put the remotePort = 3040.
thank you for your help in advance.
bye