tobias_hofer has asked for the wisdom of the Perl Monks concerning the following question:
I am developing a perl module which shall communicate by rs232 with a micro controller. The communication is done by threads and thread::queues.
Messages I want to send are put into a queue. A thread is taking messages from the queue and sends them onto the RS232 by a handle to the RS232 Win32::SerialPort object.
The same approach I do for receving rs232 stuff.
Once the receive thread got something on the rs232, the thread puts it into the receive queue. In the main thread I will handle all the received messages and send new messages.
My problem occurs on shutdown. I am not able to end the read thread as it is blocked by a call to
So I changed to "background read"my ($receivedBytes, $data) = $HandleToRS232->read();
Doing this I got nothing in $data so I did a call tomy ($receivedBytes, $data) = $HandleToRS232->read_bg();
Then I receive the message in the $string_in variable, but the call to read_done is also blocking.my($done, $count_in, $string_in) = $HandleToRS232->read_done(1);
I have read the doc. in the Win32::SerialPort and have come to give a try with the API from Win32API::CommPort.
There is a API for receiving with timeout (I need this timeout so I can end the thread). This API is based on the ReadFile API.
However, I do not get this API working properly. I did the following:
my ($result) = Win32API::CommPort::ReadFile( $HandleToRS232,$data,$NumberOfBytesToRead, $ActualReadBytes,$template);
Any help is very welcome!
Best regards!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Threaded RS232 communication
by BrowserUk (Patriarch) on Jan 30, 2013 at 10:48 UTC | |
by tobias_hofer (Friar) on Jan 30, 2013 at 13:48 UTC | |
|
Re: Threaded RS232 communication
by locked_user sundialsvc4 (Abbot) on Jan 31, 2013 at 22:56 UTC | |
by tobias_hofer (Friar) on Feb 01, 2013 at 09:36 UTC | |
by BrowserUk (Patriarch) on Feb 01, 2013 at 10:13 UTC | |
by tobias_hofer (Friar) on Feb 01, 2013 at 11:53 UTC | |
by BrowserUk (Patriarch) on Feb 01, 2013 at 12:56 UTC | |
|