LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

device card

question1. do you understand this portion of what im doing?

question2.  if so, i was trying to get your interpretation of how you execute this.

question3. also do you have a project that ithat is similiar to this , i wanted to see if you can post it.

question4. what advice would you give me to execute this.

 

elements of array        my interpretation of each array           define what each array element need to have in it

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

 

outputdata[0];           Master Card Address                           0->00000000

outputdata[1];           Update 'U'                                         85->01010101

outputdata[2];           MSB 11-bits                                       31->00011111

outputdata[3];           LSB   5 bits=1                                      1-> 00000001

outputdata[4];           x                                                       x->  00000000

outputdata[5];           x                                                       x->  00000000

outputdata[6];           SUM                                                101->01100101

 

this is base off this format.   I was wondering if someone can give mesome assistance of doing this. I think im doing it right but im going to try again.

 

·         Format:                 [Card Address] [U] [MSB] [LSB] [x] [x] [Sum of previous Bytes]

·         Response:             [Card Address] [x] [Sum of Command Bytes] [Bus Errors] [x] [x] [x]

0 Kudos
Message 11 of 80
(2,114 Views)

Ok, so let's assume com port settings are correct. Don't forget to test  return value from ComWrt, though.

 

Yes, I suppose I understand what you are doing, and I think there is a misinterpretation in your code. If you want to pass 1 in the first 5 bits (address) and 31 in the next 11 (data pattern), your word should look this way:

 

0000 0011 1110 0001 = 993

---- ---- ---

   31        - ----

                5

 

Splitting the resulting word it in two bytes will give those values: 3 (MSB) and 225 (LSB). This is what the code you posted earlier does: creating the data pattern, shifting it 5 bits to the right and adding the address:

 

   data <<= IVIACTIVETARGET_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

 

I suppose the best advice I can give you is to follow that code, changing values in accordance to your actual environment and needs and testing it with your device.



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 12 of 80
(2,105 Views)

Ok, so let's assume com port settings are correct. Don't forget to test  return value from ComWrt, though.

 

Yes, I suppose I understand what you are doing, and I think there is a misinterpretation in your code. If you want to pass 1 in the first 5 bits (address) and 31 in the next 11 (data pattern), your word should look this way:

 

0000 0011 1110 0001 = 993

---- ---- ---

   31        - ----

                5

 

Splitting the resulting word it in two bytes will give those values: 3 (MSB) and 225 (LSB). This is what the code you posted earlier does: creating the data pattern, shifting it 5 bits to the right and adding the address:

 

   data <<= IVIACTIVETARGET_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

 

 

I suppose the best advice I can give you is to follow that code, changing values in accordance to your actual environment and needs and testing it with your device.


 so basically you are saying do the opposite. shift the data bits right instead of left.

 

ok let try to interpret what you said.

 

unsigned short int DATA1=0x3;

unsigned short int DATA2=0xE1;

DATA1>>=5;

msblsb = DATA1|DATA2;

outputdata[2]=(msblsb<<8)&0xff;

outputdata[3]=msblsb &0xff;

 

are you saying do something like this.

 

how are you talking about doing it?

0 Kudos
Message 13 of 80
(2,100 Views)

I suppose the best advice I can give you is to follow that code, changing values in accordance to your actual environment and needs and testing it with your device.


 so basically you are saying do the opposite. shift the data bits right instead of left.

 

ok let try to interpret what you said.

 

unsigned short int DATA1=0x3;

unsigned short int DATA2=0xE1;

DATA1>>=5;

msblsb = DATA1|DATA2;

outputdata[2]=(msblsb<<8)&0xff;

outputdata[3]=msblsb &0xff;

 

are you saying do something like this.

 

how are you talking about doing it?

0 Kudos
Message 14 of 80
(2,099 Views)

darnell wrote:


 so basically you are saying do the opposite. shift the data bits right instead of left.

 


Darnell, are you kidding? I never said that!

 

Let's start from the beginning. Your original code was:

 

short int DATA1=1,DATA2=2,DATA_RESULT=0;
short int ADDRESS=31;
char Ch[7]={0};

Ch[0] = 0;
Ch[1] = 'U';

 

DATA_RESULT= (DATA1* 32 + DATA2) * 32 +ADDRESS; 
Ch[2] = (DATA_RESULT>>8) & 0xff;
Ch[3] = DATA_RESULT & 0xff;
Ch[4] = 0;
Ch[5] = 0;
Ch[6] = Ch[0] + Ch[1] + Ch[2] + Ch[3] +Ch[4] + Ch[5];
Ch[6] = Ch[6] & 0xFF;

 

So it seems your card has address 31 and you are doing the bit shifting (to the left) by the second multiplication by 32. Resulting data pattern for the attached device should be 34 (or 0x22 or binary 10 0010).

 

 

 

After it you posted a different, more sophisticated code:

 

#define MSCARD_BYTE 0
#define NUM_ADDRESS_BITS 5
#define    NUM_BYTE_IN_CMD 7
#define NUM_BYTE_IN_RESP 7

ViByte      outputdata[NUM_BYTE_IN_CMD];
ViByte        inbuff    [NUM_BYTE_IN_RESP];

int main()
{
    int         MSCardAddress=0;
    int         CommandCode='U';
    int         deviceAddress=0x2;
    int         data=0x4a;
    int         msblsb;
    
    outputdata[MSCARD_BYTE] = MSCardAddress;      // 0
    outputdata[1] = CommandCode;       // 'U';
   
    // embed controller number and device address into output message
    data <<= IVIACTIVETARGET_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
    // calc check sum
    outputdata[6] = outputdata[0] + outputdata[1] + outputdata[2] + outputdata[3] +outputdata[4] + outputdata[5];
    outputdata[6] = outputdata[6] & 0xFF;

 

This code (which by the way you didn't answered me where it comes) uses a different address (2) and a different data pattern (0x4a or binary 1001010).

 

 

 

What I intended to say was that in my opinion you should use the second code you posted, adapting it to your actual card address, device address and desired data pattern.



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 15 of 80
(2,095 Views)

okay the more complex code was my code i started off with first, i just didnt post it  first.

 

now. I was trying something out at first. but the complex code is what we going to keep,its  sophisticated

 

its basically the same thing i just define variables at the top. the only difference is that im throwing different hex values in. to 

 

try to get what i want in each element.the address suppose to be 1, what happen was why that particular is 2. is because we have two switch cards

 

the first card has address of 1, and the second card has and address of two. so thats why i change the address to experiment.

 

 

ok im making progress now.so what i have now is this last update.

 

 

 

 

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

 

short    int         MSCardAddress=0;
short    int         CommandCode='U';
short    int         deviceAddress=0x1;
short    int         data=0xFA;

    int msblsb;
   
    bytes_sent= OpenComConfig(1,"COM10",baudrate,parity,databits,stopbits,512,512);

   
    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 

 

i dont know if this going to work but im trying something. im trying to get 1in outputdata[3] and then i have accomplish what i wanted to do.

 

i did get 31 in  outputdata[2] ;

 

i want know if this is  going to work until tuesday.

 

so i need to do something outputdata[3].

 

do you think im on the right track.

 

can you some advice or assist me what i need to shift &.

0 Kudos
Message 16 of 80
(2,094 Views)

excuse my french lololololol, i was sleepy last nite, typing incorrect grammer lololololol.

 

ok im a lil confused now the way im doing it its not coming up right.

 

but i think i need head this path. I thought the way i was doing it was going to past the 

 

1 into the first bits. but obvisiouly not.

 

 

this is the correct way im thinking. because it passes 1 in the first five bits and then its also a 16bit word.

 

 

0000 0011 1110 0001 = 993

---- ---- ---

   31        - ----

 

 

so can you explain how can i get this binary number to be this result of 993

 

because thats what im thinking i got to  pass in the ComWrt(1,outputdata,7);

 

 

 

 

 

 

0 Kudos
Message 17 of 80
(2,082 Views)
are you there roberto, response to my last message
0 Kudos
Message 18 of 80
(2,076 Views)

As far as I can see your code looks correct to me:

 

 

 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)

 

 

It fills outputdata fields with the expected values so that you should be able to send them to your device and have it recognize the message.



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 19 of 80
(2,068 Views)

then i think its an hardware issue than. this happen the last time where my part was correct, and then im killing myself doing the samething over and over.

 

but i got a question

 

if we are sending a 16bit word y are we sending 7 bytes out.

 

because when write to the instrument ComWrt (1,outputdata,7);

 

its sending out all the elements. so whats the purpose of saying send a 16bit word. when are really writing 56bits out to the device.

 

im trying to understand that. this its new to me. normally when im talking to a device im ise to sending string commands. 

 

so basically the 16bit word is formatted in the 7 bytes

 

                                            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

                                                                       ---------

 

 

so you say this is correct when i send to the ComWrt(1,outputdata,7)

 

0 Kudos
Message 20 of 80
(2,064 Views)