09-07-2009 06:10 AM
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.
09-07-2009 09:15 AM
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
---------
09-07-2009 09:26 AM
'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)
09-07-2009 09:46 AM
09-07-2009 10:00 AM
09-07-2009 10:15 AM
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)
09-07-2009 10:38 AM
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?
09-07-2009 11:01 AM
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?
09-07-2009 11:04 AM
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?
09-08-2009 03:33 AM
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);
}