khuenguyen Posted November 22, 2010 Share Posted November 22, 2010 I have a hardware, it has an IP address, DAQFactory has an different IP. I want DAQFactory acts as a Server, hardware acts as a client. Client will actively make a connection to the server. Can I do it? thanks in advance. Link to comment Share on other sites More sharing options...
AzeoTech Posted November 22, 2010 Share Posted November 22, 2010 Yes, but it can only handle one connection on each IP port, so isn't appropriate if you need multiple devices to connect to DAQFactory. It is also a little harder to write protocols for servers because of its async nature. You create a server the same way you create a client: go to Quick - Device configuration, select New Serial /Ethernet, then instead of clicking New Ethernet Client, click New Ethernet Server. Link to comment Share on other sites More sharing options...
khuenguyen Posted November 22, 2010 Author Share Posted November 22, 2010 after I get a connection, I'll get the client ip address, the DAQ will then actively re-create a new connection and release the old connection to continue listening. Can I do this? Link to comment Share on other sites More sharing options...
AzeoTech Posted November 22, 2010 Share Posted November 22, 2010 Probably, as long as two devices don't try this procedure at the same time. A better pattern, however, is to use UDP discovery. This is where the system goes out and sends a UDP ping to all visible devices, and those that are listening respond with their IP address. I would use this method instead, writing the UDP discovery part in normal C or C++ as a DLL, then call it using extern(). Link to comment Share on other sites More sharing options...
khuenguyen Posted November 22, 2010 Author Share Posted November 22, 2010 as you said, I can create one library (.dll with some functions) in C/C++ and DAQFactory can use this functions as functions provided DAQFactory? Link to comment Share on other sites More sharing options...
AzeoTech Posted November 22, 2010 Share Posted November 22, 2010 Yes Link to comment Share on other sites More sharing options...
khuenguyen Posted November 22, 2010 Author Share Posted November 22, 2010 great, thanks you very much. Link to comment Share on other sites More sharing options...
khuenguyen Posted November 23, 2010 Author Share Posted November 23, 2010 I have a dll file. In this file, I have some class (C++), can I use them in DAQFactory? Link to comment Share on other sites More sharing options...
AzeoTech Posted November 23, 2010 Share Posted November 23, 2010 Classes? No. DAQFactory only supports accessing C style functions in a DLL. You'd have to wrap your classes in a way that exposes them with functions. This is usually done using handles. Link to comment Share on other sites More sharing options...
khuenguyen Posted December 3, 2010 Author Share Posted December 3, 2010 Hi admin, How to get IP address of client from a connection? thanks in advance. Link to comment Share on other sites More sharing options...
AzeoTech Posted December 3, 2010 Share Posted December 3, 2010 If you control the client code, I'd just add a query to whatever protocol you are implementing. If not, and you are creating your server in C code, there is a function for retrieving the IP of the attached client on a socket. I don't know what it is off hand and C code like this is a little outside the realm of this forum. Link to comment Share on other sites More sharing options...
khuenguyen Posted December 8, 2010 Author Share Posted December 8, 2010 I created a dll file, which has a function called AcceptConnection. The nature of this function is to perform the function accept() of C/C++. In DAQ workspace, I created a sequence (with name: DAQServer) to use the functions in this dll file. When sequence execute AcceptConnection function, DAQ is hangs, does not work. I use TaskManager and see that, DAQ only use 1%CPU and little RAM. If I use a client to connect to DAQ, it still success. I can send/receive data. I still try function StartThread to run sequence (DAQServer) in other thread but DAQ still does not work normal. Link to comment Share on other sites More sharing options...
AzeoTech Posted December 8, 2010 Share Posted December 8, 2010 I'm sorry, but I'd need a lot more detail, or your .ctl document. Link to comment Share on other sites More sharing options...
khuenguyen Posted December 9, 2010 Author Share Posted December 9, 2010 I create a sequence with name DAQServer as below: function DAQServer(global port) extern("DAQServer.dll","short InitServer(short)","InitDAQServer","stdcall") extern("DAQServer.dll","short AcceptConnection(short)","DAQAcceptConnect","stdcall") global retSock global retAccept retSock = InitDAQServer(port) if (retSock == -1) system.messagebox("cannot init socket") else while (1) retAccept = DAQAcceptConnect(retSock) endwhile endif continue, I create a sequence with name "main" as below: private string strStatus global port = 6000 StartThread("DAQServer(port)","MyServer",1) while (1) strStatus = GetThreadStatus("MyServer") ? strStatus delay(10) endwhile In function AcceptConnection (in file dll), I accept new incoming connection and write IP address to text file. With all clients connect to DAQ, I always receive IP in text file. DAQ only use 1%CPU but DAQ's status is "not responding" and I cann't do anything on DAQ, I still don't see value of "strStatus" in "Command/Alert window". But, the clients still connect to DAQ and send/receive data. Link to comment Share on other sites More sharing options...
AzeoTech Posted December 9, 2010 Share Posted December 9, 2010 CPU usage isn't the best indication of hanging. You have infinite loops in both your sequences with no delays built in. If Main is run in the main DAQFactory thread (by doing Main() from a button for example, or the command/alert window), it will cause DAQFactory to appear hung because the UI never gets the CPU back. Its stuck in your second loop. So: 1) start Main on its own thread by starting the sequence instead of calling it 2) add at least a minimal delay in every loop: delay(0.05) for example Link to comment Share on other sites More sharing options...
khuenguyen Posted December 10, 2010 Author Share Posted December 10, 2010 accept() is function block. Program will block until new incoming connection. So, the loop "while (1)" isn't run continuous. If I run sequence in debug mode, DAQ status is "not responding" when run command "DAQAcceptConnection" but it will normal when have new incoming connection. I try with delay() command but it still doesn't work normal. Link to comment Share on other sites More sharing options...
AzeoTech Posted December 10, 2010 Share Posted December 10, 2010 DAQFactory stalls when you call DAQAcceptConnection? Then you have an issue with your DLL code. DAQFactory can't really protect itself much against problems in DLL's loaded with extern. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.