Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Comm Module Comm_Recv

  1. #1

    Comm Module Comm_Recv

    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



  2. #2
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: Comm Module Comm_Recv

    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

  3. #3

    Re: Comm Module Comm_Recv

    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

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Comm Module Comm_Recv

    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

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Comm Module Comm_Recv

    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

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Comm Module Comm_Recv

    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

  7. #7

    Re: Comm Module Comm_Recv

    Petr & Eros

    Thank you ;D both for your replies, Petr will give your function a go and let you know the results.

    Regards

    Gerry

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Comm Module Comm_Recv

    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

  9. #9
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: Comm Module Comm_Recv

    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

  10. #10

    Re: Comm Module Comm_Recv

    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

Page 1 of 2 12 LastLast

Similar Threads

  1. COMM Module?
    By Lee Allen in forum COMM (Serial communication)
    Replies: 5
    Last Post: 24-03-2007, 19:21

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •