Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Sat Nov 18, 2017 6:03 pm

All times are UTC - 7 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Network close
PostPosted: Wed Jul 08, 2009 1:40 pm 
Offline

Joined: Wed Apr 11, 2007 4:47 pm
Posts: 32
in my application, QSI Terminal need to communicate different device. when make a switch I need to close current communication channel. and make a new connection.

when I try to close current connection, I always get Exception " NetOpen: Transmission chennel is in use(#167)"

how I do can avoid this message?

I am using QTERM-G58 wireless connection with Qlarity V2.60


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Wed Jul 08, 2009 1:50 pm 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
Can you please post the code that is causing the exception. It looks like the exception is coming from NetOpen rather than NetClose.

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Thu Jul 09, 2009 8:10 am 
Offline

Joined: Wed Apr 11, 2007 4:47 pm
Posts: 32
here is my code to be excuted when I press a button to close network :


DeckConnected:=0
netclose(G58_ENetsocket)
UnregisterMsgHandler(default, msg_comm_receive, G58_ENetSocket)
UnregisterMsgHandler(default,msg_comm_transmit,G58_ENetSocket)


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Thu Jul 09, 2009 8:19 am 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
The order of the code looks like a problem. I'm pretty sure you would want to unregister the socket before you close it.

DeckConnected:=0
UnregisterMsgHandler(default, msg_comm_receive, G58_ENetSocket)
UnregisterMsgHandler(default,msg_comm_transmit,G58_ENetSocket)
netclose(G58_ENetsocket)

If it's coming from netclose, this code will hide the error.

check error
netclose(G58_ENetsocket)
on error
_clearException()
enderr

I'd also recommend using the EthernetClient and/or EthernetServer objects instead of the API's and message handlers.

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Thu Jul 09, 2009 8:49 am 
Offline

Joined: Wed Apr 11, 2007 4:47 pm
Posts: 32
I have change the order, do unregister first, then close the network connection
like below, the exception still come.

DeckConnected:=0
UnregisterMsgHandler(default, msg_comm_receive, G58_ENetSocket)
UnregisterMsgHandler(default,msg_comm_transmit,G58_ENetSocket)
netclose(G58_ENetsocket)



then I add exception hide code like below it does not work

DeckConnected:=0
UnregisterMsgHandler(default, msg_comm_receive, G58_ENetSocket)
UnregisterMsgHandler(default,msg_comm_transmit,G58_ENetSocket)
check error
netclose(G58_ENetsocket)
on error
_clearException()
enderr


I have change to use EthernetClient to close the net, the code like below it is not work

DeckConnected:=0
UnregisterMsgHandler(default, msg_comm_receive, G58_ENetSocket)
UnregisterMsgHandler(default,msg_comm_transmit,G58_ENetSocket)
check error
Enet_Socket1.closeConnection()
on error
_clearException()
enderr



what else should i do?


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Thu Jul 09, 2009 9:07 am 
Offline

Joined: Wed Apr 11, 2007 4:47 pm
Posts: 32
hi Ron.L

you are right

that Exception is not regarding the netclose() API, I found a netopen() API is hide siting somewhere my application.

my application need g58 to switch communcation to difference device.
now i gues my new netopen()API is be excuted to fast, it should be wait previouse connection be close completed

now my question is how do i know the previouse connection be closed complete?


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Thu Jul 09, 2009 9:15 am 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
I would use the EthernetClient object and its GetConnectionState() function. Here is some example code.

Code:
    if ethernetclient_1.getConnectionState() == ec_notconnected then
        'connection closed
    elseif ethernetclient_1.getConnectionState() == ec_connectionpending then
        'connection is in a pending state, wait for the connection
        'to be established or to time-out & close
    elseif ethernetclient_1.getConnectionState() == ec_connectionmade then
        'connection is established, send/recieve data or close the connection
    endif

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Thu Jul 09, 2009 12:00 pm 
Offline

Joined: Wed Apr 11, 2007 4:47 pm
Posts: 32
hi Ron.l

the return from ethernetclient_1.getConnectionState() always 1 I gues it means ec_connectionpending

I start a 100ms timer, after I issue netClos(), a counter is be add 1 when the timer is time-out
i make a test to see how much time I have to wait befor I make a connection.
the test result shows I have to wait 50 sec.

why close a connection so different


do i have a way to make it fast?


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Thu Jul 09, 2009 12:10 pm 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
With TCP/IP, when you attempt to open a connection to a server that is not responding, there is a series of retries built into the protocol that occur before the connection is closed. TCP/IP has a lot of hand-shaking and retries built into the protocol to attempt to get the data to the device your sending it too even accross un-reliable transfer mediums such as an old telephone line or Wifi.

If you have a setup where it would be extremely unlikely for any packets to be lost (all wired well insulated CAT5 cables for example), you might try sending UDP packets back and forth to verify the existence of a device.

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Thu Jul 09, 2009 12:11 pm 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
Another option may be to use multiple EthernetClientV2 objects. That way if one is pending, you can use another one to attempt to open a connection.

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Fri Jul 10, 2009 5:48 am 
Offline

Joined: Wed Apr 11, 2007 4:47 pm
Posts: 32
Ron L. wrote:
Another option may be to use multiple EthernetClientV2 objects. That way if one is pending, you can use another one to attempt to open a connection.



I am considering use multiple EthernetClientV2 objects. with multiple EthernetClientV2 objects do i still can use Netopen() API, how i can tell Netopen() to use which EthernetClientV2 objects to make a connection.


Top
 Profile  
 
 Post subject: Re: Network close
PostPosted: Fri Jul 10, 2009 7:31 am 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
There is no reason to use the NetOpen API. The EthernetClientV2 has OpenConnection and CloseConnection functions that should be used.

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group