Reading com port

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading com port

Louis LaBrunda
Hi Everyone,

Happy New Year.

I need to read from a com port.  I am able to use:

deviceFile := CfsFileDescriptor openReadOnly: 'COM3'.
buffer := String new: 200.
readCount := deviceFile read: buffer startingAt: 1 nbyte: 200.

I have obviously some flow control code but the above code does read bytes.  The problem is if there isn't any data to read it seems to block the VM.

Does anyone have any idea how I can see/peek ahead and not try to read until I know there is data present?

Big picture:  There is a program called SimpleSat that tracks satellites.  It can be setup to output control information that can be used to aim an antenna at the satellite.  I'm trying to capture that data and convert it to control a different device to move the antenna.  To do this I am using com0com to setup a pair of virtual 
com ports where SimpleSat sends data to one side and another program (mine) can read from the other port of the pair.  This seems to work other than the VM blocking problem because I don't know when data is present.

All ideas are welcome.

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reading com port

Louis LaBrunda
Hi Everyone,

Happy New Year.

The problem is solved by defining and setting an instance of: OSCommtimeouts.  Something like this:

commTimeouts := OSCommtimeouts new.
commTimeouts ReadIntervalTimeout: 50; ReadTotalTimeoutConstant: 50; ReadTotalTimeoutMultiplier: 10.
deviceFile := CfsFileDescriptor openReadOnly: 'COM3'.
deviceFile fileDescriptor setCommTimeouts: commTimeouts.


or this:

commTimeouts := OSCommtimeouts new.
commTimeouts ReadIntervalTimeout: PlatformConstants::Maxdword; ReadTotalTimeoutConstant: 0; ReadTotalTimeoutMultiplier: 0.
deviceFile := CfsFileDescriptor openReadOnly: 'COM3'.
deviceFile fileDescriptor setCommTimeouts: commTimeouts.


Both result in the read returning with 0 bytes read when no data is present.  The rest is easy.

Lou


On Monday, December 31, 2018 at 11:38:01 AM UTC-5, Louis LaBrunda wrote:
Hi Everyone,

Happy New Year.

I need to read from a com port.  I am able to use:

deviceFile := CfsFileDescriptor openReadOnly: 'COM3'.
buffer := String new: 200.
readCount := deviceFile read: buffer startingAt: 1 nbyte: 200.

I have obviously some flow control code but the above code does read bytes.  The problem is if there isn't any data to read it seems to block the VM.

Does anyone have any idea how I can see/peek ahead and not try to read until I know there is data present?

Big picture:  There is a program called SimpleSat that tracks satellites.  It can be setup to output control information that can be used to aim an antenna at the satellite.  I'm trying to capture that data and convert it to control a different device to move the antenna.  To do this I am using <a href="https://sourceforge.net/projects/com0com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fsourceforge.net%2Fprojects%2Fcom0com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF1oBzdCk1CztF30KQhprxWy_TcaA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fsourceforge.net%2Fprojects%2Fcom0com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF1oBzdCk1CztF30KQhprxWy_TcaA&#39;;return true;">com0com to setup a pair of virtual 
com ports where SimpleSat sends data to one side and another program (mine) can read from the other port of the pair.  This seems to work other than the VM blocking problem because I don't know when data is present.

All ideas are welcome.

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reading com port

Louis LaBrunda
Sorry, I messed up the link.  This should work:

OSCommtimeouts

Lou


On Tuesday, January 1, 2019 at 3:26:19 PM UTC-5, Louis LaBrunda wrote:
Hi Everyone,

Happy New Year.

The problem is solved by defining and setting an instance of: <a href="https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_commtimeouts:" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fdesktop%2Fapi%2Fwinbase%2Fns-winbase-_commtimeouts%3A\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFaA3LFx-tp-Szzlo3kHH8kLbvJmQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fwindows%2Fdesktop%2Fapi%2Fwinbase%2Fns-winbase-_commtimeouts%3A\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFaA3LFx-tp-Szzlo3kHH8kLbvJmQ&#39;;return true;">OSCommtimeouts.  Something like this:

commTimeouts := OSCommtimeouts new.
commTimeouts ReadIntervalTimeout: 50; ReadTotalTimeoutConstant: 50; ReadTotalTimeoutMultiplier: 10.
deviceFile := CfsFileDescriptor openReadOnly: 'COM3'.
deviceFile fileDescriptor setCommTimeouts: commTimeouts.


or this:

commTimeouts := OSCommtimeouts new.
commTimeouts ReadIntervalTimeout: PlatformConstants::Maxdword; ReadTotalTimeoutConstant: 0; ReadTotalTimeoutMultiplier: 0.
deviceFile := CfsFileDescriptor openReadOnly: 'COM3'.
deviceFile fileDescriptor setCommTimeouts: commTimeouts.


Both result in the read returning with 0 bytes read when no data is present.  The rest is easy.

Lou


On Monday, December 31, 2018 at 11:38:01 AM UTC-5, Louis LaBrunda wrote:
Hi Everyone,

Happy New Year.

I need to read from a com port.  I am able to use:

deviceFile := CfsFileDescriptor openReadOnly: 'COM3'.
buffer := String new: 200.
readCount := deviceFile read: buffer startingAt: 1 nbyte: 200.

I have obviously some flow control code but the above code does read bytes.  The problem is if there isn't any data to read it seems to block the VM.

Does anyone have any idea how I can see/peek ahead and not try to read until I know there is data present?

Big picture:  There is a program called SimpleSat that tracks satellites.  It can be setup to output control information that can be used to aim an antenna at the satellite.  I'm trying to capture that data and convert it to control a different device to move the antenna.  To do this I am using <a href="https://sourceforge.net/projects/com0com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fsourceforge.net%2Fprojects%2Fcom0com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF1oBzdCk1CztF30KQhprxWy_TcaA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fsourceforge.net%2Fprojects%2Fcom0com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF1oBzdCk1CztF30KQhprxWy_TcaA&#39;;return true;">com0com to setup a pair of virtual 
com ports where SimpleSat sends data to one side and another program (mine) can read from the other port of the pair.  This seems to work other than the VM blocking problem because I don't know when data is present.

All ideas are welcome.

Lou

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.