ni.com is currently undergoing scheduled maintenance.
Some services may be unavailable at this time. Please contact us for help or try again later.
09-08-2009 07:30 PM
ok , for some reason today when we were scoping to see what we were sending out, all of my bits were reverse.
so say for instance if i set outputdata[4]=1;
on the scope machine it would send out 1000000 instead of 00000001.
so that could be an issue. also on the scope machine we kept seeing extra bits , it would throw in a 1 0, so everytime the 1 0, i would se my next element of the array.
so i dont know whats thats all about.
then also my element [6] wasnt the correct sum, so im going to try one more thing and then say its a hardware issue. but you can assist me if you want.
****************************************
#include <ansi_c.h>
#include <visa.h>
#include <userint.h>
#include <rs232.h>
#include <utility.h>
#include <stdio.h>
#include "visa.h"
#define MSCARD_BYTE 0x00
#define NUM_ADDRESS_BITS 0x5
#define NUM_BYTE_IN_CMD 0x7
#define NUM_BYTE_IN_RESP 0x7
#define SEND_CHKSUM_BYTE 0x6
#define RECORD_CHKSUM_BYTE 0x2
#define REC_BUSERROR_BYTE 0x3
#define TEXT_LENGTH 2000
#define COMPORT 10
#define BAUDRATE 115200
#define DATABITS 8
#define PARITY 0
#define STOPBITS 1
#define INPUTQ 512
#define OUTPUTQ 512
#define STRINGSIZE 7
int MASTER_RESET_UPDATE_DEVICE ( int CommandCode,int deviceAddress, int data );
//static char COM[6] = "COM10\0";
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()
{
// MASTER_RESET_UPDATE_DEVICE('R',0,0);
MASTER_RESET_UPDATE_DEVICE('U',0x1,0xFA);
return 0;
}
int MASTER_RESET_UPDATE_DEVICE (int CommandCode, int deviceAddress, int data )
{
int device_err;
int msblsb=0;
int MSCardAddress=0;
// CommandCode='U';
// deviceAddress=0x1;
// data=0xFA;
device_err= OpenComConfig(COMPORT,"",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
outputdata[4];
outputdata[5];
// calc check sum
outputdata[6] = outputdata[0] + outputdata[1] + outputdata[2] + outputdata[3] +outputdata[4]+ outputdata[5];
outputdata[6] = outputdata[6] & 0xFA;
bytes_sent=ComWrt(COMPORT,outputdata,NUM_BYTE_IN_CMD);
Delay(0.5);
bytes_read=ComRd(COMPORT,inbuff,NUM_BYTE_IN_CMD);
if (bytes_read != NUM_BYTE_IN_CMD)
{
MessagePopup("%s","NOT READING ANYTHING, CHECK HARDWAREV!!");
} */
// Get response from COM device
if (bytes_sent != NUM_BYTE_IN_CMD)
{
MessagePopup("%s","CAN'T WRITE TO DEVICE, CHECK COMPORT SETTINGS!!");
}
// Get response from COM device
// compare card Address bytes
if (outputdata[MSCARD_BYTE] != inbuff[MSCARD_BYTE])
{
MessagePopup("%s","CHECK CARD ADDRESS!!");
}
// compare checksum bytes
if (outputdata[SEND_CHKSUM_BYTE] != inbuff[RECORD_CHKSUM_BYTE])
{
MessagePopup("%s","CHECK SUM BYTE NOT EQUAL!!");
}
// Check returned status byte
if (inbuff[REC_BUSERROR_BYTE] == 0)
{
return VI_SUCCESS;
}
return 0;
}
09-08-2009 11:22 PM
Duplicate post. Answered here.
http://forums.ni.com/ni/board/message?board.id=180&message.id=42957&jump=true#M42957