Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. reading csv file to form modbus request packet
Qt 6.11 is out! See what's new in the release blog

reading csv file to form modbus request packet

Scheduled Pinned Locked Moved Unsolved C++ Gurus
2 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    musclemania05
    wrote on last edited by
    #1

    hello all I'm reading a csv file which could contain numerous rows, then parsing it into my struct variables which make up my Modbus request packet. I have successfully parsed the csv file and assigned to appropriate struct variables. Now my question is how can I utilize the QT built in Modbus library to create my request packet to send to a port for my slave to receive????? here is my code from parsing the csv file

    int main()
    {

    struct mframe
    {
    unsigned short address;
    unsigned short func_code;
    unsigned short byte_count;
    unsigned int startaddress;
    unsigned short crc;

    };

    string ConfigPath = "myname.csv";
    //char getaddress(char addr);
    //bool setaddress(char addr);

    mframe frame[1000];

    int point_count = 0;

    vector<vector<string> > matrix;

    string line;
    ifstream file(ConfigPath);
    if (!file.is_open())
    {
    perror("error while opening file");
    }

    getline(file, line, '\n'); //deletes first row of column headers

    while (getline(file, line, '\n')) //find the endline charcater
    {

    vector<string> vec;
    string linevec;
    istringstream ss(line);//allows for parsing each line
    
    while (getline(ss, linevec, ','))
    {
    	vec.push_back(linevec);//push the parsed data for that line into a vector
    }
    
    matrix.emplace_back(vec);//push each parsed line into another vector
    frame[point_count].address = stoi(vec[0]);
    frame[point_count].func_code = stoi(vec[1]);
    frame[point_count].byte_count = stoi(vec[2]);
    frame[point_count].startaddress = stoi(vec[3]);
    frame[point_count].crc = stoi(vec[4]);
    point_count++;
    

    }

    cout << point_count << endl;
    }```
    //your code here

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please don't post the same question on multiple sub-forum. One is enough.

      Duplicate

      Closing this one.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved