comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: serial.dll for serial port under IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: serial.dll for serial port under IDL [message #63027 is a reply to message #62971] Fri, 24 October 2008 09:10 Go to previous message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
Peter sent some test code to me and I was able to reproduce the problem.
It turns out that the issue is that IDL is "too fast" in that if you
write and then immediately read, IDL polls the serial port before
anything is in the serial port buffer. For small amounts of data this
means that you'll see nothing as Peter did. For large amounts of data
it means that you will not see all of the data. For example, sending
4000 bytes of data and immediately reading results in (on my machine)
only 3984 bytes being returned. If you insert a pause between the write
and the read (wait, 0.1) you will Rx all 4000 bytes.

The issue is a bit more complicated than I have presented since you
never get those last few bytes even if you call comm_read again. In my
case I should have 16 more bytes lying around but subsequent calls yield
nothing. So the question is, is this a result of a freak timing issue
that only comes up when you're looping back? Or is there a bug in the .dlm?

I'm leaning toward the prior but I don't know. I do know that if you
are providing you're own buffer to comm_read it better be the same size
or smaller than the serial port buffer or you get some weird results.

Post your results Peter.

-Rick




; test program for serial port reader
; NOTE: you MUST set the COM port number correctly first time or code
crashes
;
portstring='COM3'
print,'Trying to open ',portstring
handle=comm_open(portstring,DATA=8,BAUD=4800,STOP=1,PARITY=' N',mode=3)
print,'handle from OPEN=',handle
;--------- WRITE
data=byte('6b')
h=comm_write(handle,data)
print,'Result of write : ',h
;--------- READ
buf = bytarr(5)
h=comm_read(handle,BUFFER=buf)
print,'Result of read : ',h
print,'Buffer read: ',buf
;--------- CLOSE -------------
res=comm_close(/all)
print,'result of comm_close command:',res
end





Rick Towler wrote:
>
>
> peter.thejll@gmail.com wrote:
>> Hi, Thanks for your suggestions.
>>
>> On Oct 20, 8:19 pm, Rick Towler <rick.tow...@nomail.noaa.gov> wrote:
>>> Are you sure the serial dlm isn't working?
>>
>> No.
>>
>>> Isolate the issue by doing a
>>> loopback test. Simply short pins 2 and 3 of the DB9 connector as
>>> described here:
>>>
>>> http://zone.ni.com/devzone/cda/tut/p/id/3450
>>>
>>> Then write a simple program in IDL that sends some data then reads it.
>>> Once you can send data to yourself then connect up the external devices
>>> and try to communicate with them.
>>
>> Good idea! I am not much for soldering though - is the cable you
>> describe a 'null-modem cable'? I have one of those.
>
> No soldering required. You can use a paper clip :). That null modem
> cable should have female connectors at both ends so you can plug one end
> into your computer then short pins 2-3 at the other end of the cable.
>
> Use Hyperterm to test your cable as described on that same webpage I
> linked above. Once you know your cable is working then you can try IDL.
> The test in IDL will be as simple as this:
>
> IDL> h=comm_open('COM1',BAUD=9600,DATA=8,MODE=3,PARITY='N',STOP=1 )
> IDL> b=comm_write(h,'This is a test')
> IDL> data=comm_read(h)
> IDL> print, data
> 84 104 105 115 32 105 115 32 97 32 116 101 115 116
> IDL> print, string(data)
> This is a test
>
>
> It looks as if the original .dll was built for IDL 5.6. I just
> recompiled it for 6.4 for the test above. The issue might simply be
> that you need to recompile. I know you're working with 6.3, but I'll
> send you the .dll I just compiled and you can try that.
>
> -Rick
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: PLOTS in different windows with different RANGE
Next Topic: Surface Normals

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:52:55 PDT 2025

Total time taken to generate the page: 0.00382 seconds