Exemplo n.º 1
0
void send_command(const char *command)
{
   char tx_buf[32];
#ifdef ALLEGRO_WINDOWS
   DWORD bytes_written;
#endif
   
   sprintf(tx_buf, "%s\r", command);  // Append CR to the command
   
#ifdef ALLEGRO_WINDOWS
   PurgeComm(com_port, PURGE_TXCLEAR|PURGE_RXCLEAR);
   WriteFile(com_port, tx_buf, strlen(tx_buf), &bytes_written, 0);
   if (bytes_written != strlen(tx_buf))
   {
#ifdef LOG_COMMS
      log_comm("TX ERROR", tx_buf);  // Log transmission error
#endif
      return;
   }
#else
   comm_port_flush_output(com_port);
   comm_port_flush_input(com_port);
   comm_port_string_send(com_port, tx_buf);
#endif
   
#ifdef LOG_COMMS
   write_comm_log("TX", tx_buf);
#endif
}
Exemplo n.º 2
0
void close_comport()
{
   if (comport.status == READY)    // if the comport is open, close it
   {
#ifdef ALLEGRO_WINDOWS
      PurgeComm(com_port, PURGE_TXCLEAR|PURGE_RXCLEAR);
      CloseHandle(com_port);
#else
      comm_port_flush_output(com_port);
      comm_port_flush_input(com_port);
      comm_port_uninstall(com_port);
#endif
   }
   comport.status = NOT_OPEN;
}
Exemplo n.º 3
0
void send_command(const char *command)
{
   char tx_buf[32];
#ifdef ALLEGRO_WINDOWS
   DWORD bytes_written;
#endif
   
   sprintf(tx_buf, "%s\r", command);  // Append CR to the command
   
#ifdef ALLEGRO_WINDOWS
   PurgeComm(com_port, PURGE_TXCLEAR|PURGE_RXCLEAR);
   WriteFile(com_port, tx_buf, strlen(tx_buf), &bytes_written, 0);
   if (bytes_written != strlen(tx_buf))
   {
#ifdef LOG_COMMS
      log_comm("TX ERROR", tx_buf);  // Log transmission error
#endif
      return;
   }
#elif TERMIOS
//    printf("tx:'%s'\n",command);
	if( write(fdtty,tx_buf,strlen(tx_buf)) == -1 )
	{
	  perror("write tty");
	  close(fdtty);
	  fdtty = -1;
	}
	else
	{
        tcflush(fdtty, TCIFLUSH);
	}
#else
   comm_port_flush_output(com_port);
   comm_port_flush_input(com_port);
   comm_port_string_send(com_port, tx_buf);
#endif
   
#ifdef LOG_COMMS
   write_comm_log("TX", tx_buf);
#endif
}
Exemplo n.º 4
0
void send_command(const char *command)
{
   char tx_buf[32];
   
   sprintf(tx_buf, "%s\r", command);  // Append CR to the command

#ifdef LOG_COMMS
   write_comm_log("TX", tx_buf);
#endif

#ifdef ALLEGRO_WINDOWS
   DWORD bytes_written;
   
   PurgeComm(com_port, PURGE_TXCLEAR|PURGE_RXCLEAR);
   WriteFile(com_port, tx_buf, strlen(tx_buf), &bytes_written, 0);
#else
   comm_port_flush_output(com_port);
   comm_port_flush_input(com_port);
   comm_port_string_send(com_port, tx_buf);
#endif
}
Exemplo n.º 5
0
int main_loop(char *desc, int max_val)
{
   static int nsy = 1;

   int   r;
   int   got_i1;
   int   sent_i1;
   int   got_i2;
   int   sent_i2;

   got_i1 = -1;
   sent_i1 = 0;
   if (port2) {
       got_i2 = -1;
       sent_i2 = 0;
   }
   else {
       got_i2 = max_val;
       sent_i2 = max_val;
   }
   comm_port_reinstall(port1);
   if (port2 != NULL) comm_port_reinstall(port2);

   if (nsy) {
      fprintf(stderr, "Press return to start\n");
#ifdef ALLEGRO_H
      while (!keypressed());
      readkey();
#else
      getc(stdin);
#endif
      nsy = 0;
   }
   /* We are now listening at the new configuration. Wait for 0.1 s
    * before starting to transmit to allow the slower system to also
    * be listening before we tranmit. Don't need to do this on the
    * first time thorugh (nsy condition above) as the user has provides
    * the synchronisation then.
    */
   else if (port2 == NULL) {
#ifdef ALLEGRO_H
      rest(100);
#else
      usleep(100000);
#endif
      }

   do {
       if (sent_i1 < max_val) {
           comm_port_out(port1, (unsigned char) sent_i1++);
       }
       if ((r = comm_port_test(port1)) >= 0) {
           if (r == (got_i1+1)) got_i1++;
	   else fprintf(stderr, "ERROR on 1 [expected %d got %d]\n", got_i1+1, r);
       }

       if (port2) {
	   if (sent_i2 < max_val) {
	       comm_port_out(port2, (unsigned char) sent_i2++);
	   }
	   if ((r = comm_port_test(port2)) >= 0) {
	       if (r == (got_i2+1)) got_i2++;
	       else fprintf(stderr, "ERROR on 2 [expected %d got %d]\n", got_i2+1, r);
	   }
       }


       /* Any key will result in a stop if compiled with allegro. Otherwise,
        * use ctrl-c.
	*/
#ifdef ALLEGRO_H
       if (keypressed()) {
	  comm_port_flush_output(port1);
	  if (port2 != NULL) comm_port_flush_output(port2);
	  fprintf(stderr, "\nSTOPPED BY USER\n");
          return -1;
       }
#endif

       show_status(desc, sent_i1-1, got_i1, sent_i2-1, got_i2);
   } while ((got_i1 < (max_val-1)) || (sent_i1 < (max_val-1)) || (got_i2 < (max_val-1)) || (sent_i2 < (max_val-1)));

   show_status(desc, -2, 0, 0, 0);

   return 1;
}