No announcement yet.

Keyboard Object Question

  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Eran, whilst we are both awake

    Is there something fundamentally wrong with this:

    if (serialStatus == 1)


    while (com_Count())
    str_PutByte(comHoldingBufferPointer + inputCount ,serin());

    if (inputCount>0)
    print ([STR]comHoldingBuffer);


    Its almost working but when I send a string of say 4 characters, its very hit and miss as to the results that get printed. One in 10 times it gets the right 4 characters, most of the time it gets 2 or 3


    • #32
      Well I have made some progress today thanks to the links you sent me Eran, thanks for that

      Still two issues:

      1) the issue of whether I can use genie Arduino AND my own messages through the same com port.
      2) I have an issue with occasionally missing characters that are being sent.

      This is the code I am using to read the serial port:

      if (serialStatus == 1)
          while (com_Count())
                  inputCh:= serin();
                  str_PutByte(comHoldingBufferPointer + inputCount ,inputCh);
          if (inputCh ==32)
              str_PutByte(comHoldingBufferPointer + inputCount ,3);
              //print ([STR]comHoldingBuffer);
              ANSI2Uni(str_Ptr(comHoldingBuffer),outBuffer) ;
      For now I am just using a <SPACE> character to terminate my message

      The above code is positioned in my main loop and it works, but every third or fourth message a character is being missed. I have a buffer set up in my post_gene_init insert point

      com_Init(comBuffer, 128, 0);                                         // Setup COM0
      com_SetBaud(COM0, 960);
      If I uncomment the repeat forever lines in the code above then everyting is very stable. But of course nothing else in the project works (I'm stuck on this screen)

      It appears as if when I don't force the programme to stay permanently looking at the com port then the display misses inputs at the comm port when it is off doing other things? At first I thought it was the size of my project (lots of other forms and buttons) but even if I strip the project back to this form alone, then I get the same problem.

      I thought that using buffered comms would avoid this?

      Is there a way around the issue? or a way to improve my code or locate it somewhere different such that I stop dropping these crucial parts of my message?


      • #33
        Hi Tim,

        A very useful example from this post can help you to make Magic object work. It uses a MagicHandler function on the Arduino side.

        To communicate properly, the Arduino and the Display should run simultaneously and in sync with each other. This means that any delay or unrelated routines from either side may cause an unusual behavior to the other.

        You mentioned that the characters are missed when the display is not “looking” at the messages from the Arduino, and that is normal. The display won’t be “seeing” those messages for it is “looking away” while a message is being sent. By default, the Visi-Genie program uses COM0 for other things to communicate with the Arduino, so it is not really advisable to use the default Serial port of the display in this case. When the display is “looking away”, it is actually still communicating with the Arduino but doing things other than what you want it to look at. This means that when the display returns to looking at your messages again, one or two characters have already been sent but not noticed by the display. I hope you’re getting the picture, Tim.

        You can review the Magic code that I just sent you to know how to configure a serial port on the display side other than the default one.

        You can post your code (both sides) so I can simulate and help you debug for errors. Of course, that’s after you read the link that I just mentioned and decide on which course to take.

        Best Regards,


        • #34
          Hi Eran, I'll take a look at the MagicHandler option. Do you think that because this uses the integrated display functions that fewer bytes will get 'lost/missed'?
          I think I noticed that the example that in the Arduino sketch the author is using a software serial out, do you know if in this project the software serial out was connected to Com0 or Com1 on the display? In the display code the author uses seroutCS is this a picaso command, I couldn't find it in the diablo reference?

          The good news is that whilst in version 1 of my device I don't have a access to a spare com port (either hardware or software) a) in future production runs I could b) In normal running mode there is not heavy traffic between the two devices, its only on start up and when the user is programming the controller that we need to be able to communicate.

          Just out of interest, I have attached a couple of photos of what we are building. As you can see we should have researched a software com port because now we committed this PCB adding one would be a pain

          Click image for larger version  Name:	20180208_145750.jpg Views:	4 Size:	2.51 MB ID:	63254 Click image for larger version  Name:	IMG_7485.JPG Views:	3 Size:	2.19 MB ID:	63255

          Last edited by Bigtim; 4 May 2018, 07:05 PM.


          • #35
            Hi Tim, those photos look promising!

            If you still need additional sample codes for the magic object, you can also take a glimpse of the sample under File>Samples>ViSi Genie Magic (Picaso/Diablo)>FileAccess.

            I'll wait for the results of your implementation with Magic Handler. Don’t hesitate to ask in case you encounter problems.

            Best Regards,


            • #36
              Hi Eran, the magic bytes method, looks very promising because:

              a) it uses the genie Arduino library which solves my first problem I think.
              b) Hopefully it will not suffer the same 'drop out' problem even though I am hooked up to com0 because it is using the displays internal routines to handle the COMMS.

              I am struggling a little to get my head around the example. Do you think it would be possible for you to build me a small demo that sends the message "Hello Arduino" when a button is pressed on the delay, receive this in the Arduino and have the Arduino send back a string (via magic bytes) to the display saying "Hi Display"

              I think if I can get those basics down, this might be the way to go.

              Thanks again for the help



              • #37
                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


                • #38
                  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,


                  • #39
                    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; 11 May 2018, 08:23 PM.


                    • #40
                      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?


                      • #41
                        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

                        func rMagicObject0(var action, var object, var newVal, var *ptr)
                            var  i;
                            for (i:=0; i<newVal;i++)
                        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?


                        • #42
                          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,
                          Attached Files


                          • #43
                            Hi Eran, thanks I will give these a try and report back


                            • #44
                              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; 12 May 2018, 07:12 PM.


                              • #45
                                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; 12 May 2018, 08:10 PM.