sga500e_comm.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "plt.h"
  2. int sga500e_comm_init(int idx)
  3. {
  4. struct sga500e_t* dev = &sga500e[idx];
  5. struct comm_t* comm = &dev->comm;
  6. comm_set_state( comm, COMMST_ERR );
  7. }
  8. int sga500e_comm_reset(int idx)
  9. {
  10. struct sga500e_t* dev = &sga500e[idx];
  11. struct comm_t* comm = &dev->comm;
  12. comm_set_state( comm, COMMST_NORMAL );
  13. }
  14. void sga500e_comm_dac( int idx )
  15. {
  16. unsigned short tab_us[256]={0};
  17. struct sga500e_t* dev = &sga500e[idx];
  18. struct comm_t* comm = &dev->comm;
  19. int chanidx = comm->chanidx;
  20. int addr = comm->adr;
  21. int start, nb;
  22. int ret = 0;
  23. if(comm_get_state(comm) != COMMST_NORMAL){
  24. return;
  25. }
  26. comm_start_cal_dac_timing(comm);
  27. nb = 9;
  28. start = 0x0100;
  29. chan_lock(comm->chanidx);
  30. if( chan_read_holdingregisters_with_retry( chanidx, addr, start, nb, tab_us) < 0){
  31. chan_unlock(comm->chanidx);
  32. comm_set_state(comm, COMMST_ERR);
  33. return;
  34. }else{ // read ok
  35. chan_unlock(comm->chanidx);
  36. dev->state = tab_us[0x0100 - start];
  37. dev->decimal_pos = tab_us[0x0102 - start];
  38. if( dev->decimal_pos == 0 ){
  39. dev->density = tab_us[0x0101 - start];
  40. }else if( dev->decimal_pos == 1 ){
  41. dev->density = tab_us[0x0101 - start]/10.0;
  42. }else if( dev->decimal_pos == 2 ){
  43. dev->density = tab_us[0x0101 - start]/100.0;
  44. }else if( dev->decimal_pos == 3 ){
  45. dev->density = tab_us[0x0101 - start]/1000.0;
  46. }else if( dev->decimal_pos == 4 ){
  47. dev->density = tab_us[0x0101 - start]/10000.0;
  48. }
  49. dev->name = tab_us[0x0103 - start];
  50. dev->unit = tab_us[0x0104 - start];
  51. dev->alarm_hi = tab_us[0x0105 - start];
  52. dev->alarm_lo = tab_us[0x0106 - start];
  53. comm_stop_cal_dac_timing(comm);
  54. }
  55. }