Example #1
0
/*!*****************************************************************************
 *******************************************************************************
\note  read_serial
\date  Oct 2000
   
\remarks 

        reads into a buffer

 *******************************************************************************
 Function Parameters: [in]=input,[out]=output

 \param[in]     fd : file descriptor
 \param[in]     n_bytes: number of bytes to read
 \param[out]    buffer: buffer for read

     returns the number of bytes actually read

 ******************************************************************************/
int
read_serial(int fd,int n_bytes, char *buffer) 
{

  return rt_dev_read(fd, buffer, n_bytes);

}
Example #2
0
///============================================== FUNCTION HEADER=======================================================
/// Name        : Q8EncoderInput
/// Input       : iCardNum    - PCI memory region that is mapped to Q8 card memory
///               iChannelNum - Encoder channel number
/// Output      : None
/// Return      : an int32_t value that is read
/// Description : Reads the specified channel of encoder.Actually the value read is the counter value of the specified
///               channel
///
///=====================================================================================================================
int32_t Q8EncoderInput(int iCardNum,int iChannelNum) {
    if(fd==-1) {
        fd = rt_dev_open(DEV_NAME, O_RDWR);
    }
    struct_Q8_Config q8Str;
    q8Str.uiFuncIndex=iChannelNum+16;
    rt_dev_read(fd,&q8Str,sizeof(struct_Q8_Config));
    return q8Str.dwNvalue;
}
Example #3
0
int main(int argc, char *argv[])
{
	char buf[1024];
	ssize_t size;
	int device;
	int ret;

	/* open the device */
	device = rt_dev_open(DEVICE_NAME, 0);
	if (device < 0) {
		printf("ERROR : can't open device %s (%s)\n",
		       DEVICE_NAME, strerror(-device));
		fflush(stdout);
		exit(1);
	}

	/* first read */
	size = rt_dev_read (device, (void *)buf, 1024);
	printf("Read in device %s\t: %d bytes\n", DEVICE_NAME, size);

	/* first write */
	sprintf(buf, "HelloWorld!");
	size = rt_dev_write (device, (const void *)buf, strlen(buf) + 1);
	printf("Write from device %s\t: %d bytes\n", DEVICE_NAME, size);

	/* second read */
	size = rt_dev_read (device, (void *)buf, 1024);
	printf("Read in device %s\t: %s\n", DEVICE_NAME, buf);

	/* third read */
	size = rt_dev_read (device, (void *)buf, 1024);
	printf("Read in device %s\t: %d bytes\n", DEVICE_NAME, size);

	/* close the device */
	ret = rt_dev_close(device);
	if (ret < 0) {
		printf("ERROR : can't close device %s (%s)\n",
		       DEVICE_NAME, strerror(-ret));
		fflush(stdout);
		exit(1);
	}

	return 0;
}
Example #4
0
///================================================= FUNCTION HEADER==================================================
/// Name        : Q8GetIrq
/// Input       : iCardNum     - PCI memory region that is mapped to Q8 card memory
/// Output      : None
/// Return      : Q8 IRQ Line number
/// Description : This function fetches irq line number assigned to Q8 card.
///===================================================================================================================
uint8_t Q8GetIrq(int cardNum) {

    struct_Q8_Config q8Str;
    q8Str.uiFuncIndex=42;
    if(fd==-1) {
        fd = rt_dev_open(DEV_NAME, O_RDWR);
    }
    rt_dev_read(fd,&q8Str,sizeof(struct_Q8_Config));
    return q8Str.irq;
}
Example #5
0
///==========================================FUNCTION HEADER============================================================
/// Name        : Q8AnalogInput
/// Input       : iCardNum    - PCI memory region that is mapped to Q8 card memory
///               iCahnnelNum - D/A input channel number
/// Output      : None
/// Return      : None
/// Description : Reads the  voltage value from the specified channel.
///
///=====================================================================================================================
int16_t Q8AnalogInput(int iCardNum,int iChannelNum) {

    if(fd==-1) {
        fd = rt_dev_open(DEV_NAME, O_RDWR);
    }
    struct_Q8_Config q8Str;
    q8Str.iCardNum=iCardNum;
    q8Str.uiFuncIndex=iChannelNum+8;
    rt_dev_read(fd,&q8Str,sizeof(struct_Q8_Config));
    return q8Str.wValueSigned;
}
Example #6
0
///================================================ FUNCTION HEADER======================================================
/// Name        : Q8DigitalInput
/// Input       : iCardNum        - PCI memory region that is mapped to Q8 card memory.
///               iPtrChannelNums - Array address.In this array numbers of channels read are defined and stored.
///               iArraySÄ°ze      - Array size.
/// Output      : None
/// Return      : an unint32_t value
/// Description : Configures  the specified channel(s) as input(s) and reads the specified channel(s)
///
///=====================================================================================================================
uint32_t  Q8DigitalInput(int iCardNum,uint32_t channel,int readonly) {


    if(fd==-1) {
        fd = rt_dev_open(DEV_NAME, O_RDWR);
    }

    uint32_t udwDigitalRead=0;
    struct_Q8_Config q8Str;
    q8Str.uiFuncIndex=25;
    q8Str.onlyDigitalData=readonly;
    q8Str.udwDataDirection=0xFFFFFFFF;
    q8Str.udwDataDirection&=channel;
    q8Str.iCardNum=iCardNum;
    int i;
    uint32_t udwDataBuffer;
    uint32_t udwDataReg;
    rt_dev_read(fd,&q8Str,sizeof(struct_Q8_Config));
    return q8Str.udwDataRegister;
}