Announcement

Collapse
No announcement yet.

Write bytes to serial

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

  • Write bytes to serial

    Hi Everybody,
    today using Visi I try to write some bytes to serial COM1 where is attacched a Bluetooth device but with no luck here a snippet:

    var I;
    var combuf[40];
    com_SetBaud(COM1, 11520);

    COM1_RX_pin(PA2);
    COM1_TX_pin(PA3);
    com1_Init(combuf, 20, 0 );
    var C_BLU[31]:= ['02','40','00','1A','00','16','00','04','00','12','08','00','01','10','00','00','00','05','0A','00', 'FF','00','80','00','A3','00','00','00','FF','41','9D'] ;
    for (I:=0; I<31; I++)
    serout1(C_BLU[I]);
    next

    I think the problem is that i am not sending HEX value but CHAR
    But I do not to understand how to do.
    Thank You for support
    Best Regards
    Marco

  • #2
    Is this correct?
    var C_BLU[31]:= [0x02,0x40,0x00,0x1A,0x00,0x16,0x00,0x04,0x00,0x12,0x08,0x00,0x01,0x10,0x00,0x00,0x00,0x05,0x0A,0x00, 0xFF,0x00,0x80,0x00,0xA3,0x00,0x00,0x00,0xFF,0x41,0x9D] ;

    Comment


    • pauleilio
      pauleilio commented
      Editing a comment
      Yes that is the correct representation of a Hex number.

      Paul

  • #3
    I am stuck.....
    I am using a MOTG Bluetooth over a gen4-MOTG-AC2 connected to a Gen4-uLCD-70DT.
    I added to the proiect a button for every step:
    1- putstr("$$$"); // Enter Command mode
    2- putstr("SS,C0\r\n"); // Support device info and UART Transparent
    3- putstr("R,1\r\n") // Reboot device (reboot necessary for UART Trasparent command)
    4- putstr("$$$"); // Enter Command mode (again after reboot)
    5- putstr("c,0,886B0F01C7B2\r\n"); // Connect to the other Bluetooth device with MAC Address 88:6B:0F:01:C7:B2
    6- putstr("---"); // Return Data Mode

    All this Commands seem OK ( I have the answer on display)
    But when I send the data as I show above nothing happens.
    I know that the byte array is correct, because if I send the same array with a smartphone using nRF Connect the other Bluetooth device answer me correctly.
    So I do not understand what I am doing wrong
    Thank You
    Marco

    Comment


    • #4
      Hello Marco,

      Have you tried using to(COM1); before the putstr() eg.

      to(COM1);
      putstr("$$$");

      Paul

      Comment


      • #5
        Hi everybody,
        finally I found the problem, it wasn't the serial....
        To send data to the other BLE device I have to do other several steps. I write what I did because I think could be useful for other people.
        The Remote BLE Device has a GATT Service so it has one or more Services and some Characteristics for every Service.
        In my scenario the Remote BLE Device will be the Server and MotG Bluetooth will be the client.

        1- $$$ // Enter Command mode
        2- SS,C0 // Support device info and UART Transparent
        3- R,1 // Reboot device (reboot necessary for UART Trasparent command)
        4- $$$" // Enter Command mode (again after reboot)
        5- c,0,886B0F01C7B2 // Connect to the other Bluetooth device with MAC Address 88:6B:0F:01:C7:B2
        6- CI // works as client
        7- LC // show Services and Characteristics
        8- CHW,0008,0110000000050A00FF008000A3000000FF419D // Client Handle Write, the characteristics found that I need, Value to send in my case

        I tried this using CoolTerm connecting the MotG Bluetooth to a Serial Port and works as I want, now I will try using Gen4-uLCD-70DT
        I understood what to do reading the RN4870 Manual.
        Thank You for support.
        Best Regards
        Marco

        Comment


        • #6
          Hi Marco,

          That's great, thanks for sharing it with us, it is sure to help many who maybe stuck with the same problem.

          Many thanks

          Paul

          Comment


          • #7
            Marco, thank you so much for your post from 2017!

            I was trying to connect a MOTG Bluetooth to a Wit Motion WT901BLE 9 axis sensor and pulling my hair out.
            So little is written that I could find at this low level about BLE connection and how to get data from a peripheral.
            Also, after delving into BLE and getting a rudimentary handle on it I found that the WT901BLE datasheet does not list it's services, characteristics, or descriptors.
            This is a big oversite IMO considering it is geared toward development.
            So I would like to expand a little to explain to anyone in the future that might find this by searching for MOTG & WT901BLE.

            The WT901BLE main data stream is a Custom Service with UUID 0000FFE4-0000-1000-8000-00805f9A34FB and notify CCCD UUID 000C

            Following Marco's steps and modifying:

            1- $$$ // Enter Command mode
            2- SS,C0 // Support device info and UART Transparent (Not necessary after 1st reboot unless you change SS again)
            3- R,1 // Reboot device (reboot necessary for UART Trasparent command) (Not necessary after 1st reboot unless you change SS again)
            4- $$$" // Enter Command mode (again after reboot)
            5- C,1,FDA13A664F20 // Connect private random address to the other BLE device with MAC Address FD:A1:3A:66:4F:20 (Substitute the MAC address of your WT901BLE instead of mine)
            6- CI // works as client (Confusing until you learn that GATT roles are independent of GAP roles)
            7- LC // show Services and Characteristics (Was a step I had to do to figure out where the data stream was but not necessary once I did)
            8- CHW,000C,0100 // Client Handle Write to 000C with 0x0100

            000C is the handle for the CCCD notify of custom service 0000FFE4-0000-1000-8000-00805f9A34FB.
            To subscribe to notifications from that service you write (CHW) to it (000C) the value 0x0100 (b0001) to enable the data stream,
            0x0100 = b0001 because the low byte is first.

            This will be followed by the response:

            AOK
            CMD> AOK
            CMD> %NOTI,000B,5561D8FEA5FDBC09FBFF0800FEFF2CF690045A47%%NOTI,000B,5561E0FE9FFDBE090300FBFF00002BF690045 C47%%NOTI,000B,5561DCFEA2FDC2090300F9FF00002AF691045B47%%NOTI,000B,5561DFFE9CFDC109FFFF0100000029F69 2045A47%% etc etc

            Refer to the WT901BLE Datasheet to convert the data stream to usable data.

            Comment


            • #8
              Hi Alexander,

              Thank you for sharing this information.

              Best Regards,
              Ferdinand

              Comment

              Working...
              X