Welcome to thinbasic Gerry.
If you look at the example in the samplescript directory it uses a delay.
good luck
Hi
Just started using thinbasic to communicate with an oled display connected through a serial port.When a command is sent to the display, if everything is ok, it carries out the command and responds with an ACK(&h06).I have tried to use the COMM_RECV to catch this but without success.It seems as if COMM_RECV does not wait for the character to be received.The problem is that the next command is sent and the display hangs up. I've worked around this for now by including a delay but was just wondering if I am missing something ?
Basic code is
Comm_Send(hComm, "command" & chr$(val1) & chr$(val2) & etc)
NBytes = COMM_Get(hComm, %COMM_RXQUE)
COMM_Recv(hComm, NBytes, VariableBuffer)
Regards
Gerry
Welcome to thinbasic Gerry.
If you look at the example in the samplescript directory it uses a delay.
good luck
Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370
Hi Abraxas
Thank you for your reply.The reason I asked the question is that the help section for COMM-RECV states "Program execution will halt until NBytes bytes are available" so this suggests there should be no need for a time delay ?
Regards
Gerry
Hi GKeely,
maybe there is a typo in docs, I am sure Eros will correct it.
To wait until right number of bytes arrive you could maybe use something like:
[code=thinbasic]
' -- Wait till we get number of bytes we want
while COMM_Get(hComm, %comm_RXQUE) <> NumberOfBytesWeWant
Sleep 0 ' -- To not hog CPU
wend
' -- Now we got the bytes we need so we can process them
[/code]
Bye,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Or maybe use following function:
[code=thinbasic]
function WaitForNBytesWithTimeout( cHandle as long, wantedBytes as long, timeOutInMS as long ) as long
local timeStart as long = GetTickCount
Local ReturnValue as long = 1
while GetTickCount-timeStart < timeOutInMS
if COMM_Get(cHandle, %comm_RXQUE) = wantedBytes then
ReturnValue = 0
exit while
end if
wend
function = ReturnValue
end function
[/code]
Returns 1 if timeouted, 0 if number of requested bytes is ready
Or something like that, did not had opportunity to test the code in real battle
Bye,
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Ciao Gerry and welcome here.
COMM RECV should halt execution until requested number of bytes are present in the queue.
As Petr suggested, use COMM_Get(hComm, %comm_RXQUE) to check the size of the queue before using COMM RECV, than get the bytes and check if return buffer is what you expect.
I've checked thinBasic_COMM.dll source code module and it should work as expected.
Function WaitForNBytesWithTimeout suggested by Petr should do the job. Maybe passing one more param (BYREF sBuff AS STRING) can be used to return the queue buffer once the size is what expected. Maybe I can add this function as native COMM module function.
Let me know. If you still have problems I will check deeply in source code.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Petr & Eros
Thank you ;D both for your replies, Petr will give your function a go and let you know the results.
Regards
Gerry
Gerry,
if you can, it would be nice for us to see a picture of your oled display.
Maybe better if working with thinBasic script
Thanks a lot.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Gerry sounds like a cool project. Eros beat me to the request, but would love to see photos or even a video clip of it working! Good luck and looking forward to being WOW'd.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Thanks to all for your support
It turns out that the COMM_RECV works correctly and that a time delay is necessary after all. ???
I'm not using the OLED for anything particular but just thought that controlling it from a PC would be fun(like using a sledgehammer to crack a nut).Hopefully I can get an image to you later,i don't have a camera available.Thanks again and now back to studying more of thinbasic.
For those interested details of the display are here
http://www.4dsystems.com.au/prod.php?id=11
regards
Gerry
Bookmarks