LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Control ER-16 in Labwindows/cvi

Actually, I am having problems with the input string, I cant make one string from individual bytes.

Mehar
0 Kudos
Message 11 of 23
(1,908 Views)
What do you mean with this? Have you setup ComRd to read 16 bytes?

char buf[20];

ComRd (1, buf, 16);

With this directive you should obtain the whole string.

Unfortunately I cannot continue helping you now: it's minight here and I'm going to sleep. But if you post here some lines of your code tomorrow I can take a look and help you debugging a little.

Bye.
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 12 of 23
(1,904 Views)
I am attaching an example labview code for the utility I had planned. I was planning to use Labview but had to use Labwindows instead due to some unavoidable reasons. This consists of the subvi's initial talk which is the atest equipment and the other checksum (got as an example and then made tweaks to it) which takes care of the 15th byte in the 16 bytes needed for communication from the unit.

I need to do that in cvi now. I need to convert the decimal numbers into hex numbers, then change them into a string, or can I just write it to be integer itself ? What I dont know is would the equipment give back a string or an integer. then I need to convert that to the number. Can i use scanf for that.

With Regards
Mehar
0 Kudos
Message 13 of 23
(1,902 Views)
Ok, I have looked at your code and can precise a little the preceding pseudo-code. Look at this new version:

int i, array[20];
unsigned char buf[20];

//----------------------------------------
// Configure the port for communication
//----------------------------------------
OpenComConfig
SetComTime

//----------------------------------------
// Establish communication
//----------------------------------------
ComWrt ("ATEST EQUIPMENT\r")
ComRd (buf) // "Buf" is the string into which device response is stored
// Test lenght of response
if (strlen (buf) < 16) goto Error;
if (strcmp (buf, "ATEST EQUIPMENT\r")) goto Error;

// If you are here, the communication is established

//----------------------------------------
// Communicate with the equipment
//----------------------------------------
// Manipulate array values
array[0] = 65;
array[1] = 66;
...
array[13] = 70;

// Compute and add the checksum
array[14] = CheckSum (array);

// Send the command to the device
for (i = 0; i < 14; i++) ComWrtByte (1, array[i]);
ComWrtByte (1, 13); // Add carriage return

// Wait response
ComRd (buf)

// Again, test response lenght
if (strlen (buf) < 16) error routine

// Test response
for (i = 0; i < 16; i++) { // For every byte
// Decode individual bits by testing with the "&" operator: if =0 bit off else bit on
bit0 = buf[i] & 0x1 ? 1 : 0
bit1 = buf[i] & 0x2 ? 1 : 0
...
bit4 = buf[i] & 0x10 ? 1 : 0
bit5 = buf[i] & 0x20 ? 1 : 0
...
}



int CheckSum (int *array)

// Compute the checksum
{
unsigned int i, cs, sum = 0;

for (i = 0; i < 14; i++) sum += array[i];
...
...
...

return cs;
}

Message Edited by Roberto Bozzolo on 05-10-2005 11:15 PM



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 14 of 23
(1,887 Views)
Ok, I have looked at your code and can precise a little the preceding pseudo-code. Look at this new version:

unsigned int i, array[20];
unsigned char buf[20];

//----------------------------------------
// Configure the port for communication
//----------------------------------------
OpenComConfig
SetComTime

//----------------------------------------
// Establish communication
//----------------------------------------
ComWrt ("ATEST EQUIPMENT\r")
ComRd (buf) // "Buf" is the string into which device response is stored
// Test lenght of response
if ( strlen (buf) < 16) goto Error;
if (strcmp (buf, "ATEST EQUIPMENT\r")) goto Error;

// If you are here, the communication is established

//----------------------------------------
// Communicate with the equipment
//----------------------------------------
// Manipulate array values
array[0] = 65;
array[1] = 66;
...
array[13] = 70;

// Compute and add the checksum
array[14] = CheckSum (array);

// Send the command to the device
for (i =0; i < 14; i++) ComWrtByte (1, array[i]);
ComWrtByte (1, 13); // Add carriage return

// Wait response
ComRd (buf)

// Again, test response lenght
if (strlen (buf) < 16) error routine

// Test response
for (i = 0; i < 16; i++) { // For every byte
// Decode individual bits by testing with the "&" operator: if =0 bit off else bit on
bit0 = buf[i] & 0x1 ? 1 : 0
bit1 = buf[i] & 0x2 ? 1 : 0
...
bit4 = buf[i] & 0x10 ? 1 : 0
bit5 = buf[i] & 0x20 ? 1 : 0
...
}

unsigned int CheckSum (unsigned int *array)

// Compute the checksum

{

}


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 15 of 23
(1,886 Views)
Roberto,

One quick Question- when im reading the input for bit byte 3 bit 3

It should be bit3=buf[3] & 0x4 ? 1:0

or

bit3= buf[3] & 0x3 ? 1:0

Thanks in advance and I got the relays working was very simple actually (yeah now I can say it after I got them working LOL)

With Regards
Mehar
0 Kudos
Message 16 of 23
(1,863 Views)
"&" is the bit-wise AND operator: it performs AND comparison bit-by-bit on two operands. If you look at binary representation of the rightmost operator you can understand better what happens:

0x01 = 00000001
0x02 = 00000010
0x04 = 00000100
0x08 = 00001000
0x10 = 00010000
0x20 = 00100000
0x40 = 01000000
0x80 = 10000000

Each one of these number has only one bit high, therefore ANDing a number with one of them means to detect if in the original number that particular bit is high.

You could AND with more complex numbers in case you need to extract more informations from the received bytes. ANDin with 0x3 for example means to xtract bits 1 and 2: 0x3 = 00000011


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 17 of 23
(1,860 Views)
Roberto

Sorry no communication, was really busy with the project, I have the initial talk to be occuring ("Atest Equipment") but I am having problem when I do the later on communications with the unit as it is not responding as it should be.

I think the problem lies in the WrtComByte Function because I tried the attached Code and that did not work either.

Please have a look at it and advice me.

With Regards
0 Kudos
Message 18 of 23
(1,848 Views)
Roberto
Never Mind about the earlier Problem I was not adding the carriage return to it and that was screwing it, but I have a different problem now at hand.

bit0of5=Rdbuf1[5] & 0x01 ? 0:1;

This is always coming to 0 no matter what. What should be the bit0of5 be assigned as , I mean as an int or doubke?

With Regards
0 Kudos
Message 19 of 23
(1,835 Views)
Hello Roberto

I have pin pointed the problem to this. The example dll code is presented here, what it is doing is measuring the Ascii value of the 6th byte and then passing on the value to the Test Stand. I think it is something stupid on my part that I am not able to extract the data out of the byte and then convert it to byte and then pass onto Test Stand.
The process should be

Tx 16 bytes ------> Rx 24 bytes --------> Obtain desired byte( 6th in this particular case)----------> Transfer its Ascii value to a double (testmeasurement)------->Pass on that value of double to Test Stand.

I dont know where I am breaking the chain or if the chain is even wrong or there is another process of doing it. I am attaching the screen capture module from the function I am using in Test Stand. I am always getting the result to be a 0, no matter what I do. I am attaching the source code being used in this test to pass on the value. I have tried the code to work independently in the attached atest.prj but it is not working when i try to run it in Test Stand.


void __declspec(dllexport) __stdcall ADC_J3_1(double *measurement,
char reportText[1024], short *errorOccurred, long *errorCode, char errorMsg[1024])
{
int error = 0;
// ErrMsg errMsg = {'\0'};
// ERRORINFO errorInfo;

// REPLACE THE FOLLOWING WITH YOUR SPECIFIC TEST CODE
double testMeasurement = 5.0;
// double lowLimit;

char Rdbuf[23];
int i;

//--------------------------
// Write Data
//--------------------------
Wrtbuf[0]=0x41;
Wrtbuf[1]=0x02;
Wrtbuf[2]=0x00;
Wrtbuf[3]=0x00;
Wrtbuf[4]=0x00;
Wrtbuf[5]=0x00;
Wrtbuf[6]=0x00;
Wrtbuf[7]=0x00;
Wrtbuf[8]=0x00;
Wrtbuf[9]=0x00;
Wrtbuf[10]=0x00;
Wrtbuf[11]=0x00;
Wrtbuf[12]=0x00;
Wrtbuf[13]=0x00;
Wrtbuf[14]=chksum(Wrtbuf);
//Wrtbuf[15]=0x0D;
for (i=0; i<15; i++)
{
ComWrtByte (COMport,Wrtbuf[i]);
//DebugPrintf("%c",Wrtbuf[i]);
}
ComWrtByte (COMport,0x0D);
Delay(1);
//------------------------------
// Receive Data
//------------------------------

ComRd (COMport, Rdbuf, 24); // "Buf" is the string into which device response is stored

// Test lenght of response

if (strlen (Rdbuf) < 24) goto Error;
//TestResponse
//sprintf(&Rdbuf[6],"%s>%f",&testMeasurement);
//Scan(&Rdbuf[6],"%s>%f",&testMeasurement);
//Fmt(&Rdbuf[6], "%s>%f",testMeasurement);
//testMeasurement=Rdbuf[6];
//DebugPrintf("%x",Rdbuf[6]);
testMeasurement= strtod(&Rdbuf[6], NULL);

*measurement = testMeasurement;

// The following code shows how to access a property or variable via the TestStand ActiveX API
// To use this code you must add a parameter "CAObjHandle seqContextCVI" to this function and pass
// a sequence context to it.
// tsErrChk(TS_PropertyGetValNumber(seqContextCVI, &errorInfo,
// "Step.Limits.Low", 0, &lowLimit));

Error:
// FREE RESOURCES HERE

// If an error occurred, set the error flag to cause a run-time error in TestStand.
if (error < 0)
{
// *errorOccurred = TRUE;

// OPTIONALLY SET THE ERROR CODE AND STRING
// *errorCode = error;
// strcpy(errorMsg, errMsg);
}
}
0 Kudos
Message 20 of 23
(1,835 Views)