Announcement

Collapse
No announcement yet.

Com port and NULL char

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

  • Com port and NULL char

    serout(0) ; is working

    but I can't use : to(COM0); print([CHR] 0) ;

    any idea ?

  • #2


    The print statement expects a string which has an ASCIIZ terminator (0x00) to tell the print statement to stop printing when the end of the string is encountered.. If you wish to send a zero to comms, just use serout(0);
    Regards,
    Dave

    Comment


    • #3


      So this code will never work

      cpt := 0;
      repeat
      print([CHR] cpt) ;
      cpt++ ;
      until (cpt > 10)

      Comment


      • #4


        Not quite sure what you are trying to achieve, the ASCII character set starts at 0x20 (32 decimal) which is a space, followed by ASCII characters '0' , '1' etc. There are only 2 control characters which have any effect below 32, carriage return and line feed (0x0D and ox0A respectively). So if you wanted to print the ASCII number set for instance, you could try this :-

        cpt := 32;
        repeat
        print([CHR] cpt) ;
        cpt++ ;
        until (cpt > 42);
        Regards,
        Dave

        Comment


        • #5


          Hi Meldavia,

          Don't mean to hijack the thread, but many comms protocols are not Ascii / terminator char based, but binary / Message based. For example, my company uses a protocol with a message structure of:

          STX BCH BCL CMD BODY CS ETX

          where STX is Hex 0x02, ETX is Hex 0x03, and bytes in the body can be values from 0x00 to 0xFF.
          _______________
          Best Regards,
          Howard

          Comment


          • #6


            The print statement only prints the ASCII character set, and if redirection to COM port is used, it just prints what it would otherwise print on the screen which is the 96 available characters from 0x20 up to 0x7F. The serout(n); function is for raw unadorned comms output. The print statement can be used in conjuction though , eg:-
            serout(STX); //start of text
            serout(5); //count of text characters to follow
            to(COM0); print"(HELLO"); // body of text
            serout(0); //terminator
            serout(ETX); //end of text
            serout(EOT); // end of transmission

            A better method would be to make a function that outputs a buffer using serout(n); in a loop.

            btw, due to internal limitations, when [CHR] is used within a print statement which is redirected to COM0, all values except 0 can be sent.
            Regards,
            Dave

            Comment

            Working...
            X