LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

device card

Darnell, the documentation clearly states that all commands consist in a 7-bytes packet to be sent to the device. Inside the packet you have up to 4 bytes of data that must match the syntax for each command used: unused bytes must be set to 0.

 

The 'U' command  uses 2 out of those 4 bytes of data, in which DD address and data pattern must be mixed according to the documentation. Resulting '16-bit word' is splitted by your code in outputdata[2] and outputdata[3] bytes of the command string, while the other bytes are filled with the proper content (including the final checksum). After this is done you must send the whole 7-byte packet to the device and wait for the response.

 

If response does not arrive at all then the problem may lie either in com port settings, incorrect cabling or device hardware problems.

Do you happen to have some program from the producer of the device to test it? If you have then you can at least verify that hardware and cabling are OK and come to debug your code.



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 21 of 80
(2,005 Views)

so this is the correct format then, this will make my life such better if this in the correct format.

 

also you said something ABOUT U uses two the bytes. in the in the manual i only see you in one byte.

 

where do you see U in two of the bytes .

 

so is all of this correct according to the manual.

 

                                             16bit word below in []

                                           -----------------------------

 

0000 0000    0101 0101     [ 1110 0001     0000 0001]    0000 0000    0000 0000     0111 0101

 

  [0]              [1]    'U'            [2] MSB =11bits                  [4]   x=0      [5] x=0          [6]     117                 

------------    ------------       -------------------                ------------     ------------     ------------

                                                                   [3] LSB=5bits

                                                                       ---------

 

0 Kudos
Message 22 of 80
(1,997 Views)

'U', which is the command keyword, appears in one byte only.

Data associated with the command use 2 out of 4 byte of the data area.

 

Are you intending to send to the card a different bit pattern with respect to the code I used, right? (0x708 or 1110 0001 000 instead of 0xFA)



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 23 of 80
(1,995 Views)
where is the code that you used?
0 Kudos
Message 24 of 80
(1,995 Views)
here


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 25 of 80
(1,993 Views)

 short int     data=0xFA;            // data=         0000000011111010 (250)

 

 data <<= 5;                         // data=         0001111101000000 (8000)

 msblsb = data | deviceAddress;      // msblsb=       0001111101000001 (8001)
 outputdata[2] = (msblsb>>8) & 0xff; // outputdata[2]=00011111         (31)

 outputdata[3] =  msblsb & 0xff ;    // outputdata[3]=        01000001 (65)

 

 can you explain these two lines as far as what the data| deviceAddress and (msblsb>>8) & 0xff.

 

i want to see if im on the same page.

 msblsb = data | deviceAddress;      // msblsb=       0001111101000001 (8001)
 outputdata[2] = (msblsb>>8) & 0xff; // outputdata[2]=00011111         (31)

 

                                                                          

0 Kudos
Message 26 of 80
(1,991 Views)

darnell wrote:

 can you explain these two lines as far as what the data| deviceAddress and (msblsb>>8) & 0xff.

 

i want to see if im on the same page.

 msblsb = data | deviceAddress;      // msblsb=       0001111101000001 (8001)
 outputdata[2] = (msblsb>>8) & 0xff; // outputdata[2]=00011111         (31)

I don't understand why you need me to comment your code (I copied a section of what you should have written some time ago), anyway...

 

 

 msblsb = data | deviceAddress;      // msblsb=       0001111101000001 (8001)
'data' has been previously shifted to the left by 5 bits: rightmost 5 bits are set to 0 in the shift.

ORing 'data' with 'deviceAddress' sets every bit where either one of the originating bits is 1, as described here. This way we are mixing deviceAddress and data pattern as required by the device (a preliminary is

missing, ensuring that deviceAddressuses only the first 5 bits: this is probably unnecessary, anyway testing that deviceAddress <32 ensures it and can be easily added).

 

  outputdata[2] = (msblsb>>8) & 0xff; // outputdata[2]=00011111         (31)

Here a shift to the right is performed plus an AND: result is extracting the rightmost 8 bits from the word (MSB).

The AND is probably redundant since outputdata is a char (1 byte) and not a short, but just to be sure...

 

 outputdata[3] =  msblsb & 0xff ;    // outputdata[3]=        01000001 (65)

This AND extracts the lower bits from the word, masking the higher ones.

 

 

 

 

Have you tested it with your hardware? Do you have some test program from card producer for you to check hardware and cabling?



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 27 of 80
(1,987 Views)

 

i wont be able to until tomorrow. im just getting it ready. but if this dont work then its just a cable issue or hardware issue.

 

but im going to call the first thing tomorrow to get all this information from the vendor.

 

so again just for clarification to be able to communicate to this device card. 56bits is needed. and a the 16bit word is within the 56bits which element 2 & 3

 

correct?

 

 

 

 

0 Kudos
Message 28 of 80
(1,984 Views)

also is there a similiar project that you know of in CVI labwindows or any project period that is doing something similiar to what im doing.

 

also is your value of your element 6 is 181?

 

0 Kudos
Message 29 of 80
(1,985 Views)

i got a question.

 

i did a byte_sent=ComWrt(1,outputdata,7);

 

when i check the value of byte_sent, it doesnt give me wat im looking for, as far what we are sending in the outputdata. do the value of 

 

the variable byte_sent suppose to be the same as the format we did with your program.

 

or it doesnt matter.

 

because that could be the case . byte_sent give me a whole different number than the format we are sending.

 

 

**************************************

 

#include <ansi_c.h>
#include <visa.h>
#include <userint.h>
#include <rs232.h>
#include <utility.h>
#include <stdio.h>


#define MSCARD_BYTE       0x00
#define NUM_ADDRESS_BITS  0x5
#define    NUM_BYTE_IN_CMD   0x7
#define NUM_BYTE_IN_RESP  0x7

#define TEXT_LENGTH       2000

#define COMPORT           1
#define BAUDRATE          115200
#define DATABITS          8
#define PARITY            0
#define STOPBITS          1
#define INPUTQ            512
#define OUTPUTQ           512
#define STRINGSIZE        7


unsigned char   outputdata[NUM_BYTE_IN_CMD];
unsigned char    inbuff    [NUM_BYTE_IN_RESP];


   int bytes_sent=0;
    int bytes_read=0;
  
char read_data[TEXT_LENGTH];

int main()
{
     
short    int         MSCardAddress=0;
short    int         CommandCode='U';
short    int         deviceAddress=0x1;
short    int         data=0xFA;

    int msblsb=0;
   
    bytes_sent= OpenComConfig(COMPORT,"COM10",BAUDRATE,PARITY,DATABITS,STOPBITS,INPUTQ,OUTPUTQ);

   
    memset( outputdata, 0, NUM_BYTE_IN_CMD);
    memset( inbuff,     0, NUM_BYTE_IN_RESP);   
   
    outputdata[MSCARD_BYTE] = MSCardAddress;
    outputdata[1] = CommandCode; //'U';
   
    // embed controller number and device address into output message

    data <<= NUM_ADDRESS_BITS; // left shift data bits
    msblsb = data | deviceAddress;  // combine data and address bits
    outputdata[2] = (msblsb>>8) & 0xff;  // Set MSB
    outputdata[3] =  msblsb & 0xff;  // Set LSB
//     sprintf(test,"%x",outputdata);
   

    // calc check sum
    outputdata[6] = outputdata[0] + outputdata[1] + outputdata[2] + outputdata[3] +outputdata[4] + outputdata[5];
    outputdata[6] = outputdata[6] & 0xFF;

//    Delay(1);
    byte_sent=ComWrt(1,outputdata,7);
    //Delay(2);


//printf("%x",outputdata);
//GetKey();
    bytes_read=ComRd(COMPORT,outputdata,NUM_BYTE_IN_CMD);
   
//    Delay(1);
}
 

 

 

0 Kudos
Message 30 of 80
(1,971 Views)