Re: Threaded access to serial port under Windows



Thanks for the reply

Maybe you can help with a better design, I am talking to a hardware device
in an async way, I need to have fileevent work without blocking the
execution of the main thread. . The hardware device both responds to our
commands and can also send unsolicited pushes which we must handle

So basically the first thread only does writing and the second thread does
mostly reading.

The way we got that to happen was to do this:

<Main Script is started>
- Spins off read thread that uses fileevent to be notified when data
appears on the serial port, uses thread shared variables to give data back
to main thread

<Test Execution occurs here>

We found fileevent only calls us back when in the event loop.

Thanks,

Jason

It works on Linux and HP-UX beautifully but not Windows because we can't
open the port twice.
"Alexandre Ferrieux" <alexandre.ferrieux@xxxxxxxxx> wrote in message
news:1174517891.574172.55050@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Mar 21, 11:33 pm, "Jason Sheets" <jason.she...@xxxxxx> wrote:
Dear TCL Community,

We are developing a tool that needs to have access to a serial port from
two
threads within TCL.
...
Basically I need read/write access to the serial port in 2 threads on
Windows.

It doesn't make sense to have 'simultaneous r/w access' over a common
channel.
Indeed, there is no automagical muxing/demuxing of requests. Writes
may be randomly interleaved (in which case your data granularity had
better be no larger than one byte), but concurrent reads are
completely uncontrollable (which thread gets what bytes ?)

So I guess you mean that each of your 2 threads, in turn, does a
complete transaction, including a write and a read, and that no
unsollicited event comes down the wire outside the transactions. In
this case you'd better do all your I/O on the channel in thread A, and
when B needs it, delegate to A via normal Tcl interthread
communication.

-Alex



.



Relevant Pages

  • Re: why cant i write to a file with this code?
    ... Can't really say without knowing the format of the data that your hardware device sends through the serial port. ... You are assuming that your readstatement always returns a single chunk, or a packet, from your hardware device. ... The Linux kernel has absolutely no idea, nor does it care, what you have attached to the serial port, and the format of the data you are receiving. ...
    (comp.os.linux.misc)
  • Re: fileevent not working with serial
    ... | I've tried adding the fileevent before and after the proc to no ... Apart from the obvious missing close brace for the proc this should ... serial port is unbuffered and flushed properly. ... set data ...
    (comp.lang.tcl)
  • Re: serial fileevent on fedora core 3
    ... >fileevent with the serial port to communicate with some lab instruments ... After you "puts a command string ...", ...
    (comp.lang.tcl)
  • Re: How to calculate the checksum?
    ... Christian Havel wrote: ... hardware device through the RS232 serial port? ... Do you have some sample data and an expected result to ...
    (microsoft.public.dotnet.languages.csharp)
  • Whats SerialPort can not fire DataReceived event.
    ... I have a C# program can to test serial port communication. ... it is same hardware device and serial port driver, ... using API is ...
    (microsoft.public.dotnet.framework.compactframework)