123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- #include "tf.h"
- #include "plt.h"
- static void tongfei_comm_0x0000(int idx)
- {
- unsigned short tab_us[128] = {0};
- struct tongfei_t *dev = &tf[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;
- }
- nb = 33;
- start = 0x0000;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- rc = chan_read_holdingregisters_with_retry(chanidx, addr, start, nb, tab_us);
- if (rc < 0)
- {
- comm_set_state(comm, COMMST_ERR);
- }
- chan_unlock(chanidx);
- if (rc == 0)
- { /* read ok */
- //0x0000
- dev->run_statue = tab_us[0]; //运行状态,0空闲 1准备启动 2运行 3 延时停机 4 故障
- if (dev->run_statue == 0)
- {
- sprintf(dev->run_state_str, "%s", "stop");
- }
- else if (dev->run_statue == 1)
- {
- sprintf(dev->run_state_str, "%s", "ready");
- }
- else if (dev->run_statue == 2)
- {
- sprintf(dev->run_state_str, "%s", "run");
- }
- else if (dev->run_statue == 3)
- {
- sprintf(dev->run_state_str, "%s", "delay stop");
- }
- else
- {
- sprintf(dev->run_state_str, "%s", "error");
- }
-
- dev->io_in= tab_us[1];
- dev->io_out= tab_us[2];
- dev->out_water_temp= tab_us[3] / 100.0; //进水口温度
- dev->in_water_temp= tab_us[4]/ 10.0; //出水口温度
- dev->in_evaporation_temp= tab_us[5]/ 10.0;//蒸发入口温度
- dev->out_evaporation_temp= tab_us[7]/ 10.0;//蒸发入口温度
- dev->ev_temp= tab_us[8] / 10.0; //环境温度
- dev->expansion_valve_degree= tab_us[11]; //膨胀阀当前开度
- dev->in_water_press= tab_us[18]/10.0; //进水口压力
- dev->out_water_press= tab_us[19]/10.0; //出水口压力
- dev->Err_1= tab_us[25];
- dev->Err_2= tab_us[26];
- dev->Err_3= tab_us[27];
- dev->Err_4= tab_us[28];
- dev->FrequencyChangerErr = tab_us[29];
- }
- else
- {
- return;
- }
-
- nb = 3;
- start = 0x1000;
- chan_lock(chanidx);
- usleep(100000); // 100ms
- rc = chan_read_holdingregisters_with_retry(chanidx, addr, start, nb, tab_us);
- if (rc < 0)
- {
- comm_set_state(comm, COMMST_ERR);
- }
- chan_unlock(chanidx);
- if (rc == 0)
- { /* read ok */
- //0x1000
- dev->runMode = tab_us[0x1001 - start];
- if (dev->runMode == 1)
- {
- sprintf(dev->runMode_str, "%s", "cool");
- }
- else if (dev->runMode == 2)
- {
- sprintf(dev->runMode_str, "%s", "heat");
- }
- else if (dev->runMode == 3)
- {
- sprintf(dev->runMode_str, "%s", "loop");
- }
- else if (dev->runMode == 4)
- {
- sprintf(dev->runMode_str, "%s", "auto");
- }
- dev->ctlMode = tab_us[0x1000 - start];
- if (dev->ctlMode == 0)
- {
- sprintf(dev->ctrMode_str, "%s", "manual ");
- }
- else if (dev->ctlMode == 1)
- {
- sprintf(dev->ctrMode_str, "%s", "auto");
- }
- else if (dev->ctlMode == 2)
- {
- sprintf(dev->ctrMode_str, "%s", "romote");
- }
- }
- else
- {
- return;
- }
- }
- int tongfei_set_dev_start(int idx)
- {
- int ret = 0;
- struct tongfei_t *dev = &tf[idx];
- struct comm_t *comm = &dev->comm;
- chan_lock(comm->chanidx);
- ret = chan_write_single_register_with_retry(comm->chanidx, comm->adr, 0x0300, 1);
- chan_unlock(comm->chanidx);
- log_dbg("%s, idx:%d", __func__, idx);
- log_info("----------------------------------%s, ret:%d,tongfei start", __func__, ret);
- return ret;
- }
- int tongfei_set_dev_stop(int idx)
- {
- int ret = 0;
- struct tongfei_t *dev = &tf[idx];
- struct comm_t *comm = &dev->comm;
- chan_lock(comm->chanidx);
- ret = chan_write_single_register_with_retry(comm->chanidx, comm->adr, 0x0300, 2);
- chan_unlock(comm->chanidx);
- log_dbg("%s, idx:%d", __func__, idx);
- return ret;
- }
- /*
- 范围[0,5]
- 0 停止,
- 1 制冷,
- 2 加热,
- 3 内循环
- 4 全 自 动 ( 根 据 水温)
- */
- int tongfei_set_dev_runmode(int idx, int mode)
- {
- int ret = 0;
- struct tongfei_t *dev = &tf[idx];
- struct comm_t *comm = &dev->comm;
- chan_lock(comm->chanidx);
- ret = chan_write_single_register_with_retry(comm->chanidx, comm->adr, 0x1001, mode);
- chan_unlock(comm->chanidx);
- log_dbg("%s, idx:%d", __func__, idx);
- return ret;
- }
- /*
- 范围[0,2]
- 0 命令方式启停,
- 1 制自动延时开启,
- 2 远程开启
- */
- int tongfei_set_dev_ctlmode(int idx, int mode)
- {
- int ret = 0;
- struct tongfei_t *dev = &tf[idx];
- struct comm_t *comm = &dev->comm;
- chan_lock(comm->chanidx);
- ret = chan_write_single_register_with_retry(comm->chanidx, comm->adr, 0x1000, mode);
- chan_unlock(comm->chanidx);
- log_dbg("%s, idx:%d", __func__, idx);
- return ret;
- }
- int tongfei_set_dev_mbadr(int idx, int val)
- {
- int ret = 0;
- struct tongfei_t *dev = &tf[idx];
- struct comm_t *comm = &dev->comm;
- chan_lock(comm->chanidx);
- ret = chan_write_single_register_with_retry(comm->chanidx, comm->adr, 0x100a, val);
- chan_unlock(comm->chanidx);
- log_dbg("%s, idx:%d, val:%d, ret:%d", __func__, idx, val, ret);
- return ret;
- }
- int tongfei_comm_init(int idx)
- {
- struct tongfei_t *dev = &tf[idx];
- struct comm_t *comm = &dev->comm;
- comm_set_state(comm, COMMST_ERR);
- }
- int tongfei_comm_reset(int idx)
- {
- struct tongfei_t *dev = &tf[idx];
- struct comm_t *comm = &dev->comm;
- comm_reset(comm);
- // comm_set_state( comm, COMMST_NORMAL );
- }
- void tongfei_comm_dac(int idx)
- {
- struct tongfei_t *dev = &tf[idx];
- struct comm_t *comm = &dev->comm;
- int ret = 0;
- if (comm_get_state(comm) != COMMST_NORMAL)
- {
- return;
- }
- comm_start_cal_dac_timing(comm);
- tongfei_comm_0x0000(idx);
- }
|