Beispiel #1
0
void bt_sendBIND( char type, char* pString )
{
    RS232_SendBuf(com_port, "AT+BIND=", strlen("AT+BIND="));
    RS232_SendBuf(com_port, pString, strlen(pString));
    RS232_SendBuf(com_port, "\r\n", 2);
    Sleep(100);
}
Beispiel #2
0
void bt_sendCommand( char type, char* pString )
{
//    printf(pString);
//    printf(" ...\t");
//    printf("\n");
    RS232_SendBuf(com_port, pString, strlen(pString));
    if(type == HC05)
        RS232_SendBuf(com_port, "\r\n", 2);
    Sleep(100);
}
void FPGAFitnessCalculator::enviar_individuo(int comport_num,
        const Cromossomo& individuo) {
    RS232_SendByte(comport_num, (unsigned char) SET_CIRCUIT);

    auto descricao_les = individuo.descricao_les();
    auto descricao_outs = individuo.descricao_outs();

    RS232_SendBuf(comport_num, &descricao_les[0], descricao_les.size());
    RS232_SendBuf(comport_num, &descricao_outs[0], descricao_outs.size());
}
void SBGInsIg500N::init(){
	
	SBGSetNavVelocitySrc vel(true,SBGSetNavVelocitySrc::USER);
	SBGSetLowPowerMode gps(true,SBGSetLowPowerMode::SBG_GPS_OFF_MODE);
	SBGSetDefaultOutputMask output(true, EULER );
	SBGSetContinuousMode mode;
	
	if ( RS232_SendBuf(port, vel.to_bytes(), vel.getMessageLength()) != vel.getMessageLength() )
		ROS_INFO("Problem while sending Velocity source");
	getNextAck();
	if ( RS232_SendBuf(port, gps.to_bytes(), gps.getMessageLength()) != gps.getMessageLength() )
		ROS_INFO("Problem while sending GPS power mode");
	getNextAck();
	if ( RS232_SendBuf(port, output.to_bytes(), output.getMessageLength()) != output.getMessageLength() )
		ROS_INFO("Problem while sending default output mask");
	getNextAck();
	if ( RS232_SendBuf(port, mode.to_bytes(), mode.getMessageLength()) != mode.getMessageLength() )
		ROS_INFO("Problem while sending the continuous mode data");
	getNextAck();
}
void transmitBuffer(){
    byte b;
    byte buf[4096];
    int i=0;
    while( serial.outgoing_buffer->pop(b) > -1 )
    {
        buf[i++]=b;
    }
    //Sending data byte by byte is SLOOOOOW. Don't do that if speed is a concern.
    //Save all the data you want to send (e.g. a packet) in a buffer.  Then send
    //the buffer at once to the serial port.
    RS232_SendBuf(TTYACM0, buf,i);
}
Beispiel #6
0
// Write multiple bytes
bool CCPCBooster::WriteBuffer(unsigned char *buffer, const  long nbBytes)
{
	long bytesLeft = nbBytes;

	while(bytesLeft != 0)
	{
		int i = RS232_SendBuf(_COMPortHandle, buffer, bytesLeft);
		if (i >= 0) {
			bytesLeft -= i;
			buffer += i;
		} else {
			// error!
			return false;
		}
	}
	return true ;
}
Beispiel #7
0
int rs232_SendBuf (U1 *pthreads_ptr, U1 *varlist_ptr, U1 *vm_mem_ptr, S4 threadnum, S8 stacksize)
{
	S8 portnumber, size, i;
	S8 retvar_index;
	S8 ret;
	S8 bvar_index;
	S8 byte_b;

	U1 buf[4096];
	
	struct pthreads *pthreads;
	struct varlist *varlist;
	struct vm_mem *vm_mem;
	
	pthreads = (struct pthreads *) pthreads_ptr;
	varlist = (struct varlist *) varlist_ptr;
	vm_mem = (struct vm_mem *) vm_mem_ptr;

	if (stpull_l (threadnum, pthreads, stacksize, &retvar_index) != ERR_STACK_OK) printf ("rs232_SendBuf: stack error!\n");
	if (stpull_l (threadnum, pthreads, stacksize, &size) != ERR_STACK_OK) printf ("rs232_SendBuf: stack error!\n");
	if (stpull_l (threadnum, pthreads, stacksize, &bvar_index) != ERR_STACK_OK) printf ("rs232_SendBuf: stack error!\n");
	if (stpull_l (threadnum, pthreads, stacksize, &portnumber) != ERR_STACK_OK) printf ("rs232_SendBuf: stack error!\n");
	
	var_lock (varlist, bvar_index);
	
	for (i = 0; i < size; i++)
	{
		if (! let_array2_byte (varlist, vm_mem, bvar_index, i, &byte_b)) printf ("rs232_SendBuf: value array overflow!\n");
		buf[i] = byte_b;
	}
	
	var_unlock (varlist, bvar_index);
	
	ret = RS232_SendBuf (portnumber, buf, size);
	
	var_lock (varlist, retvar_index);
	if (! let_2array_qint (varlist, vm_mem, ret, retvar_index, 0)) printf ("rs232_SendBuf: return value array overflow!\n");
	var_unlock (varlist, retvar_index);
	
	
	return (0);
}
// Read from file to serial - used writing to RAM
void read_from_file(char* filename, char* cmd) {
	// Load a new file
	FILE *pFile = fopen(filename, "rb");
	RS232_cputs(cport_nr, cmd);
	
	// Wait a little bit until we start gettings some data
	#ifdef _WIN32
	Sleep(500);
	#else
	usleep(500000); // Sleep for 500 milliseconds
	#endif
	
	int Kbytesread = 0;
	int uptoKbytes = 1;
	unsigned char readbuf[100];
	while(1) {
		if (!(fread((char *) readbuf, 1, 64, pFile))) {
			break;
		}
		readbuf[64] = 0;
		
		// Send 64 bytes at a time
		RS232_SendBuf(cport_nr, readbuf, 64);
		
		printf("#");
		Kbytesread += 64;
		if (Kbytesread / 1024 == uptoKbytes) {
			printf("%iK", (Kbytesread/1024));
			uptoKbytes++;
		}
		fflush(stdout);
		
		#ifdef _WIN32
		Sleep(5);
		#else
		usleep(5000); // Sleep for 200 milliseconds
		#endif
	}
	
	fclose(pFile);
}
// {{{RME transition ':TOP:S1:J5193551C029A:sendCommand'
INLINE_METHODS void serialTranslateCapsule_Actor::transition3_sendCommand( const byteArray * rtdata, serialProtocol::Base * rtport )
{
	// {{{USR
	byteArray b = *rtdata;

	while(this->isSending){ } // Do. absolutely. Nothing... :D

	this->isSending = true;
	unsigned char data[b.size()];
	int i = 0;
	for(i = 0; i < b.size(); i++){
	    data[i] = b.get(i);
	}
	data[i] = 0;

	RS232_SendBuf(COM_PORT, data, b.size());

	/*cout << "STR: Sending data: ";
	b.print();*/

	this->isSending = false;
	// }}}USR
}
Beispiel #10
0
char* ComC(int a, int cport_nr, char *b)
{
  static int j=0;
  int i, k=0, n, bdrate=115200;         /*  cport_nr 15 is (COM16 on windows) */
         /* 115200 baud */
  int bytes_sent, bytes_received;
  unsigned char buf[4096]; //key[70];
  char temp [65];//char temp [64];
  unsigned char login[6] = "root\r";
  unsigned char getValue[11]="fpga info\r";
  //a=1;

  if( a<2 && RS232_OpenComport(cport_nr, bdrate) )
	{
	printf("Can not open comport\n");
    return b[0];
	}


  while(1 && j <1 && a <2)
  {
	
    n = RS232_PollComport(cport_nr, buf, 4095);
	if(n > 0)
    {
      buf[n] = 0;   /* always put a "null" at the end of a string! */

      for(i=0; i < n; i++)
      {
        if(buf[i] < 32)  /* replace unreadable control-codes by dots */
        {
          buf[i] = '.';
        }
      }
	  printf("%s", (char*) buf);
	    if (strstr((char*) buf,"login:"******"Sent %i bytes\n",bytes_sent); 
		// printf("received %i bytes: %s\n", n, (char *)buf);
		j++;
		}
    }
  }
  
  while (a<2) {
	  a=1;
	printf("%s", (char*) buf);
	memset(&buf[0], 0, sizeof(buf));
	Sleep(1000);
	bytes_sent = RS232_SendBuf(cport_nr,getValue, 10);
	Sleep(1000);
	n = RS232_PollComport(cport_nr, buf, 4095);
	Sleep(1000);
	printf("%s", (char*) buf);
	a++;
	}

  j=0;
  //while (j<1 && a>=2 && a <= 64)
  while (j<1 && a>=2 )
  {
	//printf("%s", (char*) buf);
	memset(&buf[0], 0, sizeof(buf));
	Sleep(1000);
	bytes_sent = RS232_SendBuf(cport_nr,getValue, 10);
	Sleep(1000);
	n = RS232_PollComport(cport_nr, buf, 4095);
	Sleep(1000);
	printf("%s \n", (char*) buf);
	fflush(stdout);
	i=0;

	while(k<66) {
		if((buf[112+k]!= 13) && (buf[112+k]!= 10)) {		
			temp[i] = buf[112+k];	
		printf("%c", temp[i]);
		i++;
		}
		k++;
	}

	temp[i] = '\0';
	printf("\n\nThe string is %s", temp);
	a++;
	j++;
  }  

  strcpy(b,temp);
   
  printf("\n%s",b);
  Sleep(100);
  //Print for Debug
  return b;
}
Beispiel #11
0
int Hardware::Send(uint8_t *data, int size)
{	
#ifdef USESERIAL	
    return RS232_SendBuf(SERIAL_PORT, data, size);
#endif
}
int main ( int argc, char *argv[] )
{
  int n,j,
      cport_nr=22,        /* /dev/ttyAMA0 */
      bdrate=9600;       /* 9600 baud */
  unsigned char buf[128];

  // Parse the command line options
  for (j = 1; j < argc; j++) {
	int more = j+1 < argc; // There are more arguments
	if (!strcmp(argv[j],"--port") && more) {
		cport_nr=atoi(argv[++j]);
        } else if (!strcmp(argv[j],"--baud") && more) {
                bdrate=atoi(argv[++j]);
	} else if (!strcmp(argv[j],"--debug")) {
		debug=1;
	} else if (!strcmp(argv[j],"--verbose")) {
		verbose=1;
        } else if (!strcmp(argv[j],"--demo")) {
                demoMode=1;
	} else if (!strcmp(argv[j],"--help")) {
		showHelp();
		exit(0);
	} else {
	fprintf(stderr,	"Unknown or not enough arguments for option '%s'.\n\n",	argv[j]);
	showHelp();
	exit(1);
	}
    }

  if (debug==1)
  {
    printf("Using port %i\n", cport_nr);
    printf("Baud Rate %i\n", bdrate);
  } 

  unsigned char requestString[]  = {0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xEB, 0x90, 0xEB, 0x90, 0xEB, 0x90, 0x16, 0xA0, 0x00, 0xB1, 0xA7, 0x7F};
  int sentChars;

  if (demoMode == 0)
  {
    if(RS232_OpenComport(cport_nr, bdrate))
    {
      if (debug == 1)
        printf("Can not open comport\n");
      return(0);
    }
    
    sentChars = RS232_SendBuf(cport_nr,requestString,18);
    if(sentChars<0) {
      if (debug == 1)
        printf("Can not send request\n");
      return(0);
    }
  }
  else
  {
    sentChars = 18;
  }

  if (debug == 1)
    {
      printf("Sent %i bytes: ", sentChars);
      print_hex_memory((char *)requestString, 18);
    }

  if (demoMode == 0)
  {
    usleep(100000);
    n = RS232_PollComport(cport_nr, buf, 127);
  }
  else
  {
    //Manually fake a response
    unsigned char buf2[]  = {0xEB, 0x90, 0xEB, 0x90, 0xEB, 0x90, 0x00, 0xA0, 0x18, 0xC9, 0x05, 0x36, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x04, 0xAE, 0x05, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x01, 0x01, 0x2E, 0x5D, 0x01, 0x00, 0x21, 0xF2, 0x7F, 0x00};
    memcpy(buf, buf2, 36);
    n=36;
  }

    if(n > 0)
    {
      buf[n] = 0;   /* always put a "null" at the end of a string! */
      if (debug == 1)
      {
        printf("received %i bytes\n", n);
        print_hex_memory((char *)buf, n);
      }
      if (verbose == 1)
        process_string_verbose((char *)buf);
      else
        process_string((char *)buf);
    }


  return(0);
}
Beispiel #13
0
int LagTestSerialPortComm::write(unsigned char* data, int size){
    return RS232_SendBuf(this->portN, data, size);
}