Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Parsing CSV file to construct Modbus Request Packet
Forum Updated to NodeBB v4.3 + New Features

Parsing CSV file to construct Modbus Request Packet

Scheduled Pinned Locked Moved Unsolved General and Desktop
modbuspacketsmasterclient
1 Posts 1 Posters 968 Views
  • 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 14 Apr 2017, 13:50 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;
    }```

    1 Reply Last reply
    0

    1/1

    14 Apr 2017, 13:50

    • Login

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