LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

device card

i have a document you guys i want to know if im formatting the 16bit word correctly.

 

im going to send the document and my code.

 

 

 

Download All
0 Kudos
Message 1 of 80
(5,068 Views)

I just took a fast look at your files and have some hints for you to consider:

 

  1. I don't understand why you are opening the port for a 7-bit communication: the documentation clearly states that all messages are 7-byte strings, but I saw nothing but a generic "standard RS232 interface", so I would switch to 8-bit communication and see what's happening
  2. As far as I can see, you are correctly preparing your "U" message in 'ch' variable (supposing your actual card has address 0) but you are sending 'TEMP' variable to the device, maybe in an attempt to send only the content of the message; your device is not likely to answer such a message: try sending it 'ch'
  3. You could avoid some uncertainty in how (and when!) Windows sends messages over the serial port by passing -1 as the output buffer lenght in OpenComConfig: this usually gives you a more predictable system performance
  4. Last but not least: when attaching a project to the forum, you should include only relevant files: 'cvibuild' directory and *_cdb.* files are not needed and consume forum space unnecessary (5 kB of effective code are hidden into 270 kB of unnecessary files)


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 2 of 80
(5,058 Views)

hi roberto ok i started my code over i just replace the outdata with Ch.

 

is this how im suppose to do it. i second guess myself when i cant get something to work.

 

, you mention the 7 byte strings

 

 

can you give me an example where im missing that in my code.

 

0 Kudos
Message 3 of 80
(5,056 Views)

//i forgot to post the cost in the last maessage.

//also you mention something about the bit communication.  where would i change or input the 7 bytes of strings and 8 bit communication

//just trying to be clear that im doing it right

 

 

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

/*#define SWITCH1                  0
#define SWITCH2                  1
#define SWITCH3                  2
#define SWITCH4                  3
#define SWITCH5                  4      */

#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;
   
    OpenComConfig(1,"COM1",115200,0,7,1,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 <<= 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;

//    Delay(1);
    ComWrt(1,outputdata,7);
   
    Delay(1);
}


0 Kudos
Message 4 of 80
(5,056 Views)

so from reading the manual did i set everything correctly.

 

also i notice in the code i just posted

 

when i step through on the outpudata i got a buff err number 0x004091FC""

 

so do you think that is the reason.

 

ComWrt(1,outputdata,7); 

0 Kudos
Message 5 of 80
(5,051 Views)

Hi Darnell, the code you posted last is significantly different from the one on the original post and is using VISA which you were not using originally: did you copied it from some documentation that you didn't posted before?

 

What I was referring to was to open the com port in a different way: OpenComConfig(1,"COM1",115200,0,8,1,512,512); but if this code comes from an official example seems we have to assume it is correct...

 

So we are coming to a very basic question: are you observing some problem in this code? Which one? Did you receive any error from ComWrt? Trap the return code from the function and check its value after the call.

Second, what do you mean by when i step through on the outpudata i got a buff err number 0x004091FC""? Since the first character of the buffer is a nul character (0) you won't see anything unless you expand the buffer and look at individual bytes (or select Options >> Display entire buffer in the string display while in debug mode.

 

Last hint: the code shown has card and device addresses hardcoded in the source: do they match you actual device configuration? You may be trying to speak to a non-existing device in your system!!



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 6 of 80
(5,038 Views)

cool i got the same buff error 0x004091FC"" so i was just making sure i was doing right. now the next thing is i think im not sending the right 16bit word or something. because i scope it out to see if i was actully sending data out , i was but i dont think it was the right 16bit word. so i going to assume that its my mistake in the code.

so im going to try everything carefully.  Also is the buff error a good thing or its not?

 

 

im going to post everything in the manual so you can see the protocol. i posted the key points out of the manual to set up the execution. so you can view. so of the stuff in the manual you dont need to do.

 

what i get from this manual is that im doing a seven bytes meaning  char outputdata[7];

 

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                                                  31->00011111

outputdata[3];           LSB                                                    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 7 of 80
(5,027 Views)

DD Address

 

Switch 1 (SW1) on DD cards set the address for a specific card (see PCB Layout):

 

Valid addresses are 1-30.

 

Switch toggled to 'on' (rocker down) sets that bit (1-5).

 

Up to 30 DD cards may be attached to any particular M/S.  Each DD must have an address from 1 to 30.  Addresses 0, 31, 32 are not defined and should not be used. An Address of 0 is reserved to indicate an End of File (EOF) condition for the SRAM profile.  Multiple DD cards may have duplicate addresses so that both cards respond with the same data

 

·         Update DD (U)

·         Sets a specific DD card to a static data pattern.  The data consists of a 16-bit word with the least significant 5 bits being the DD address and the most significant 11 bits being the data pattern. 

·         Use this command to set/reset a specific DD card.

·         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 8 of 80
(5,027 Views)

Darnell, you are a master in not answering any question; you always run forward, instead, without clarifying anything of previous items! Smiley Mad I'm not understanding anything of your situation!

I will ask you some questions: please answer each of them in a clear and exhaustive manner, otherwise I won't be able to help you any more.

 

Q1. You opened the serial port this way: OpenComConfig(1,"COM1",115200,0,7,1,512,512);
With these parameters a serial communication is opened with no parity, 7 data bits and 1 stop bit. This is quite an uncommon communications protocol, almost all devices I have interfaced used 8 data bits and I saw no notice in this respect in the documentation you posted. So my question is: did you take these parameters from some other documentation for your device or from some example program shipped by the producer? Or have you set them by yourself based on some reasoning? And which one?

 

Q2. Does ComWrt return any error when executed? Please test it and report us its return value.

 

Q3. What do you mean by buff err number 0x004091FC"" ? I supposed you have taken this value in the Variables window while breaking program execution, and the double quotation marks made me think you were looking at a char[] (string) variable (supposedly 'outputdata'): if this is the case, the number you are seeing is the memory address of the string and it is not an error code at all. Additionally, as I explained before, you see nothing inside the quotation marks since the first character of the string is 0 (which corresponds to your card address), which is the string terminator in C. Again, if this is the case, you can see the content of the char array by expanding it and examining individual array elements.

 



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 9 of 80
(5,015 Views)

okay im going to do it this way.

 

basically all of the requirements have came from a document.

 

the device card that i have is ten years old. so i agree with you to.

 

but i have tried four different ways before you even ask your question, which are

 

OpenComConfig(1,"COM1",115200,0,7,1,512,512);

OpenComConfig(1,"COM1",115200,0,8,1,512,512);

OpenComConfig(1,"COM1",9600,0,7,1,512,512);

OpenComConfig(1,"COM1",9600,0,8,1,512,512);

 

also keep in mind that the instruments that i have been programming for the last couple of months are device cards

that i have been program 10 to 15 years ago. So im completely with you when you say that the settings are uncommon.

that was the first thing i said my self.

 

 

question 2. i didnt test for error handling yet. but as far as opening the the port . I did not get no errors.

                  

question 3. i just wanted to make sure that i was correct when i kept seeing the buff error. sometimes

                  i when i can get something to work and have done all that i can do , i attend to start asking

                 questions I know just to make sure that im on the right page. which i need to stop doing.

                  before i post anything in the forum .trust and believe I have tried everything there is. so then 

                  i ask question not for people to my work, because i have already done the work. Im a person

                 that i would like to see different ways of doing things. because maybe doing something wrong.

 

 

                  

 

0 Kudos
Message 10 of 80
(5,011 Views)