示例#1
0
// настроить порт
int port_init ( askue_port_t *Port, const char *file, const char *speed, const char *dbits, const char *sbits, const char *parity )
{
    int RS232 = rs232_open ( file );
    if ( rs232_init ( RS232, &( Port->Termios ) ) )
    {
        rs232_close ( RS232 );
        return -1;
    }
    
    rs232_set_databits ( &( Port->Termios ), dbits );
    rs232_set_stopbits ( &( Port->Termios ), sbits );
    rs232_set_parity ( &( Port->Termios ), parity );
    rs232_set_speed ( &( Port->Termios ), speed );
    
    if ( rs232_apply ( RS232, &( Port->Termios ) ) )
    {
        rs232_close ( RS232 );
        return -1;
    }
    
    Port->RS232 = RS232;
    if ( __port_open ( Port ) )
    {
        close ( Port->RS232 );
        return -1;
    }
    else
    {
        return 0;
    }
}
示例#2
0
void bs_inverter_init(u_int8_t bs_mode)
{
  char* buffer=NULL;
  buffer=calloc(BUFFERSIZE_BS_INVERTER, 1);
  struct bs_inverter_elements bs_inverter_stat;
  memset(&bs_inverter_stat,0, sizeof(bs_inverter_stat));
  
  switch (bs_mode)
  {
    case 0:
      bs_inverter_get_stats(buffer, &bs_inverter_stat);
      bs_inverter_get_param(buffer, &bs_inverter_stat);
      rs232_close();
      bs_inverter_print_stats(&bs_inverter_stat);
      bs_inverter_print_param(&bs_inverter_stat);
    break;
    case 1:
      bs_inverter_get_stats(buffer, &bs_inverter_stat);
      rs232_close();
      bs_inverter_print_stats(&bs_inverter_stat);      
    break;
    case 2:
      bs_inverter_get_param(buffer, &bs_inverter_stat);
      rs232_close();
      bs_inverter_print_param(&bs_inverter_stat);
    break;
    case 3:
      bs_raw_mode();
      rs232_close();
    break;
  }

  if (buffer!=NULL) buffer=NULL;
  
}
示例#3
0
//------------------------------------------------------
unsigned int get_compass_position_360(void)
{
	int ttys_descriptor;
	int bytes_arrived = 0;
	unsigned char buffer_in[MAX_LEN_BUFFER];
	float ret_value;
	while(1) 
	{
			ttys_descriptor = init_serial_port();
			write_cmd(ttys_descriptor,0x12);
			sleep(1);
			bytes_arrived = rs232_buffer_in_lenght(ttys_descriptor);
			if (bytes_arrived != ANSWER_CMD_360_POS_LENGHT)	
			{
				printf("ERROR: Re-send command (360) to serial port, bytes arrived:%d\n",bytes_arrived);
				rs232_close(ttys_descriptor);
				continue;
			}
			break;	
	}
	rs232_get(ttys_descriptor,buffer_in, ANSWER_CMD_360_POS_LENGHT);
	ret_value = (((float)buffer_in[0]) * 360)/255;
	rs232_close(ttys_descriptor);	  
	return (unsigned int)ret_value;
}
示例#4
0
文件: cpap.c 项目: hawkhsieh/sigbox
void *functionTestUART( void *param )
{
    int uart_id_index=(int)param;
    char command_code[32]={0x93,0xaa};
    UartID *uart_id = &cpap_global.uart_id[uart_id_index];
    uint8_t recv_buffer[128];
    int is_cpap_present=0;

   // pthread_detach( pthread_self() );
    if ( SendCommand( uart_id->descriptor , command_code , 2 , recv_buffer , sizeof( recv_buffer ) , 4 ) > 0 )
    {
        if ( recv_buffer[0] == 0x93 && recv_buffer[1] == 0xaa )
        {
            printf_debug("use uart %s , uart_id[%d].descriptor=%d\n" , uart_id->deviceName , uart_id_index , uart_id->descriptor );
            is_cpap_present=1;
            cpap_global.uart_fd=uart_id->descriptor;
        }
        else
        {
            printf_debug("close uart %s doesnt echo\n" , uart_id->deviceName );
        }
    }

    if ( is_cpap_present == 0 )
    {
        rs232_close( uart_id->descriptor );
        uart_id->descriptor = -1;
    }

    return 0;
}
示例#5
0
RS232_LIB void
rs232_end(struct rs232_port_t *p)
{
	struct rs232_windows_t *wx = p->pt;

	DBG("p=%p p->pt=%p\n", (void *)p, p->pt);

	if (!rs232_port_open(p)) {
		free(p->pt);
		free(p);
		return;
	}

	rs232_flush(p);

	if (!SetCommState(wx->fd, &wx->old_dcb)) {
		DBG("SetCommState() %s\n", last_error());
		return;
	}

	if (!SetCommTimeouts(wx->fd, &wx->old_tm)) {
		DBG("SetCommTimeouts() %s\n", last_error());
		return;
	}

	rs232_close(p);
	free(p->pt);
	free(p);
}
示例#6
0
文件: rs232.c 项目: AreaScout/vice
/* reset RS232 stuff */
void rs232_reset(void)
{
    int i;

    for (i = 0; i < RS232_NUM_DEVICES; i++) {
        if (fds[i].inuse) {
            rs232_close(i);
        }
    }
}
示例#7
0
void mppt_init()
{
  char* buffer=NULL;
  buffer=calloc(MPPT_BUFFERSIZE, 1);
  
  mppt_read(buffer);
  rs232_close();
  
  if (buffer!=NULL) buffer=NULL;
  
}
/* error = port:close() */
static int lua_port_close(lua_State *L)
{
	struct rs232_port_t *p = *(struct rs232_port_t**) luaL_checkudata(L, 1, MODULE_NAMESPACE);

	if (p == NULL || !rs232_port_open(p)) {
		lua_pushinteger(L, RS232_ERR_PORT_CLOSED);
		return 1;
	}

	lua_pushinteger(L, rs232_close(p));
	return 1;
}
示例#9
0
//----------------------------------------------------
void get_compass_data_full(unsigned char *buffer_in)
{
	int ttys_descriptor;
	int bytes_arrived = 0;

	while(1) 
	{
			ttys_descriptor = init_serial_port();
			write_cmd(ttys_descriptor,0x23);
			sleep(1);
			bytes_arrived = rs232_buffer_in_lenght(ttys_descriptor);
			if (bytes_arrived != ANSWER_CMD_FULL_LENGHT)	
			{
				printf("ERROR: Re-send command (FULL) to serial port, bytes arrived:%d\n",bytes_arrived);
				rs232_close(ttys_descriptor);
				continue;
			}
			break;	
	}
	rs232_get(ttys_descriptor,buffer_in, ANSWER_CMD_FULL_LENGHT);
	rs232_close(ttys_descriptor);	
}
示例#10
0
void mppt_init_raw()
{
  char* buffer=NULL;
  buffer=calloc(MPPT_BUFFERSIZE, 1);
  int idx=0;
  
  set_interface_attr(B19200, 0);
  sleep(MPPT_RS232_TIMEOUT);
  rs232_read(buffer, MPPT_BUFFERSIZE, MPPT_RS232_TIMEOUT, 0);
  rs232_close();
  for (idx=0; idx<MPPT_BUFFERSIZE;idx++)
  {
    printf("0x%02x ", buffer[idx]);
  }
  printf("\n");
  if (buffer!=NULL) buffer=NULL;
  
}  
示例#11
0
//------------------------------------------------------
void reset_cmps10()
{ 
	int ttys_descriptor;
	int bytes_arrived;
	unsigned char buffer_in[MAX_LEN_BUFFER],cmd_1,cmd_2,cmd_3;
	
	// Open serial port 
	ttys_descriptor = rs232_open(SERIAL_PORT,B9600,CS8,PNONE,SB1);

	// Test port descriptor 
	if(ttys_descriptor == -1)	{printf("ERROR:serial port not open,exit!!!");exit(1);}
	
	// Command to send
	cmd_1 = 0x6A;cmd_2 = 0x7C;cmd_3 = 0x81;
	
	// Send request 0x23
	bytes_arrived = 0;
	rs232_write(ttys_descriptor,&cmd_1,1);
	usleep(50000);
	bytes_arrived = rs232_bytes_arrived(ttys_descriptor,0);
	rs232_get(ttys_descriptor,buffer_in, 1);
	printf("Bytes arrived %d - Value %d\n",bytes_arrived,buffer_in[0]);
	
	rs232_write(ttys_descriptor,&cmd_2,1);
	usleep(50000);
	bytes_arrived = rs232_bytes_arrived(ttys_descriptor,0);
	rs232_get(ttys_descriptor,buffer_in, 1);
	printf("Bytes arrived %d - Value %d\n",bytes_arrived,buffer_in[0]);
		
	rs232_write(ttys_descriptor,&cmd_3,1);
	usleep(50000);
	bytes_arrived = rs232_bytes_arrived(ttys_descriptor,0);
	rs232_get(ttys_descriptor,buffer_in, 1);
	printf("Bytes arrived %d - Value %d\n",bytes_arrived,buffer_in[0]);
	rs232_close(ttys_descriptor);
	
}
CommunicatieBeheerder::~CommunicatieBeheerder() {
    rs232_close();
}
/*------------------------------------------------------------------------------
 * main -- Open terminal and launch keypad thread.
 *         Check for button input and respond appropriately
 *------------------------------------------------------------------------------
 */
int main (void) {
//  int i;
  int ret;
  char *emergency="! EMERGENCY !";
  char button_read = FALSE;  // Local snapshot of Global 'Button'
  char prev_button = 0;

  /* error handling - reset LEDs */
  atexit(closing_time);
  signal(SIGINT, closing_time);

  term_initio();
  rs232_open();
  
  setup_ports();
  ret = pthread_create( &keypad_thread, NULL, keypad, NULL);
    
  while(alive){
    button_read = button;
    if(button_read){
      if(prev_button != button_read){
        if(blocking){
          while(blocking == TRUE && alive){
            usleep(SLEEP);
          }
        }
        else{
          printf("button: %c\n",button_read);
          switch(button_read){
            case 'A':
              display_string("Hello. =)",BLOCKING);
              break;
            case 'B':
              move_cursor(LEFT);
              break;
            case 'C':
              display_string("Cancel =(",NOT_BLOCKING);
              break;
            case 'D':
              delete_char();
              break;
            case 'E':
              display_string(emergency,BLOCKING);
              break;
            case 'F':
              move_cursor(RIGHT);
              break;
            case ERROR:
              break;
            default:
              insert_char(button_read);
              break;
          }
        }
      }
    }
    prev_button = button_read;
  }

  pthread_join(keypad_thread, NULL);

  term_exitio();
  rs232_close();
  return 0;
}
示例#14
0
void QRS232::close()
{
	rs232_close(m_port);
	m_open = false;
	m_port = NULL;
}
示例#15
0
void close_term(){
  term_exitio();
  rs232_close();
}
示例#16
0
void term_phoenix_close()
{
    rs232_close(fd);
}
示例#17
0
int main (void) {
//  int i;
  int ret;
  char *emergency="! EMERGENCY !";
  char *welcome="Welcome.";
  char *enter_pin="Please Enter PIN.";
  char button_read = FALSE;  // Local snapshot of Global 'Button'

  /* error handling - reset LEDs */
  atexit(closing_time);
  signal(SIGINT, closing_time);

  term_initio();
  rs232_open();
  
  setup_ports();
  ret = pthread_create( &keypad_thread, NULL, keypad, NULL);

//  display_string(welcome,PADDED,BLOCKING);

  while(alive){
    if(state == EMERGENCY){
        display_string(emergency,PADDED,NOT_BLOCKING);
      continue;
    }
    switch(state){
      case WAITING_LOGGED_OUT:
        display_string(enter_pin,PADDED,NOT_BLOCKING);
        digits[0] = 0x80;  // Set cursor position
        
        while(!button && alive && state == WAITING_LOGGED_OUT){ // Just Wait 
         usleep(SLEEP);
        }
        if(state == EMERGENCY) break; // Get out if there's an emergency
        if(button >= '0' && button <= '9'){
          state = INPUTTING_PIN; // Fall through to next state
        }
        else{
          break;
        }
        
      case INPUTTING_PIN:
        if(button_read = button){ // Intentionally Assignment
          input_pin(button_read);  // Sends a snapshot of button
        }
        cursor_blink();
        break;
        
      case WAITING_LOGGED_IN:
        display_string("Enter Track Number.",PADDED,NOT_BLOCKING);
        digits[0] = 0x80;  // Set cursor position
        
        while(!button && alive && state == WAITING_LOGGED_IN){ // Just Wait 
          usleep(SLEEP);
        }
        if(state == EMERGENCY) break; // Get out if there's an emergency
        if(button >= '0' && button <= '9'){
          state = INPUTTING_TRACK_NUMBER; // Fall through to next state
        }
        else if(button == ENTER_MENU){
          state = MENU_SELECT; // Fall through to next state
          break;
        }
        else{
          break;
        }
        
      case INPUTTING_TRACK_NUMBER:
        if(button_read = button){ // Intentionally Assignment
          input_track_number(button_read);  // Sends a snapshot of button
        }
        cursor_blink();
        break;
        
      case MENU_SELECT:
        display_string("MENU.",PADDED,NOT_BLOCKING);
        menu_select();
        break;
        
      default:
        break;
    }
    delay();
  }


  pthread_join(keypad_thread, NULL);

  term_exitio();
  rs232_close();
  return 0;
}
示例#18
0
void rs232drv_close(int fd)
{
    rs232_close(fd);
}