#include "plt.h" int rh811ad053f_comm_init(int idx) { struct rh811ad053f_t *dev = &rh811ad053f[idx]; struct comm_t *comm = &dev->comm; comm_set_state(comm, COMMST_ERR); } int rh811ad053f_comm_reset(int idx) { struct rh811ad053f_t *dev = &rh811ad053f[idx]; struct comm_t *comm = &dev->comm; comm_set_state(comm, COMMST_NORMAL); } void rh811ad053f_comm_dac(int idx) { unsigned short tab_us[256] = {0}; struct rh811ad053f_t *dev = &rh811ad053f[idx]; struct comm_t *comm = &dev->comm; int chanidx = comm->chanidx; int addr = comm->adr; int start, nb, rc, i; int ret = 0; if (comm_get_state(comm) != COMMST_NORMAL) { return; } comm_start_cal_dac_timing(comm); nb = 2; start = 0x0002; chan_lock(comm->chanidx); if (chan_read_holdingregisters_with_retry(chanidx, addr, start, nb, tab_us) < 0) { chan_unlock(comm->chanidx); comm_set_state(comm, COMMST_ERR); return; } else { /* read ok */ chan_unlock(comm->chanidx); dev->humi = tab_us[0x0003 - start] / 10.0; dev->temp = *((SHORT *)&tab_us[0x0002 - start]) / 10.0; comm_stop_cal_dac_timing(comm); } }