I see the problem:
Your header file has this:
protected:
int ps[6];
private:
asynUser* device;
Your driver has this. It is incorrect, you are writing to addresses 0, 1, 2, 4, 5, 6 but it should be 0, 1, 2, 3, 4, 5. When you write to 6 you are overwriting this->device, changing it to 5.
createParam("i_1", asynParamInt32, &ps[0]);
createParam("i_2", asynParamInt32, &ps[1]);
createParam("i_3", asynParamInt32, &ps[2]);
createParam("f_1", asynParamFloat64, &ps[4]);
createParam("f_2", asynParamFloat64, &ps[5]);
createParam("f_3", asynParamFloat64, &ps[6]);
From: Abdalla Ahmad <Abdalla.Ahmad at sesame.org.jo>
Sent: Thursday, October 13, 2022 8:14 AM
To: Mark Rivers <rivers at cars.uchicago.edu>; tech-talk at aps.anl.gov <tech-talk at aps.anl.gov>
Subject: RE: Segmentation fault when using asyn Octect writeRead
Hello Mark
Please find attached gdb backtrace. You are right about the conversion, but for the casting since it returns raw data, either I do memcpy to a float pointer
or:
*value = *(epicsFloat64*) &temp;
Either way it did not work. I think Something is wrong with the asyn user I am passing, its address is 0x5 for some reason.
Thanks
Abdalla.
From: Mark Rivers <rivers at cars.uchicago.edu>
Sent: Thursday, October 13, 2022 4:04 PM
To: Abdalla Ahmad <Abdalla.Ahmad at sesame.org.jo>; tech-talk at aps.anl.gov
Subject: Re: Segmentation fault when using asyn Octect writeRead
> The device returns all readings, float and integer, as a raw unsigned 32-bit integer and then I cast the raw data pointer into float pointer if needed.
Then your code is wrong. You are passing a pointer to a different data type, and not actually doing an int to float conversion. The code should be this:
asynStatus PSController::readFloat64(asynUser* asyn, epicsFloat64* value)
asynStatus status = performIO(asyn, &temp);
*value = (epicsFloat64) temp;
}
Please print the address of this->device using printf("this->device=%p\n", this->device) just before the call to pasynOctetSyncIO->writeRead().
Please also send the actual output of the gdb backtrace.
Hello Mark
Yes that was an indexing mistake but it did not work. The device returns all readings, float and integer, as a raw unsigned 32-bit integer and then I cast
the raw data pointer into float pointer if needed. I did ran the IOC under GDB and it crashes on the call to writeRead, exactly at line 238 in asynOctetSyncIO.c where it tries to cast the userPvt pointer of the asynUser to ioPvt*.
Best Regards,
Abdalla.
I think I see an error in your driver:
memcpy(tx_array + 0, &(tx.status), sizeof(u16));
memcpy(tx_array + 2, &(tx.command), sizeof(u16));
memcpy(tx_array + 2, &(tx.address), sizeof(u16));
memcpy(tx_array + 4, &(tx.data), sizeof(u32));
You are copying to tx_array+2 twice. I think you probably mean
memcpy(tx_array + 0, &(tx.status), sizeof(u16));
memcpy(tx_array + 2, &(tx.command), sizeof(u16));
memcpy(tx_array + 4, &(tx.address), sizeof(u16));
memcpy(tx_array + 6, &(tx.data), sizeof(u32));
The following also looks like it might be an error. You are passing a pointer to a float cast to u32*. Does your device really return a 32-bit float, or does it return an
integer?
asynStatus PSController::readFloat64(asynUser* asyn, epicsFloat64* value)
float temp = (float) *value;
asynStatus status = performIO(asyn, (u32*) &temp);
}
Neither of these problems is likely to cause the crash. Please run the program under gdb and send the output of "backtrace" when it crashes.
Hello
I am writing a driver to control a custom power supply using asynPortDriver, I am using asynOctetSyncIO->writeRead interface to do IO with the controller but the IOC crashes
on calling the function (https://github.com/AbdallaDalleh/psc-asyn-driver/blob/main/pscApp/src/PSController.cpp#L83 ). The asynOctetSyncIO interface crashes
specifically on line 238, when casting the userPvt pointer of the passed asynUser pointer. I used this interface many times before and I have no idea why the segmentation fault happens.
Best Regards,
Abdalla.
|