Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA CODE Create a new Transmit Thread in the ConnectPort class. This Thread sho

ID: 3582575 • Letter: J

Question

JAVA CODE

Create a new Transmit Thread in the ConnectPort class. This Thread should transmit out (send) one character every second over the serial port. The sequence of the characters to be transmitted is ‘a’, ‘b’ ‘c’ … until ‘z’ and then start over from ‘a’ again.

THIS IS THE ORIGINAL TRANSMIT THREAD I BELIEVE...

(If anything i just need the logic to program this)

public int sendMessage(String msg)

{

if (serialPort != null)

{

try{

OutputStream out = serialPort.getOutputStream();

    byte[] b = msg.getBytes("UTF-8");

    out.write(b);

    out.flush();

   

    return 0;

}

catch (Exception serialTxExcep){

serialTxExcep.printStackTrace();

}

}

return -1;

}

Explanation / Answer

We can use getBytes() method which returns each byte serially. So, the logic to accept character sequentially would look like this: OutputStream mOutputToPort = serialPort.getOutputStream(); String mValue = "ABCDEFG.....ZA"; System.out.println("beginning to Write . "); Byte[] data = mValue.getBytes(); for(int i=0;i