Serial Module readLine

I just started testing the serial module and am getting the following error.

Traceback (most recent call last):
File “event:actionPerformed”, line 1, in
java.io.IOException: java.io.IOException: Underlying input stream returned zero bytes
caused by IOException: Underlying input stream returned zero bytes
Ignition v7.5.0 (b1079)
Java: Sun Microsystems Inc. 1.6.0_29

I have a serial analyzer between the device (a scale) and the client and confirmed Port is open, command is sent to scale, scale replies with delimited string.
value = system.serial.readLine(‘COM2’) code is on a command button to make sure there are no timing issues. When command button is clicked, error is thrown. I have tried this on a client with the serial client module and on the server with the serial gateway module. Same error is thrown in both cases.

What is the code you wrote?

value = system.serial.readLine(‘COM1’)
event.source.parent.getComponent(‘Label’).text = value

The developer is looking into it.

I can only replicate this error here when it should legitimately occur, i.e. my serial device on the other end is actually not sending anything.

Tell me more about your setup and show me all of your code, including the lines where you initially configure the serial port. Also tell me about how this serial analyzer works and where it is between the gateway or client and the device.

The analyzer is a comFront rs232 analyzer. Serial comm is based upon input and output buffers with independent timing. It is quite normal to pull from an input buffer sometime (micro to milliseconds to seconds) after data has been placed in the buffer. I believe what you are describing is more of a serial data stream , in which case there is a probability data will be coming into the buffer as readLine is executing. On the other hand, if data has been placed in the buffer, readLine should be able to pull from it at anytime. I’ll give you a call tomorrow.

Did you call system.serial.configureSerialPort() before trying to read from it? If you didn’t, you’re reading with whatever the default settings are, and they’re probably wrong.

system.serial.configureSerialPort is called one a command button. - OPEN
system.serial.write is called one another- WRITE.
system.serial.readLine is called on the third - READ.

test-
click OPEN.
click WRITE, send/receive data verified on analyzer
click READ, error thrown

Baud on the device is set to 2400, I know the config is correct as the analyzer displays the data bidirectionally and I can see the command sent to the scale and the data returned from the scale is correct as expected. It is my understanding the system.serial.configureSerialPort only needs to be called once, perhaps this is the issue.

Yeah, you only need to configure the serial port once.

I’m not really sure why nothing is coming back from readLine(), have you tried this without the analyzer in between?

Put the write and the read in the same button. Your probably not fast enough.

On a side note, here is a window to test serial communications between 2 serial ports on the same computer. I run this inside a VM, but the basic idea is there.
Serial Test 7.5.0.proj (12.5 KB)

I think I need to make some modifications to the serial module today. Right now each system.serial.* call opens the port, does its thing, then closes it. Perhaps data is being lost in between calls because of this…

I’ll add system.serial.setOpen() and system.serial.setClosed() that will be used to open/close the port explicitly instead of doing it implicitly with each call. Then, if you want, you can set it up to configure/open in a startup script and close in a shutdown script. Or if you want more fine-grained control you can open, do your write/read combo, and close.

Sounds like it might be the problem. I was about to recommend explicit open/close calls. It also might be useful to have an port ownership call if possible. I have been writing serial drivers for various devices for about twenty five years and I know how tricky it can be, especially when you factor in platform independence and JAVA.

I’m attaching 1.5.1-beta1 serial support modules that work on the idea that you need to explicitly open the port after configuring it before you can use it. And close it when you’re done.

Adds system.serial.openSerialPort() and system.serial.closeSerialPort().

All read/write calls operate on an already opened port. The input and output streams are created when the port is opened and not thrown away until closed.

If info is still being lost at this point I’ve got no idea where to start trouble-shooting. It could be an unsolvable timing issue. Who knows.
Serial Support Gateway-module.modl (210 KB)
Serial Support Client-module.modl (161 KB)

Works like a champ! The only issue is the call requires the port to be referenced as an argument.
system.serial.openSerialPort(“COM1”) vs system.serial.openSerialPort()
system.serial.closeSerialPort(“COM1”) vs system.serial.closeSerialPort()

Thanks for the prompt attention to fixing this.

[quote=“markdobtech”]Works like a champ! The only issue is the call requires the port to be referenced as an argument.
system.serial.openSerialPort(“COM1”) vs system.serial.openSerialPort()
system.serial.closeSerialPort(“COM1”) vs system.serial.closeSerialPort()

Thanks for the prompt attention to fixing this.[/quote]

Yeah, I omitted that, but it’ll show up in the autocomplete saying you need the port and eventually the user manual.

Glad it’s working now.