Announcement

Collapse
No announcement yet.

Protocol for communicating with a visi system via the terminal (uOLED-160-G2)

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

  • Micropointe
    replied
    Hello,

    Again and again me ...

    I realized the connection between my screen and Arduino Mega.

    After much difficulty validating communication ... Everything works!
    Moreover, there is an error in the documentation "4D-AN-00092_R_1_0"
    => In the "Connection Using Jumper Wires" section, must not reverse the RX / TX!

    Then here is the code I use on the Arduino:

    Code:
    #define DisplaySerial Serial1
    #define MySerial Serial
    
    //----------------------------------------------------------------------
    #include <SoftwareSerial.h>
    
    //-------GOLDELOX DISPLAYS-------
    // /*
    #include <Goldelox_Const4D.h>
    #include <Goldelox_Const4DSerial.h>
    #include <Goldelox_Serial_4DLib.h>
    #include <Goldelox_Types4D.h>
    
    //use DisplaySerial to communicate with the display.
    Goldelox_Serial_4DLib Display(&DisplaySerial);
    
    }
    
    void setup()
    {
    
    pinMode(13,OUTPUT);
    pinMode(RESETLINE, OUTPUT); // Set D2 on Arduino to Output
    digitalWrite(2, LOW);         // Reset the Display via D2
    delay(100);
    digitalWrite(2, HIGH);         // unReset the Display via D2
    delay(5000);                // Wait a start
    
    SoftwareSerial
    
    //start Serial
    MySerial.begin(9600) ;         // Debug serial arduino
    DisplaySerial.begin(9600); // Serial to com screen 4D
    
    Display.gfx_Cls(); // Clear Screen
    }
    void loop()
    {
    int TempEXT        // Temperature exterior
    
    TempEXT=1223;
    
    DisplaySerial.write('S0002');            // Change Screen
    delay(1000);
    DisplaySerial.write('T' && TempEXT);    // Test temperature
    delay(1000);
    }
    Then my sreen code:

    Code:
    #platform "GOLDELOX"
    
    #inherit "4DGL_16bitColours.fnc"
    
    var combuf[4] ;
    func main()
    /*
        putstr("Mounting...\n");
        if (!file_Mount()) // mount the uSD
            while(!file_Mount())
                putstr("Drive not mounted...");
                pause(200);
                gfx_Cls();
                pause(200);
            wend
        endif
    */
    
        // Déclaration
        var n, p, i;
        var cmd;        // => Last charactere read
        var numx1;        // => Gear
        var numx2;        // => Engine temperature
        var numx3;        // => Time
        var numx4;        // => Ambient temperature
        var numx5;        // => Atmo. pressure
        var numx7;        // => N° screen
    
        setbaud(BAUD_9600);                             // 9600 baud rate
        com_Init(combuf,8,0);           // <--- set comms buffer so com_Count can work
    
        // Defaut value var
     //   ActualScreen := 1;                                // Screen n°1 by defaut at start
    
    
        repeat                                                  // loop
    
            if (com_Count() >= 3)                        // <--- send 3 characters ("Gxx", "Txx", ...) for this version
    
                cmd := serin ();                              // get a character (or -1 if nothing there)
    
                if (cmd == 'G')                                  // if cmd = G = gear engaged  (format "0" )
                    numx1 := serin() << 8 | serin() ;     // depending on endianness of sent integer
    
                else if (cmd == 'J')
    
                else if (cmd == 'T')                    // if cmd = T = Engine temperature  (format "000.0")
                    numx3 := serin() << 8 | serin() ;     // depending on endianness of sent integer
                    putstr(numx3);
                    
                else if (cmd == 'H')                    // if cmd = H = Time (HH MM) (format "00" & "00")
    
                else if (cmd == 'A')                    // if cmd = A = Ambient temperature (format "00.0")
    
                else if (cmd == 'P')                    // if cmd = P = Atmo. pressure (format "0000")
    
                else if (cmd == 'S')                    // if cmd = S = Screen change demand (format "0")
                    numx7 := serin() << 8 | serin() ;     // depending on endianness of sent integer
                    putstr(numx7);
     //               ChangeScreen (var nS)          // Call function screen change
    
                endif
    
            endif
    
        forever
    
    endfunc

    Here is my problem, when the Arduino sends the command "DisplaySerial.write ('S0002');"

    I The display shows the value 12586!
    As the display shows the value so it is that I got into the "If" so the 'S' has been recognized but why this value?

    When do you?

    Leave a comment:


  • ESPsupport
    replied
    Have you had a 'quick' read of the 4DGL Programmers Reference Manual? It should give you plenty of hints.

    It is installed with Workshop

    Pressing F1 with the cursor on an 'internal 4DGL function' and pressing F1 will bring up the '4DGL internal functions manual' at the page for that function.

    If the cursor is on a 4DGL type programming construct (eg func, endfunc, #inherit) the "4DGL Programmers Reference Manual" will be opened instead.

    The problem with serial communication is that it is really bigger than Ben Hur, there are just so many different possibilities that have been developed over the years (RS232, from where most of these possibilities descend was first documented in 1962, and I'm sure it actually predates that by a few years).

    I've never seen any 'simple' discussion on the net and the size and complexity might be the reason why

    Leave a comment:


  • Micropointe
    replied

    My mistake was simply to confuse "send HEX" and sends character with the window left (ASCII).
    When I wanted to send in 1223:
    I tapped on the keyboard "1223" in ASCII so what gave the result "31 32 32 33" in places with sending "send HEX" "04c7" (=1223 = DEC) !

    I think I did not express myself well.

    Thank you for your explanation and the time you have devoted myself!

    Then I come from VB and I had never seen the syntax "<<".
    I understood tardily that it was a byte offset !!

    http://en.wikipedia.org/wiki/Bitwise...t_shift_.3C.3C

    If I may, it would be nice to add an example of communication in the sample files ...

    As soon as I finished my project, I will add in shares hoping it helps two or three newbie like me

    Many thanks again. You can close the post !

    Leave a comment:


  • ESPsupport
    replied
    If you send "T2331" the hex representation is 0x5432333331

    The first serin will read 0X54 (the "T")

    The second will read 0x32 (the "2")
    The third will read 0x33 (the first "3")

    serin() << 8 | serin()
    will then be
    0x32 << 8 | 0x33
    -> 0x3200 | 0x33
    -> 0x3233
    -> 12851

    Not sure what code you have added for "T", but, as I mentioned you need to send the number as hex, not decimal ASCII

    What part of the syntax are you having trouble with? What language are you most familiar with?

    Leave a comment:


  • Micropointe
    replied
    Hello,

    I read and re-read the documentation but I do not understand your code!

    I have great difficulty with this syntax ...

    I understand why the first code is not good. I can lose characters ...

    I sent for example with a 10 ms interval the following commands:
    G0001
    T2331

    The letter allows me to identify the command.

    If I come back to your code:

    Code:
    numx1 := serin() << 8 | serin() ;
    I do not understand this command can you explain please ?

    If I send the "T2331" value is" 54171F", the result with this code is " 5919" !

    I need your help I trampled!

    Many thanks.


    Leave a comment:


  • ESPsupport
    replied
    That's very close, here's the same thing with a few changes and comments

    Code:
    #platform "GOLDELOX"
    
    #inherit "4DGL_16bitColours.fnc"
    
    var combuf[4] ;
    func main()
    /*
        putstr("Mounting...\n");
        if (!file_Mount()) // mount the uSD
            while(!file_Mount())
                putstr("Drive not mounted...");
                pause(200);
                gfx_Cls();
                pause(200);
            wend
        endif
    */
    
        // Déclaration
        var n, p, i;
        var cmd;        // => Last charactere read
        var numx1;        // => Gear
        var numx2;        // => Engine temperature
        var numx3;        // => Time
        var numx4;        // => Ambient temperature
        var numx5;        // => Atmo. pressure
        var numx6;        // => N° screen
    
        setbaud(BAUD_9600);                             // 9600 baud rate
        com_Init(combuf,8,0);           // <--- set comms buffer so com_Count can work
    
        // Defaut value var
     //   ActualScreen := 1;                                // Screen n°1 by defaut at start
    
    
        repeat                                                  // loop
    
            if (com_Count() >= 3)                        // <--- send 3 characters ("Gxx", "Txx", ...) for this version
    
                cmd := serin ();                              // get a character (or -1 if nothing there)
    
                if (cmd == 'G')                                  // if cmd = G = gear engaged  (format "0" )
                    numx1 := serin() << 8 | serin() ;     // depending on endianness of sent integer
               //     SEROUT (numx1);                       // <--- this would only send low byte anyway
                    gfx_MoveTo(0,0) ;
                    print([DEC5ZB] numx1," ") ;           // blank at end is needed if previous number was -ve
    
                else if (cmd == 'J')
    
                else if (cmd == 'T')                    // if cmd = T = Engine temperature  (format "000.0")
    
                else if (cmd == 'H')                    // if cmd = H = Time (HH MM) (format "00" & "00")
    
                else if (cmd == 'A')                    // if cmd = A = Ambient temperature (format "00.0")
    
                else if (cmd == 'P')                    // if cmd = P = Atmo. pressure (format "0000")
    
                else if (cmd == 'S')                    // if cmd = S = Screen change demand (format "0")
    
     //               ChangeScreen (var nS)          // Call function screen change
    
                endif
    
            endif
    
        forever
    
    endfunc
    Remember how I said it is easier and more 'compact' to send the numbers as binary? Well, since you need to support -ve numbers for 'Ambient Temperature', that makes it even harder to send the numbers as text. More accurately even harder to receive it as you need to check for and action the sign.

    So the program above will work for 'G' and you should be able to see how to add the others.

    To get this to work, fire up terminal and use send hex to send 4700FF (the 47 is the hex of 'G'), then try 47FF00, 472222, etc.

    If you really want to be sending G1234, etc, have a go at that and see how you get on (You will need & to strip off the ASCII part of the number, *10 to build it and a small loop). There is an example in the forum somewhere, just couldn't find it just now.

    Leave a comment:


  • Micropointe
    replied
    Hey,

    Thanks for your help !

    I had not used this code because I have more trouble understanding it

    But I'll try to leave that code.

    I understand with examples "Serin" allows me to read the last character sent but I have difficulty understanding how to retrieve the following 4.

    Example:

    Code:
    cmd: = serin (); // Get a character (or -1 if nothing there)
    
    if (cmd == 'I') // If "I" is identified then I proceed ...
    Then how to retrieve the rest of my chain (I sent "G0001" or "T1235")?


    Below the new working basis from your code ...

    Code:
    func main()
    
    putstr("Mounting...\n");
    if (!file_Mount()) // mount the uSD
        while(!file_Mount())
            putstr("Drive not mounted...");
            pause(200);
            gfx_Cls();
            pause(200);
        wend
    endif
    
    
    // Déclaration
    var n, p, i;
    var cmd;        // => Last charactere read
    var numx1;        // => Gear        
    var numx2;        // => Engine temperature
    var numx3;        // => Time
    var numx4;        // => Ambient temperature
    var numx5;        // => Atmo. pressure
    var numx6;        // => N° screen
    
    setbaud(BAUD_9600);                             // 9600 baud rate
    
    // Defaut value var
    ActualScreen := 1;                                // Screen n°1 by defaut at start
    
    
    repeat                                                  // loop
        
        if (com_Count ()> = 5)                        // Send 5 characters ("G0001", "T2301", ...)
        
            cmd: = serin ();                              // get a character (or -1 if nothing there)
            
            if (cmd == 'G')                                  // if cmd = G = gear engaged  (format "0" )
                numx1 := serin() << 8 | serin() ;     // depending on endianness of sent integer
                SEROUT (numx1);                       // Send return value for debug
    
            else if (cmd == 'J')
    
            else if (cmd == 'T')                    // if cmd = T = Engine temperature  (format "000.0")
                
            else if (cmd == 'H')                    // if cmd = H = Time (HH MM) (format "00" & "00")
    
            else if (cmd == 'A')                    // if cmd = A = Ambient temperature (format "00.0")
                
            else if (cmd == 'P')                    // if cmd = P = Atmo. pressure (format "0000")
    
            else if (cmd == 'S')                    // if cmd = S = Screen change demand (format "0")
        
                ChangeScreen (var nS)          // Call function screen change
          
            endif                            
    
        endif    
    
    forever
    
    endfunc

    Leave a comment:


  • ESPsupport
    replied
    Why didn't you start with the sample I gave you? The sample you have used is not at all suited to what you are trying to do.

    Also, com_Init() initializes the comms buffered service, you want to organize your code so that you only do that once, as, if you do it multiple times you could be throwing away received characters.

    Also, the sample receives the numbers in Binary, not ASCII. This means less information is transferred and the length is easier to 'know'

    Leave a comment:


  • Micropointe
    replied
    Hello,

    Thank you for the answer.

    I've done a lot of research but I did not find a clear answer.

    I tested several code this weekend but I have great difficulty and I would like to take your help please!

    I tried to send a series of 5 characters via the terminal eg "T2301" and then "G0001" then "H1030" then "A0211" and "P1010".

    I want to use the letter to identify the string and store the 4 next characters to store in a variable.

    Here is my code:

    Code:
    var buf1[3];
    var bufptrs[0];
    
    func main()
    var n, p;
    var Last_Chr;
    var numx1, numx2, numx3, numx4, numx5
    
    bufptrs[0] := buf1;                     // initialize the buffer pointer list
    
    Last_Chr := serin();                  // Reading the last character
    
    if ((Last_Chr == 'T')                    // if Last_Chr = T proced ...
    
        while(n<4)
            com_Init(bufptrs[0],4,0);
    
            while(!com_Full())
                numx1 := bufptrs[0];        // Variable filling with 4 characters
                putstr(bufptrs[n]);            // print for debug
                putch('\n');
                
                com_Init(bufptrs[0],4,0);    // reset comms buffer
            wend
    
            n++;
        wend
    
    else if (Last_Chr == 'G')                // if Last_Chr = G proced ...
        
    else if (Last_Chr == 'H')    
    
    else if (Last_Chr == 'A')        
        
    else if (Last_Chr == 'P')    
    
    
    endif    
    
    repeat forever
    
    endfunc
    The source code comes from this page ...
    http://forum.4dsystems.com.au/forum/...ers-from-usart



    I have a hard time using the "Com_Init" then empty the stored characters!

    When I send 'G' in the terminal monitor my 4 characters, I have no result!

    Many thanks for youtr help !



    Last edited by Micropointe; 9th February 2015, 08:07 PM.

    Leave a comment:


  • ESPsupport
    replied
    I think this has been fully answered in your other post.

    In short Goldelox does not support Genie, you will need to write your own protocol.

    There are some examples on the forum here.

    Something like 'a', leddigits1 value, 'b', leddigits2 value, etc. But as a hex stream rather than text, should work well

    ​The code in post #4 gives you the general idea http://forum.4dsystems.com.au/forum/...tion-ulcd-32pt

    Leave a comment:


  • Protocol for communicating with a visi system via the terminal (uOLED-160-G2)

    Hello,

    I did a project with 5 Visi leddigitals.
    I compiled the project and the screen works.

    I would now like to use the terminal to interact with the screen and change the values of my leddigitals. When I try to send commands, the product does not answer (only green message when I write)!

    Can you help me please?
Working...
X