07-06-2012 03:23 PM
I have a RT application that does this:
ResetDAQDevices(); Read Channel Configuration from File(); CreateDAQmxTasks(); OpenFileForWritingData(); While(!shutting down) { msg = BuildDataMsg; WriteDataToFile(msg); ProcessSystemEvents(); if (TCPConnected) //This is a threaded TCP Server ServerTCPWrite(msg); SleepUS(1000000); }
I can write data to file, and I can send data via TCP, but I cannot do both within the same execution. When I try, I get an error on fputs(msg, DataFile); that says "Argument Must be an Open Stream"
I realize I should probably be using thread safe data as both the file output and tcp output are writing the same message, but why do I get an error that my file is not open whenever I try to do both at the same time? How is the file closing?
Thanks.
07-06-2012 04:24 PM
I should also mention that my message is in character string format and that I am writing characters to TCP and to file. I tried implementing the RT thread safe queue data writing example, but it is written for "wb" and one value of type double. Is it possible to have thread safe data for a character array?
07-09-2012 03:44 PM
Hello,
It is hard to tell given your high level code what could be happening. It doesn't make sense that the file would be randomly closing or timing out. Is there a possibility you can post your code here?
One issue could be the way that you are trying to access the message that you are trying to write twice in two different threads. Are you using a pointer to the message or making a temporary copy?
Also how are you managing the handle to the file? It could be that the reference is not being dealt with properly.
Which example were you referring to?
There shouldn't be any limitation to data types for thread safe queues. Take a look at the thread safe queue section in this article.
07-09-2012 03:49 PM
I'd prefer to send the code to you rather than post it here.
I am not trying to write to the message (msg) in different threads, but the TCP thread certainly could access msg while it is being written to or while the fputs is accessing it. I am using a pointer to the message. The example is FileIORT. I'll look into the thread safe queue via the link you sent.
07-10-2012 04:55 PM
Let me just clarify what you are trying to do. You want to upload a dll to a RT target which will capture data from a device and simultaneously write the captured data to a file as well as transmit it over TCP?
Have you successfully been able to modify the example you mentioned to write characters to and from a file? The CmtWriteTSQData function takes a buffer which is a pointer to an array of items to write. Then you can probably try combining the NetworkVariableRT example with that one. NetworkVariables are simpler to use then TCP communication for sharing data.