reading csv file to form modbus request packet

  • 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]);


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

  • Lifetime Qt Champion


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


    Closing this one.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.