LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Why the GetInQLen(Get the COM PORT Input buffer length) function does not work with Windows NT and Windows2000

Hi,
I'm trying to get the number of bytes received by the RS232 COM Port using the GetInQLen function provided by the NI RS232 library, well, this function work correctly with W95/98/ME but it does not work at all with Windows NT or Windows2000, Why???????
Thanks a lot
0 Kudos
Message 1 of 6
(4,139 Views)
I have worked a lot with serial communication but I never found such a problem in NT or 2K. In my opinion your problem have another explanation than the operating system.

Maybe you can post an abstract from your code to detail the use of the serial port, in order for us to help you more precisely.

Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 6
(4,139 Views)
Thnaks a lot Roberto, well here is the code in use and is working perfectly on Win98/95/Me but never with NT or W2000:

In the main program :
The code open and config. Serial port Com1
ret = OpenComConfig (ComPort, "", baudrate, 0, 8, 1, 65535, 65535);
then declares a Time_Task function for Idle event, something like an infinite loop when no action is taken by the CVI enters in this function:

ret=InstallMainCallback (Time_Task, 0, 1);
ret = SetIdleEventRate (80);

In the Time_Task function:
InQueue=GetInQLen (com_port);
if(InQueue)SerialControl(com_port);
Whenever the Com buffer has at least 1 byte the SerialControl is called and I can process the incomming serial data.

In the SerialControl function:
ret=read_serial_buffer(serial_b
uff_in,comPort);

In the read_serial_buffer function:
InQueue=GetInQLen (com_port);
ComRd (comPort,serial_buff_in , InQueue);
In that way I know already how many bytes in the InQueue and the serial_buffer_in is filled by all the received bytes...
That all, This code is working perfectly on W98/95/ME but with NT or 2000 it won't to work.
Thanks in advance for your help..
0 Kudos
Message 3 of 6
(4,139 Views)
I don't know if this will help, but I have had a similar OS related problem with NT. In my case, the function GetOutQLen failed operation in NT (sp 6). Through experimentation, I found that through multiple calls to the GetOutQLen function, the OS seemed to "wake up" (after a couple thousand loop iterations) and send the command correctly. In Windows 98, however, the function proceeded without error on the first call. You could try the following code

i=0;
dTime = Timer ();
while (i<=0) {
i = GetInQLen (1);
dTotal = Timer ();
if ((dTotal - dTime) > dOSTimeout) {//OS error
//OS took too long, exit with an error
}
}

It basically keeps sending the function until it finds data on the input queue. Then, you can continue processin
g your command. Hope this helps, good luck.
0 Kudos
Message 4 of 6
(4,139 Views)
Well, my programs really work with direct polling (send a command, wait and look if an answer is received), and there is no such frequent call of GetInQLen: this can explain why I never caught this type of error.

In your case, I personally will try installing a com callback to process the dialogue through the serial port, something like
InstallComCallback (1, LWRS_RXCHAR, 0, 0, comCallback, 0);
The comCallback can substitute your Time_task() function, except that is called only when the specified event is triggered (this reduces the system activity also). In the comCallback you can manage your communication integrating what is actually in your SerialControl() function or simply calling it.

Please read the note in the functio
n help: depending on your application, you will need to use LWRS_RECEIVE for the Event Mask and 1 for the Notify Count parameters.

Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 6
(4,139 Views)
Hi, The code of bthorp for sorry does not work, I did the same by inserting a little delay befor calling the
GetInQLen function, very starnge!!
Roberto, using the direct polling the GetInQLen works correctly but I need to make it work in background wothout waiting, cause I don't know when and how many bytes the Serial Device will send to the CVI.
using the InstallComCallback, it does not work also:
ret = InstallComCallback (ComPort, 0x8002, 2,'}', Serial_input1, 0);

in that way it should call the Serial_input1 whenever one of the Masks is true, bytecount=2 and End of string byte ='}'.
From my serial device on the powerOn it sends the string:"{*}" so the InstallComCallBack should work, in fact with W98/Me it works magnifically
but with NT or 2000 not at all, very very strange this fact.........
Thanks for the help.
Bye
0 Kudos
Message 6 of 6
(4,139 Views)