Announcement

Collapse
No announcement yet.

Keyboard Object Question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bigtim
    replied
    Thanks Eran, as ever that's very useful information.

    I don't think I am recursively calling any functions but certainly worth bearing in mind. In my test mode I am declaring a lot of big arrays and the problem occurred when I tried to initialise another 150bytes within my magicObject code. I did move these out to the glabal variables area as I wil need them in other parts of the code and cut back on some of the silly initialisations I was doing and this seemed to help.

    Useful to know I can increase the stack size though

    Thanks again

    Leave a comment:


  • Eran
    replied
    Hi Tim,

    Stack Overflow usually happens when you’re calling functions recursively without returning.

    You may take a look at these forum threads for more information about stack overflow.
    https://forum.4dsystems.com.au/forum...o-15#post43996
    https://forum.4dsystems.com.au/forum...2057#post22057
    https://forum.4dsystems.com.au/forum...rflow#post4458
    https://forum.4dsystems.com.au/forum...0468#post60468

    You may also change the Stack Size and see if the error’s still there.

    https://forum.4dsystems.com.au/forum...tion#post46574

    If the stack overflow still gets to be an issue, I recommend that you execute your code part-by-part and determine which part results to the error so debugging will be much easier.

    Best Regards,
    Eran

    Leave a comment:


  • Bigtim
    replied
    Hi Eran, made good progress today thanks to your help with the comms

    Is there a limit to the number of bytes of memory that can be allocated to variables? I ran into a stack overflow error today which was only solved when I reduced the number of bytes of memory I am allocating in my variables section. The good news is that now the comms are nice an slick I won't need to download massive chunks of data but it did alarm me. On compilation the message tells me I am using around 14K (of the 32K) available so far so I though I had plenty of head room left.

    Leave a comment:


  • Bigtim
    replied
    Eran, that's perfect. Tested and working perfectly. What a dope Thank you again for the amazing help and support!

    Leave a comment:


  • Eran
    replied
    Hi Tim,

    You’re missing an acknowledgment in your magicObject code. You can add the line serout(ACK) ; at the end of your magicObject code. This is an acknowledgment from the display to the Arduino that the Display is done receiving data from the Arduino.

    You can choose either way you want and can always ask for clarifications.

    *Please have a look at the modified version of your magicObject code:


    Code:
    func rMagicObject0(var action, var object, var newVal, var *ptr)
        var  i;
    
        print([CHR]newVal);
        print("\n");
    
        for (i:=0; i<newVal;i++)
          print([CHR]ptr[i]);
        next
    
        print("\n");
    
        serout(ACK) ;    // send back an ACK to command, do this last, otherwise the master may send the
                             // next command which is cannot be started until this is finished.
    
    endfunc
    Thanks and I hope this helps,

    Eran

    Leave a comment:


  • Bigtim
    replied
    Hi Eran, using the WriteObject method I created a loop and sent my string one character at a time. It works and is generally a bit faster than the WriteMagicBytes option. Before I decide on a final direction, it would be really good to know if I am doing something wrong with WriteMagicBytes, the fact it works instantly on the first attempt but is then delayed is really frustrating

    Leave a comment:


  • Bigtim
    replied
    hmmm, can't seem to find a way of transmitting a string of 25 bytes to from the Arduino to the display without using WriteMagicBytes which seems slow. I have attached my code and Arduino project would you be able to take a look and see if there is a way of overcoming this delay in the comms?

    At the moment all I am doing with the magic bytes is printing them out. The message is triggered when EDIT DATA and LABELS1 buttons are pressed from the main menu (none of the other buttons on the edit data screen are coded up yet )

    What's really intriguing about the
    WriteMagicBytes issue is that it works instantly the first time after the screen boots, its only subsequent messages that appear slow? How can this be?
    Attached Files
    Last edited by Bigtim; 12th May 2018, 09:10 PM.

    Leave a comment:


  • Bigtim
    replied
    Hi Eran, these examples run very smoothly and the reporting back of the x is instant.

    So are we saying that to write back my message to the display It would be better to use genie.WriteObject rather than
    genie.WriteMagicBytes? With the genie writeObject command is it ok to send a string 25 characters long?


    genie.WriteObject(34, 0, 'XXXXXX');
    Last edited by Bigtim; 12th May 2018, 08:12 PM.

    Leave a comment:


  • Bigtim
    replied
    Hi Eran, thanks I will give these a try and report back

    Leave a comment:


  • Eran
    replied
    Hi Tim,

    Please try the attached examples:
    Version 1 uses a magicObject. A winbutton is used first to report a message to the Arduino. The Arduino then sends a Write Object function to the display to trigger the magicObject as the object sends back the current button’s number to the Arduino.
    Version 2 doesn’t use a magicObject but utilizes the seroutCS functions to send bytes to the host. A winbutton directly sends the current button’s number to the Arduino.

    Please open Arduino’s Serial Monitor while testing and wait for the “Waiting…” prompt.

    You can always ask for clarifications about the examples Tim.

    Hope this helps and best regards,
    Eran
    Attached Files

    Leave a comment:


  • Bigtim
    replied
    And another

    So I now have communication working in both directions. Just one issue, when I send 25 magic bytes from the Arduino, there is a delay of around 1 second before the display handles them.

    I am sending

    genie.WriteMagicBytes(0, sendArray, sendArrayLength);

    and I have this code in my magicObject function

    Code:
    func rMagicObject0(var action, var object, var newVal, var *ptr)
    
        var  i;
    
        for (i:=0; i<newVal;i++)
          print([CHR]ptr[i]);
        next
    
        print("\n");
    So in theory not much happening.

    Oddly the very first attempt after the screen boots up is very fast, but subsequent messages suffer the delay. Is this my code or is the magicObject function only serviced every second or so?



    Leave a comment:


  • Bigtim
    replied
    Sorry Eran, another damn question.

    I am trying to get a form with two buttons on it to call a common MagicEvent and use the newval variable to tell me which of the buttons called the event. I thought I had done this previously but can't seem to make it work this morning. Am I going mad or is this not possible?

    Leave a comment:


  • Bigtim
    replied
    Hi Eran, hope you are well


    Quick question if I may

    Thanks to your help I am now able to send magic bytes from my Arduino and receive them in the display.

    Today's task is to get the display to send some bytes to the Arduino. In basic terms when I hit a button on one of my forms, I want to send an array of 6 bytes to the Arduino. I'm assuming the format would be something like this (but obviously extended to 6 bytes):

    seroutCS(REPORT_MAGIC_EVENT_BYTES) ; // we report in bytes
    seroutCS(object) ; // report object ID
    seroutCS(2) ; // two bytes following
    seroutCS(x) ; // write x as a byte
    seroutCS(y) ; // write y as a byte
    seroutOcs () ; // write out checksum


    Can I use this Report Magic Bytes function from any magic code block or can this only be sent from a MagicObject code block?

    Edit: seems to work fine when I call that code from a MagicEvent block of code
    Last edited by Bigtim; 11th May 2018, 09:23 PM.

    Leave a comment:


  • Eran
    replied
    Hi Tim,

    Glad to hear that you have managed to implement it on your own and that you’re enjoying magicBytes.

    If you still have questions then don’t hesitate to ask them.

    All the best for your project!

    Best Regards,
    Eran

    Leave a comment:


  • Bigtim
    replied
    Eran, ignore my last couple of posts I managed to work through sending magicBytes from the Arduino using the genieArduino library. It seems to be working perfectly.

    Just need to work out how to send messages back to the Arduino (ReportMagicBytes?) and I think we have cracked it

    Leave a comment:

Working...
X