The question comes up after finding that when you need one time in a 5-second query something from a serial device, then if you open-close device for every query, then you have 100% CPU load hit on that time. I.e there is init code:
BOOL initX5000serial(struct DockyData *dd)
{
BOOL res = FALSE;
int8 err = 0;
dd->port = IExec->AllocSysObject(ASOT_PORT, NULL);
if(dd->port)
{
dd->req = IExec->AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_Size,sizeof(struct IOExtSer),
ASOIOR_ReplyPort,dd->port, TAG_DONE);
if(dd->req)
{
if(IExec->OpenDevice("serial.device", 1, (struct IORequest*)dd->req, 0) != -1)
{
// Set parameters to address MCU
dd->req->IOSer.io_Command = SDCMD_SETPARAMS;
dd->req->io_Baud = 38400; // 38400 Baud
dd->req->io_ReadLen = 8; // 8 bit data
dd->req->io_WriteLen = 8; // 8 bit data
dd->req->io_StopBits = 1; // 1 Stop bit
dd->req->io_SerFlags &= ~SERF_PARTY_ON; // No Parity
dd->req->io_SerFlags |= SERF_XDISABLED; // No Flow Control
err = IExec->DoIO( (struct IORequest*)dd->req );
if(err == IOERR_SUCCESS)
{
res = TRUE;
}
}
}
}
return(res);
}
There is de-init code:
void closeX5000serial(struct DockyData *dd)
{
if(dd->dev_open) { IExec->CloseDevice( (struct IORequest*)dd->req ); dd->dev_open = FALSE; }
if(dd->req) { IExec->FreeSysObject(ASOT_IOREQUEST, dd->req); dd->req = NULL; }
if(dd->port) { IExec->FreeSysObject(ASOT_PORT, dd->port); dd->port = NULL; }
}
Now if we do something like:
dd->dev_open = initX5000serial(dd);
if(dd->dev_open)
{
QueryTemp(dd);
QueryVoltFan(dd);
}
We then hit 100% CPU loading every time we query our stuff.
If I remember right, it is correct to open/close the device for every query, right? And it should be not opened all the time?
Any advice is welcome, thanks!