Announcement

Collapse
No announcement yet.

Sending keyboard entry(string) to host

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

  • Sending keyboard entry(string) to host

    In my ViSi Genie (Pro license) project I configured a simple keyboard for entering an 8 character filename.
    Entering a string and correcting input using a backspace key works fine now. The string is printed on the display correctly.

    Now I would like to send the string containing the filename to my host when the Enter key is pressed.
    I suppose function 'SendReport' should be using for this, however I cannot get it working.
    Here's the code I'm using:

    func rMagicKbClrEvent1(var reportID, var objType, var objHash, var value)
    if((value>=32) && (value<=126) && counter <8) //check of characters are input and if less than 30
    char[counter] := value; //store keyboard value to character array
    putch(char[counter]); //print value
    counter++; //to increment index of array everytime an input from keyboard is received
    else if(value == 8) //check if backspace is pressed
    if(counter) //check if counter is not less than 0
    counter--; //decrement array index
    char[counter] := 0; //store NULL to array
    txt_MoveCursor(lft, col + counter); //Move Cursor to character that will be deleted
    putch('_'); //Replace with Space ' '
    txt_MoveCursor(lft, col + counter); //Move Cursor to replace Space if a character key is pressed
    endif
    else if (value == 13) //check if Enter has been pressed
    SendReport(REPORT_OBJ, tStrings, 62, char) ;
    endif
    endfunc


    Could you help me with this ?

    Regards,
    Bauke

  • #2
    Hi Bauke,

    Now I would like to send the string containing the filename to my host when the Enter key is pressed.
    To send a string to destinations other than the screen, you could use to(outstream),
    e.g.:
    Code:
    to(COMx); //change x to corresponding port
    putch(char);
    For more information on how to use the function, please refer to Diablo16 Internal Functions Manual (page 88-89).

    I suppose function 'SendReport' should be using for this, however I cannot get it working.
    From the ViSi-Genie Reference Manual (page 40), SendReport sends a standard 6 byte report Object or Event packet to the Genie
    Serial port. Hence, you cannot use it to send string data to host controller.

    I hope this helps. Should you have any other inquiry, feel free to ask.

    All the best,
    Sherwin
    Last edited by sherwin4D; 9th September 2019, 07:05 PM.

    Comment


    • #3
      Hi Sherwin,

      Thanks for your clear explanation.
      Function 'putch' works like a charm.

      This is the code that works fine for me:
      Code:
      ... else if (value == 13)    //check if enter has been pressed
              for (i:=0; i<counter; i++)
                  to(COM0);
                  putch(char[i]) ;     // send entered characters to host
              next
              while (i < 8)
                  to(COM0);
                  putch(" ") ;           // add up to 8 characters using spaces
                  i++;
              wend
          endif
      This way I always receive a fixed length result. The spaces can be stripped on the host easily.



      When I looked in the 'Diablo16 Internal Functions Manual' my eye also fell on function 'putstr'(<pointer>)' that seems an even better solution for my purposes, however I cannot get the expected results with it.

      In the 'Const Globals + Routine' event code i defined the pointer to the result string:
      var respchp; // pointer to response string

      and in the 'Post activate form' event:
      respchp := str_Ptr(char);

      But none of these pieces of code do work:
      Code:
      ... else if (value == 13)       //check if enter has been pressed
              putstr(respchp);
      endif
      or:
      Code:
      ... else if (value == 13)       //check if enter has been pressed
              putstr(char);
      endif
      or:
      Code:
      ... else if (value == 13)       //check if enter has been pressed
              putstr(char[0]);
      endif
      and it doesn't work either when I added a line 'char[counter]:='\n'; ' before calling putstr.

      I'm still curious:
      would it be possible to use function 'putstr' for this purpose ? (and how...)

      Regards,
      Bauke

      Comment


      • #4
        I found a bug in my code, by the way:

        Code:
         
         while (i < 8)             to(COM0);             putch(" ") ;           // add up to 8 characters using spaces             i++;         wend
        should be:

        Code:
         
         while (i < 8)             to(COM0);             putch(' ') ;           // add up to 8 characters using spaces             i++;         wend
        Bauke

        Comment


        • #5
          Hi Bauke,

          would it be possible to use function 'putstr' for this purpose?
          As stated on the manual, you could also use putstr() to send string data to host. To test this,
          you could manually send a string, that is:
          Code:
          to(COMx);
          putstr("hello123");
          I hope this helps.

          Best regards,
          Sherwin

          Comment


          • #6
            Hi Sherwin,

            Your example works fine.

            I however would like to send the contents of character array 'char' to the com port using function putstr().

            But none of the following instructions gives the expected results (see also post #3):
            Code:
            putstr(char);
            putstr(char[0]);
            putstr(respchp);
            ...and adding an end-of-string character using 'char[7]:=0;' before calling putstr doesn't make a difference.

            Am I forgetting something or is it not possible to use putstr() for sending character arrays ?

            Thanks,
            Bauke

            Comment


            • #7
              Hi Bauke,

              Am I forgetting something or is it not possible to use putstr() for sending character arrays?
              It's certainly possible to use putstr() for sending character arrays.

              But none of the following instructions gives the expected results (see also post #3)
              As mentioned putstr prints a string.
              This can be done directly by simply using: putstr("Hello");

              If you are to test:
              Code:
              var char[10];
              to(char); putstr("Hello");
              putstr(char);
              This would output "Hello" properly.

              However, if you do this:
              Code:
              var char[10];
              char[0] := 'H';
              char[1] := 'e';
              char[2] := 'l';
              char[3] := 'l';
              char[4] := 'o';
              char[5] := '\0';
              putstr(char);
              This will output "H".

              This is because the code above stores the character (8bits) to a var (16bits).

              That means the line: char[0] := 'H'; actually is similar to char[0] := 'H\0';
              As you can see, the string is immediately terminated after letter H.

              The proper way to compose a string is shown below:
              Code:
              var char[10], ptr;
              ptr := str_Ptr(char);
              
              str_PutByte(ptr++, 'H');
              str_PutByte(ptr++, 'e');
              str_PutByte(ptr++, 'l');
              str_PutByte(ptr++, 'l');
              str_PutByte(ptr++, 'o');
              str_PutByte(ptr, '\0');
              
              putstr(char);
              This should output "Hello" properly.

              Then just add to(COM0); before the putstr(..) command to send it via serial instead of the screen.

              Please have a look at this appnote for more information on how you could store string data into a variable array:
              AN-00193 Designer or ViSi Strings and Character Arrays

              I hope this helps.

              Good luck and best regards,
              Sherwin

              Comment


              • #8
                Hi Sherwin,

                Now the handling of strings is completely clear to me.

                Thanks for your answer,
                Bauke

                Comment

                Working...
                X