03-15-2007 02:08 PM
@jeffh12345 wrote:If you are using viReadAsync, you will need to handle the VI_EVENT_IO_COMPLETION event, and ensure that you check the status with viGetAttribute on VI_ATTR_STATUS.Done, but was not checking this: This status is updated when the handler completes and closes the event, correct?
03-15-2007 02:18 PM
Something to add for clarification:
The messages i get are async: they can happen at any time, any number of them from the network
I need to capture and process the messages: some belong to me, some don't
I have no idea what is waiting for me in the buffer, how many, what size
All I know is that a fragment can be 8-64 bytes long: multiple fragments can happen right after each other, or spaced over several seconds
I have a limited time to reply to some messages before they get resent
using USB like a serial port is a good description of what I am doing
Hope this helps:
Jeff
03-15-2007 02:35 PM
03-20-2007 07:49 AM
BULK IN does not seem to queue properly.
There must be an extremely small queue, as I still drop data, unless I grab
256 bytes at a time, even though my packet size is 64.
There may be a bug there.
I tried to impliment the following:
For each packet received:
Read 1 byte for beginning of packet byte
Read 7 bytes more for header
Read x bytes for rest of packet based upon size of packet inside header
Where x would be between 0 and 56 bytes
Very unstable, I was loosing packets, only got pieces
This works great using RS232
How big is the queue?
Any way to see how many bytes are there, like the RS232 port?
Thanks,
Jeff
03-26-2007 01:15 PM
09-08-2008 06:42 AM
hi,
i am vinoth. I have written the code for USB communication. I have used a cypress IC, whose part no is cy7c68013 (56-pin), which is an high speed USB controller. I have attached the coding which I have written in CVI.
#include <utility.h> #include <formatio.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> #include "visa.h" static ViSession defaultRM; static ViSession instr; static ViStatus status; static ViUInt32 retCount; static ViUInt32 writeCount; static unsigned char buffer[100]; static ViBuf stringinput[5]; char test[9000]; static unsigned char test_gdd[20]; static unsigned char test_gdd_out[20]; char test2[64]; char temp[50]; static unsigned char test1[2]; static ViPUInt16 retur; static ViPUInt16 readcount; int fp,fp1, fp2; int i; char testint1[1024], testint2[1024], testint3[1024], testint4[1024], testint5[1024], testint6[1024], testint7[1024], testint8[1024]; char testintout1[1024]; static ViPUInt16 readcount1; static ViPUInt16 readcountbuf1; char bulkloopbuffer[8200]; char bulkloopbuf1[1024], bulkloopbuf2[1024], bulkloopbuf3[1024], bulkloopbuf4[1024], bulkloopbuf5[1024], bulkloopbuf6[1024], bulkloopbuf7[1024], bulkloopbuf8[1024]; int main(void) { status=viOpenDefaultRM (&defaultRM); if (status < VI_SUCCESS) { printf("Could not open a session to the VISA Resource Manager!\n"); exit (EXIT_FAILURE); } status = viOpen (defaultRM,"cypress_EZusb", VI_LOAD_CONFIG, VI_NULL, &instr); if (status < VI_SUCCESS) { printf ("Cannot open a session to the device.\n"); goto Close; } status = viSetAttribute (instr, VI_ATTR_TMO_VALUE, 5000); status = viUsbControlIn (instr, 128, 06, 256, 0, 18, test_gdd, retur); // for Get Descriptor-Device Delay (0.001); // delay for 1ms test1[0] = 1; // for reset condition status = viUsbControlOut (instr, 64, 160, 58880, 0, 1, test1); // reset condition out printf("\nStatus_reset_1 = %d",status); Delay (.001); // delay for 1ms fp2 = OpenFile ("c:\\cypress\\USB\\Examples\\FX2LP\\Bulkloop\\bulkloop.hex", VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII); ReadFile (fp2, bulkloopbuffer, 7200); // to be read only 7KB(in hex, 7168) of data CloseFile (fp2); //------------------ downloading bulkloop.hex for renumeration --------------------------------------------- for (i = 0; i <= 1023; i++) { bulkloopbuf1[i] = bulkloopbuffer[i]; } status = viUsbControlOut (instr, 64, 160, 0, 0, 1024, bulkloopbuf1); // 1st 1024 bits download Delay (.001); // delay for 1ms status = viUsbControlIn (instr, 192, 160, 0, 0, 1024, bulkloopbuf1, readcountbuf1); // 1st 1024 bits upload for (i = 0; i <= 1023; i++) { bulkloopbuf2[i] = bulkloopbuffer[i + 1024]; } status = viUsbControlOut (instr, 64, 160, 1024, 0, 1024, bulkloopbuf2); for (i = 0; i <= 1023; i++) { bulkloopbuf3[i] = bulkloopbuffer[i + 2048]; } status = viUsbControlOut (instr, 64, 160, 2048, 0, 1024, bulkloopbuf3); for (i = 0; i <= 1023; i++) { bulkloopbuf4[i] = bulkloopbuffer[i + 3072]; } status = viUsbControlOut (instr, 64, 160, 3072, 0, 1024, bulkloopbuf4); for (i = 0; i <= 1023; i++) { bulkloopbuf5[i] = bulkloopbuffer[i + 4096]; } status = viUsbControlOut (instr, 64, 160, 4096, 0, 1024, bulkloopbuf5); for (i = 0; i <= 1023; i++) { bulkloopbuf6[i] = bulkloopbuffer[i + 5120]; } status = viUsbControlOut (instr, 64, 160, 5120, 0, 1024, bulkloopbuf6); for (i = 0; i <= 1023; i++) { bulkloopbuf7[i] = bulkloopbuffer[i + 6144]; } status = viUsbControlOut (instr, 64, 160, 6144, 0, 1024, bulkloopbuf7); //----------------------- end of downloading bulkloop.bex ------------------------------------------------ test1[0] = 0; // for reset condition status = viUsbControlOut (instr, 64, 160, 58880, 0, 1, test1); // reset condition out //--------------------------------------------------------------------------------------------------------- Delay (0.001); // delay for 1ms //--------------------------------------------------------------------------------------------------------- test1[0] = 1; // for reset condition status = viUsbControlOut (instr, 64, 160, 58880, 0, 1, test1); // reset condition out //--------------------------------------------------------------------------------------------------------- Delay (.001); // delay for 1ms //--------------------------------------------------------------------------------------------------------- for (i = 0; i <= 4; i++) { stringinput[i] = "a"; } status = viWrite (instr, (ViBuf)stringinput, 1, &writeCount); if (status < VI_SUCCESS) { printf("Error writing to the device\n"); goto Close; } Delay(0.001); // delay for 1ms test1[0] = 0; status = viUsbControlOut (instr, 64, 160, 58880, 0, 1, test1); printf("\nStatus_reset_0 = %d",status); Close: printf("\nClosing Sessions\nHit enter to continue."); fflush(stdin); getchar(); status = viClose(instr); status = viClose(defaultRM); return 0; }
It shows an error as follows:
NON-FATAL RUN-TIME ERROR: "test_case.c", line 217, col 14, thread id 0x00000408: Function viWrite: (return value == -1073807302 [0xbfff003a]). Unable to start operation because setup is invalid (due to attributes being set to an inconsistent state).
Will you please explain the error what is saying. Please send the necessary information regarding this code. I am waiting for your reply soon.