[SOLVED] serial port write with no delay between bytes when sending hex values

I’m trying to send hex data out of the FTDI serial port IC at 19200, 8N1. (windows 7, processing 3.3.6)

When I use this code:

public void button2(){
  int i;
  int collect[] = {0x55,0x02,0x50,0xFE,0x20,0x20,0x20,0x20,0x30,0x03};

  intTxCnt+=1;
  print("Sent (dec) " + intTxCnt + " : "); 

  for(i = 0 ; i < collect.length ; i++) 
  {
      myPort.write(collect[i]);
      print(collect[i]);
      print(" ");
  }
  println(" ");
}

There is a roughly 0.6mS to 1.2mS delay between bytes. (I’m using a logic analyzer to see this) (it is easy to see why there is a delay, only one byte is loaded in at a time and windows 7 makes the delay variable)

When a string is written to the serial port, there is no variable delay between bytes:

  myPort.write("hello");

But, what I would like to do is write the hex (binary or non-ASCII) values in the “collect” array without the variable delay between the bytes. Any thoughts on how to do this?

Matt Meerian

1 Like

Change collect’s datatype to byte[], and pass it as Serial::write()'s argument.

3 Likes

That did the trick, it works wonderfully.
GoToLoop, thanks for the help.
matt