Hi all,
Busy writing code to control a GPIB bus over a serial port and for the most part works reasonably.
While I have all the Serial port stuff happening one feature that I really need is to know when the UART TX Buffer is empty. IE so can know a full string was sent out the port before making an attempt to write the next string. Responses from devices on the GPIB bus have varying latency and in some cases don't like commands being sent one after the other in quick succession. I could just use timed events but gets messy and really not that efficient.
Having a means to know when the Transmission was complete would be useful. Ploughing around I found reference to this, can be found in a few places related to Java but not on Processing site.
public void serialEvent(SerialPortEvent event)
{
switch (event.getEventType())
{
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
// we get here if data has been received
byte[] readBuffer = new byte[20];
try
{
// read data
while (inputStream.available() > 0)
{
int numBytes = inputStream.read(readBuffer);
}
// print data
String result = new String(readBuffer);
System.out.println("Read: "+result);
} catch (IOException e) {}
break;
}
{
switch (event.getEventType())
{
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
// we get here if data has been received
byte[] readBuffer = new byte[20];
try
{
// read data
while (inputStream.available() > 0)
{
int numBytes = inputStream.read(readBuffer);
}
// print data
String result = new String(readBuffer);
System.out.println("Read: "+result);
} catch (IOException e) {}
break;
}
Seems to have lots of juicy features but seems to be only usable from JAVA directly. Guess I don't understand how to use this but thats why I like processing, I don't have to fully understand and still get a lot of return for the effort.
Reading assorted peoples questions on the forum seems the sorts of things people ask for is here, but not accessible from the Serial library in processing. Especially things like knowing a framing error happened when an Arduino is slightly off frequency or even implementing hardware handshaking.
Has anyone included the above sort of serial events within processing and got it working?
Thanks
Stefan
1