Results 1 to 6 of 6

Thread: convert fprint() to writing text in text area

  1. #1
    Join Date
    Aug 2012
    Location
    Boulder, Colorado
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default convert fprint() to writing text in text area

    premise:

    I am using an FTDI C232H cable to communicate via I2C protocol to a MAX31785 fan controller. I have a basic script setup
    that can communicate with the fan controller and do other meaningful stuff. I want to convert that into a GUI that just has a
    column of buttons on the left side that perform various functions, program, read temp, read fan rpm, and then write the
    output and stuff to a text area.

    Problem/Question:

    I am not sure how to go about this using Qt. I am sure there are at least a dozen ways to perform this task but I am not sure
    which one would work the best and make the most sense. Basically I want to transform all the fprints() to a write to the text area.

    here is the script that I currently have:

    Qt Code:
    1. #include <stdio.h>
    2. #include <tchar.h>
    3. #include <Windows.h>
    4. #include "Headers/ftd2xx.h"
    5. #include "Headers/libMPSSE_i2c.h"
    6.  
    7. using namespace std;
    8.  
    9.  
    10.  
    11. /******************************************************************************/
    12. /* Function Definitions */
    13. /******************************************************************************/
    14. /* Helper macros */
    15.  
    16.  
    17. void Check_Status(unsigned long exp)
    18. {
    19. if(exp!=FT_OK)
    20. {
    21. printf("\n\n\n%s: %d : %s(): \n status(0x%x)=\n",__FILE__, __LINE__, __FUNCTION__,exp);
    22. getchar();
    23. exit(1);
    24. }
    25. else
    26. {
    27. ;
    28. }
    29. }
    30.  
    31. FT_STATUS status;
    32. FT_HANDLE Handle;
    33.  
    34.  
    35. //int _tmain(int argc, _TCHAR* argv[])
    36. int main()
    37. {
    38. //FTDI Driver stuff
    39. FT_DEVICE_LIST_INFO_NODE devList;
    40. uint32 channels;
    41. int channelOpen = 0;
    42.  
    43. // EEPROM reading variables and structures
    44. char Manufacturer[64];
    45. char ManufacturerID[64];
    46. char Description[64];
    47. char SerialNumber[64];
    48.  
    49. FT_EEPROM_HEADER ft_eeprom_header;
    50. ft_eeprom_header.deviceType = FT_DEVICE_232H;
    51.  
    52. FT_EEPROM_232H ft_eeprom_232h;
    53. ft_eeprom_232h.common = ft_eeprom_header;
    54. ft_eeprom_232h.common.deviceType = FT_DEVICE_232H;
    55.  
    56. // libMPSSE-related variables
    57. ChannelConfig channelConf;
    58. Init_libMPSSE();
    59. //General variables
    60. uint32 TrialAddress = 0x00;
    61. int i;
    62. int j;
    63. uint8 i2cAddress = 0x00;
    64. unsigned char i2cDataSend[1024] = {0}; // Initialize a data buffer and set to all Zeros
    65. unsigned char i2cDataReceive[1024] = {0}; // Initialize a data buffer and set to all Zeros
    66. uint32 i2cNumBytesToTx = 0; // Initialize a counter for the buffer and set to Zero
    67. uint32 i2cNumBytesTxd = 0; // Initialize another counter for the number of bytes actually sent and set to Zero
    68. uint32 i2cNumBytesToRx = 0; // Initialize a counter for the recieve buffer and set to Zero
    69. uint32 i2cNumBytesRxd = 0; // Initialize another counter for the number of bytes actually recieved and set to Zero
    70.  
    71.  
    72. channelConf.ClockRate = I2C_CLOCK_STANDARD_MODE;// 100,000 Hz
    73. channelConf.LatencyTimer= 255;
    74. channelConf.Options = I2C_DISABLE_3PHASE_CLOCKING;
    75. printf("Press Enter to Start");
    76. getchar();
    77.  
    78. status = I2C_GetNumChannels(&channels);
    79. Check_Status(status);
    80. printf("Number of available I2C channels = %d\n",channels);
    81. //Get information on each available channel.
    82. if(channels>0)
    83. {
    84. for(i=0;i<channels;i++)
    85. {
    86. status = I2C_GetChannelInfo(i, &devList);
    87. Check_Status(status);
    88. printf("Information on channel number %d:\n",i);
    89. //print the dev info
    90. printf(" Flags=0x%x\n", devList.Flags);
    91. printf(" Type=0x%x\n", devList.Type);
    92. printf(" ID=0x0%x\n", devList.ID);
    93. printf(" LocId=0x%x\n", devList.LocId);
    94. printf(" SerialNumber=%s\n", devList.SerialNumber);
    95. printf(" Description=%s\n", devList.Description);
    96. }
    97. }
    98. else
    99. {
    100. printf("No FTDI devices were found\n");
    101. getchar();
    102. return 0;
    103. }
    104.  
    105.  
    106. //
    107. //I2C_OpenChannel
    108. status = FT_Open(channelOpen,&Handle);
    109. if (status == FT_OK)
    110. {
    111. printf("Channel %d has been successfully opened\n", channelOpen);
    112. }
    113. else
    114. {
    115. printf("Channel %d is unable to be opened\n", channelOpen);
    116. printf("status = 0x%x\n");
    117. getchar();
    118. return 0;
    119. }
    120. printf("Reading the EEPROM...\n");
    121. status = FT_EEPROM_Read(Handle, &ft_eeprom_232h, sizeof(ft_eeprom_232h), Manufacturer, ManufacturerID, Description, SerialNumber);
    122. if (status == FT_OK)
    123. {
    124. printf(" VendorID = 0x%04x\n", ft_eeprom_232h.common.VendorId);
    125. printf(" ProductID = 0x%04x\n", ft_eeprom_232h.common.ProductId);
    126. printf(" Manufacturer = %s\n",Manufacturer);
    127. printf(" Manufacturer ID = %s\n",ManufacturerID);
    128. printf(" Description = %s \n", Description);
    129. printf(" SerialNumber = %s \n", SerialNumber);
    130. }
    131. else
    132. {
    133. printf("Unable to read EEPROM\n");
    134. }
    135.  
    136. printf("Initializing for I2C operation...\n");
    137. status = I2C_InitChannel(Handle,&channelConf);
    138. if (status == FT_OK)
    139. {
    140. printf("Channel %d has been successfully initialized.\n", channelOpen);
    141. }
    142. else
    143. {
    144. printf("Channel %d is unable to be initialized\n", channelOpen);
    145. printf("status = 0x%x\n", status);
    146. getchar();
    147. I2C_CloseChannel(Handle);
    148. return 0;
    149. }
    150. getchar();
    151. printf("Searching for I2C devices... ");
    152. j = 0;
    153.  
    154. //this section finds all MAX chips by sending out the write_protect command
    155. //on every availavle 7 bit I2C address, not including address 0x00 because that is
    156. //a broadcast address
    157.  
    158. i2cNumBytesToTx = 0;
    159. i2cDataSend[i2cNumBytesToTx++] = 0x10; //Write_Protect Command
    160. i2cDataSend[i2cNumBytesToTx++] = 0x00; //Disable write protect
    161. for (i = 0x00; i < 128; i++)
    162. {
    163. TrialAddress = i;
    164. status = I2C_DeviceWrite(Handle, TrialAddress, i2cNumBytesToTx, i2cDataSend, &i2cNumBytesTxd, 0x07);
    165. if (status == FT_OK)
    166. {
    167.  
    168. j++;
    169. printf("\n I2C Address %X Responded\n",i);
    170. }
    171. else
    172. {
    173. ;
    174. }
    175. }
    176. if (j == 0)
    177. {
    178. printf("Could not find any I2C devices\n");
    179. }
    180. printf("\n\nThat is all for now, move along,\n nothing more to see here,\n move along to another program \n");
    181. getchar();
    182. Cleanup_libMPSSE();
    183. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: convert fprint() to writing text in text area

    There are plenty of tutorials and examples and in the documentation to help build the basic application shell. The Qt equivalent to printf() is QString::arg() and you get and set the text of a QTextEdit or QPlainTextEdit with their text() and setText() functions respectively.

  3. #3
    Join Date
    Aug 2012
    Location
    Boulder, Colorado
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: convert fprint() to writing text in text area

    There are plenty of tutorials and examples and in the documentation to help build the basic application shell.
    If I had found something, I probably would not of posted this.
    In all of the examples I have seen, I have never seen QString::arg().

    This is more of what I was talking about, or I should say it has the effect that I am looking for.

    Qt Code:
    1. QString line = "Writing Text";
    2. QString line2 = "Writing more";
    3. ui->textEdit->append(line);
    4. ui->textEdit->append(line2);
    5. ui->textEdit->show();
    To copy to clipboard, switch view to plain text mode 

    Is there an example using the QString::arg()?

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: convert fprint() to writing text in text area

    I just had a very quick look and I saw that the Class Wizard example uses this. Anyway it is as simple as this:
    Qt Code:
    1. myTextEdit->setText(QString::fromAscii("Hello, %1! Did you know that %2 + %3 = %4?").arg(QString::fromAscii("world"), 2, 2, 4));
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: convert fprint() to writing text in text area

    Quote Originally Posted by Darktyr View Post
    Is there an example using the QString::arg()?
    The text of docs I gave you a link to gives you an example. Here: QString::arg()
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  6. #6
    Join Date
    Aug 2012
    Location
    Boulder, Colorado
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: convert fprint() to writing text in text area

    Thank You ChrisW67 and yeye_olive.

Similar Threads

  1. getting text from text area in qml
    By Sharmibala in forum Newbie
    Replies: 1
    Last Post: 4th March 2012, 12:01
  2. Writing the text within a text edit to a file
    By Splatify in forum Newbie
    Replies: 4
    Last Post: 23rd February 2011, 22:48
  3. writing to a text-file
    By QtBros61 in forum Newbie
    Replies: 7
    Last Post: 9th April 2010, 11:15
  4. Qt class showing text area/text edit
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 21st August 2008, 12:15
  5. Writing Text on a Rectangle!!!
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2006, 10:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.