示例#1
0
文件: test.c 项目: birenpandya/sensor
int main(int argc, char *argv[])
{

	unsigned long count;
	count = 0;
	int temp = 0;
	int i =0 ;       
	int reset = 0;
	int bd = atoi(argv[1]);
        int dc1 = atoi(argv[2]);
        int dc2 = atoi(argv[3]);

	baud_rate = bd;
	printf("bd is set to %d\n",baud_rate);
	ptz_init();
	ptz_write(RS485_DEVICE_WRITE_MODE);
	status = uart_init(UART_PORT) ;
	printf("\n V.2.2: delay: %d \n",dc1);
	if(status <= 0 )
	{
                printf("\nmodbusRS485_init: uart_init failed:%d \n",status);
                return  FAILURE;
        }
		dc2 =dc2*1000;
		dc1 =dc1*1000;
	printf("Delay set is Before write %d \t after write %d \n",dc1,dc2);
	while(1)
	{
//	ptz_write(RS485_DEVICE_WRITE_MODE);
          //      usleep(dc);
#if 1
	status = uart_write(UART_PORT,r2,11);
	if(status < SUCCESS){
                printf("\nsensor write failed Error:%d \n ",status);
                status = FAILURE;
         }
	usleep(dc1);
#endif
	ptz_write(RS485_DEVICE_READ_MODE);
     // usleep(dc2);
#if 1 
	temp = uart_read(UART_PORT,buffer_t1, 1);
         if(temp > 0){
		printf("\nbuff contains : \n");
		  for(i = 0; i <= temp; i++)
			  printf("\t%c\t ",buffer_t1[i]);
	 }
	 else{
		printf("uart read : error %d \n",temp);
	}

     #endif 
//	usleep(500);
//	ptz_write(RS485_DEVICE_WRITE_MODE);
	sleep(1);
	printf("\n ++ %d \n",++tp);


	}
}
示例#2
0
/*
Function to initialize RS485 communication.
*/
int modbusRS485_init(int ionum)
{	
	int status = MODBUS_SUCCESS;
	rs485port = ionum;
#if MODBUS_DEBUG
	printf(" rs485 port is %d \n",rs485port);	
#endif
	ptz_init();
 	ptz_write(RS485_DEVICE_WRITE_MODE);

	if (uart_init(0) <= 0) {
		printf("modbusRS485_init: uart_init failed \n");
		status = EMODBUS_INIT;
	}

#if MODBUS_DEBUG
        printf("  port is %d  open\n",rs485port);
#endif
	
	return status;
}
示例#3
0
int main(int argc, char **argv)
{
	memset(&global_ptz_private_handle, 0x00, sizeof(global_ptz_private_handle));
	ptz_init(&global_ptz_private_handle);	
	SYS_INFO("Enter ptz_manager func.\r\n");
	
	while(1)
	{
		if (poll(global_ptz_private_handle.polltimeout, global_ptz_private_handle.active_fdcount , -1) > 0) 
        {
			SYS_INFO("POLL event found.\r\n");
			if (global_ptz_private_handle.polltimeout[0].revents)
			{
				//do UNIX recv event.
				ptz_unix(&global_ptz_private_handle);
			}
			ptz_poll_init(&global_ptz_private_handle);
		}
	}

	return 0;
}