1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include "plt.h"
- int sga500e_comm_init(int idx)
- {
- struct sga500e_t* dev = &sga500e[idx];
- struct comm_t* comm = &dev->comm;
- comm_set_state( comm, COMMST_ERR );
- }
- int sga500e_comm_reset(int idx)
- {
- struct sga500e_t* dev = &sga500e[idx];
- struct comm_t* comm = &dev->comm;
- comm_set_state( comm, COMMST_NORMAL );
- }
- void sga500e_comm_dac( int idx )
- {
- unsigned short tab_us[256]={0};
- struct sga500e_t* dev = &sga500e[idx];
- struct comm_t* comm = &dev->comm;
- int chanidx = comm->chanidx;
- int addr = comm->adr;
- int start, nb;
- int ret = 0;
- if(comm_get_state(comm) != COMMST_NORMAL){
- return;
- }
- comm_start_cal_dac_timing(comm);
- nb = 9;
- start = 0x0100;
- 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->state = tab_us[0x0100 - start];
- dev->decimal_pos = tab_us[0x0102 - start];
- if( dev->decimal_pos == 0 ){
- dev->density = tab_us[0x0101 - start];
- }else if( dev->decimal_pos == 1 ){
- dev->density = tab_us[0x0101 - start]/10.0;
- }else if( dev->decimal_pos == 2 ){
- dev->density = tab_us[0x0101 - start]/100.0;
- }else if( dev->decimal_pos == 3 ){
- dev->density = tab_us[0x0101 - start]/1000.0;
- }else if( dev->decimal_pos == 4 ){
- dev->density = tab_us[0x0101 - start]/10000.0;
- }
- dev->name = tab_us[0x0103 - start];
- dev->unit = tab_us[0x0104 - start];
- dev->alarm_hi = tab_us[0x0105 - start];
- dev->alarm_lo = tab_us[0x0106 - start];
- comm_stop_cal_dac_timing(comm);
- }
-
- }
|